n1ql.js 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Language: N1QL
  3. Author: Andres Täht <andres.taht@gmail.com>
  4. Contributors: Rene Saarsoo <nene@triin.net>
  5. Description: Couchbase query language
  6. Website: https://www.couchbase.com/products/n1ql
  7. */
  8. function n1ql(hljs) {
  9. return {
  10. name: 'N1QL',
  11. case_insensitive: true,
  12. contains: [
  13. {
  14. beginKeywords:
  15. 'build create index delete drop explain infer|10 insert merge prepare select update upsert|10',
  16. end: /;/, endsWithParent: true,
  17. keywords: {
  18. // Taken from http://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/reservedwords.html
  19. keyword:
  20. 'all alter analyze and any array as asc begin between binary boolean break bucket build by call ' +
  21. 'case cast cluster collate collection commit connect continue correlate cover create database ' +
  22. 'dataset datastore declare decrement delete derived desc describe distinct do drop each element ' +
  23. 'else end every except exclude execute exists explain fetch first flatten for force from ' +
  24. 'function grant group gsi having if ignore ilike in include increment index infer inline inner ' +
  25. 'insert intersect into is join key keys keyspace known last left let letting like limit lsm map ' +
  26. 'mapping matched materialized merge minus namespace nest not number object offset on ' +
  27. 'option or order outer over parse partition password path pool prepare primary private privilege ' +
  28. 'procedure public raw realm reduce rename return returning revoke right role rollback satisfies ' +
  29. 'schema select self semi set show some start statistics string system then to transaction trigger ' +
  30. 'truncate under union unique unknown unnest unset update upsert use user using validate value ' +
  31. 'valued values via view when where while with within work xor',
  32. // Taken from http://developer.couchbase.com/documentation/server/4.5/n1ql/n1ql-language-reference/literals.html
  33. literal:
  34. 'true false null missing|5',
  35. // Taken from http://developer.couchbase.com/documentation/server/4.5/n1ql/n1ql-language-reference/functions.html
  36. built_in:
  37. 'array_agg array_append array_concat array_contains array_count array_distinct array_ifnull array_length ' +
  38. 'array_max array_min array_position array_prepend array_put array_range array_remove array_repeat array_replace ' +
  39. 'array_reverse array_sort array_sum avg count max min sum greatest least ifmissing ifmissingornull ifnull ' +
  40. 'missingif nullif ifinf ifnan ifnanorinf naninf neginfif posinfif clock_millis clock_str date_add_millis ' +
  41. 'date_add_str date_diff_millis date_diff_str date_part_millis date_part_str date_trunc_millis date_trunc_str ' +
  42. 'duration_to_str millis str_to_millis millis_to_str millis_to_utc millis_to_zone_name now_millis now_str ' +
  43. 'str_to_duration str_to_utc str_to_zone_name decode_json encode_json encoded_size poly_length base64 base64_encode ' +
  44. 'base64_decode meta uuid abs acos asin atan atan2 ceil cos degrees e exp ln log floor pi power radians random ' +
  45. 'round sign sin sqrt tan trunc object_length object_names object_pairs object_inner_pairs object_values ' +
  46. 'object_inner_values object_add object_put object_remove object_unwrap regexp_contains regexp_like regexp_position ' +
  47. 'regexp_replace contains initcap length lower ltrim position repeat replace rtrim split substr title trim upper ' +
  48. 'isarray isatom isboolean isnumber isobject isstring type toarray toatom toboolean tonumber toobject tostring'
  49. },
  50. contains: [
  51. {
  52. className: 'string',
  53. begin: '\'', end: '\'',
  54. contains: [hljs.BACKSLASH_ESCAPE]
  55. },
  56. {
  57. className: 'string',
  58. begin: '"', end: '"',
  59. contains: [hljs.BACKSLASH_ESCAPE]
  60. },
  61. {
  62. className: 'symbol',
  63. begin: '`', end: '`',
  64. contains: [hljs.BACKSLASH_ESCAPE],
  65. relevance: 2
  66. },
  67. hljs.C_NUMBER_MODE,
  68. hljs.C_BLOCK_COMMENT_MODE
  69. ]
  70. },
  71. hljs.C_BLOCK_COMMENT_MODE
  72. ]
  73. };
  74. }
  75. module.exports = n1ql;