n1ql.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. Category: database
  8. */
  9. function n1ql(hljs) {
  10. // Taken from http://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/reservedwords.html
  11. const KEYWORDS = [
  12. "all",
  13. "alter",
  14. "analyze",
  15. "and",
  16. "any",
  17. "array",
  18. "as",
  19. "asc",
  20. "begin",
  21. "between",
  22. "binary",
  23. "boolean",
  24. "break",
  25. "bucket",
  26. "build",
  27. "by",
  28. "call",
  29. "case",
  30. "cast",
  31. "cluster",
  32. "collate",
  33. "collection",
  34. "commit",
  35. "connect",
  36. "continue",
  37. "correlate",
  38. "cover",
  39. "create",
  40. "database",
  41. "dataset",
  42. "datastore",
  43. "declare",
  44. "decrement",
  45. "delete",
  46. "derived",
  47. "desc",
  48. "describe",
  49. "distinct",
  50. "do",
  51. "drop",
  52. "each",
  53. "element",
  54. "else",
  55. "end",
  56. "every",
  57. "except",
  58. "exclude",
  59. "execute",
  60. "exists",
  61. "explain",
  62. "fetch",
  63. "first",
  64. "flatten",
  65. "for",
  66. "force",
  67. "from",
  68. "function",
  69. "grant",
  70. "group",
  71. "gsi",
  72. "having",
  73. "if",
  74. "ignore",
  75. "ilike",
  76. "in",
  77. "include",
  78. "increment",
  79. "index",
  80. "infer",
  81. "inline",
  82. "inner",
  83. "insert",
  84. "intersect",
  85. "into",
  86. "is",
  87. "join",
  88. "key",
  89. "keys",
  90. "keyspace",
  91. "known",
  92. "last",
  93. "left",
  94. "let",
  95. "letting",
  96. "like",
  97. "limit",
  98. "lsm",
  99. "map",
  100. "mapping",
  101. "matched",
  102. "materialized",
  103. "merge",
  104. "minus",
  105. "namespace",
  106. "nest",
  107. "not",
  108. "number",
  109. "object",
  110. "offset",
  111. "on",
  112. "option",
  113. "or",
  114. "order",
  115. "outer",
  116. "over",
  117. "parse",
  118. "partition",
  119. "password",
  120. "path",
  121. "pool",
  122. "prepare",
  123. "primary",
  124. "private",
  125. "privilege",
  126. "procedure",
  127. "public",
  128. "raw",
  129. "realm",
  130. "reduce",
  131. "rename",
  132. "return",
  133. "returning",
  134. "revoke",
  135. "right",
  136. "role",
  137. "rollback",
  138. "satisfies",
  139. "schema",
  140. "select",
  141. "self",
  142. "semi",
  143. "set",
  144. "show",
  145. "some",
  146. "start",
  147. "statistics",
  148. "string",
  149. "system",
  150. "then",
  151. "to",
  152. "transaction",
  153. "trigger",
  154. "truncate",
  155. "under",
  156. "union",
  157. "unique",
  158. "unknown",
  159. "unnest",
  160. "unset",
  161. "update",
  162. "upsert",
  163. "use",
  164. "user",
  165. "using",
  166. "validate",
  167. "value",
  168. "valued",
  169. "values",
  170. "via",
  171. "view",
  172. "when",
  173. "where",
  174. "while",
  175. "with",
  176. "within",
  177. "work",
  178. "xor"
  179. ];
  180. // Taken from http://developer.couchbase.com/documentation/server/4.5/n1ql/n1ql-language-reference/literals.html
  181. const LITERALS = [
  182. "true",
  183. "false",
  184. "null",
  185. "missing|5"
  186. ];
  187. // Taken from http://developer.couchbase.com/documentation/server/4.5/n1ql/n1ql-language-reference/functions.html
  188. const BUILT_INS = [
  189. "array_agg",
  190. "array_append",
  191. "array_concat",
  192. "array_contains",
  193. "array_count",
  194. "array_distinct",
  195. "array_ifnull",
  196. "array_length",
  197. "array_max",
  198. "array_min",
  199. "array_position",
  200. "array_prepend",
  201. "array_put",
  202. "array_range",
  203. "array_remove",
  204. "array_repeat",
  205. "array_replace",
  206. "array_reverse",
  207. "array_sort",
  208. "array_sum",
  209. "avg",
  210. "count",
  211. "max",
  212. "min",
  213. "sum",
  214. "greatest",
  215. "least",
  216. "ifmissing",
  217. "ifmissingornull",
  218. "ifnull",
  219. "missingif",
  220. "nullif",
  221. "ifinf",
  222. "ifnan",
  223. "ifnanorinf",
  224. "naninf",
  225. "neginfif",
  226. "posinfif",
  227. "clock_millis",
  228. "clock_str",
  229. "date_add_millis",
  230. "date_add_str",
  231. "date_diff_millis",
  232. "date_diff_str",
  233. "date_part_millis",
  234. "date_part_str",
  235. "date_trunc_millis",
  236. "date_trunc_str",
  237. "duration_to_str",
  238. "millis",
  239. "str_to_millis",
  240. "millis_to_str",
  241. "millis_to_utc",
  242. "millis_to_zone_name",
  243. "now_millis",
  244. "now_str",
  245. "str_to_duration",
  246. "str_to_utc",
  247. "str_to_zone_name",
  248. "decode_json",
  249. "encode_json",
  250. "encoded_size",
  251. "poly_length",
  252. "base64",
  253. "base64_encode",
  254. "base64_decode",
  255. "meta",
  256. "uuid",
  257. "abs",
  258. "acos",
  259. "asin",
  260. "atan",
  261. "atan2",
  262. "ceil",
  263. "cos",
  264. "degrees",
  265. "e",
  266. "exp",
  267. "ln",
  268. "log",
  269. "floor",
  270. "pi",
  271. "power",
  272. "radians",
  273. "random",
  274. "round",
  275. "sign",
  276. "sin",
  277. "sqrt",
  278. "tan",
  279. "trunc",
  280. "object_length",
  281. "object_names",
  282. "object_pairs",
  283. "object_inner_pairs",
  284. "object_values",
  285. "object_inner_values",
  286. "object_add",
  287. "object_put",
  288. "object_remove",
  289. "object_unwrap",
  290. "regexp_contains",
  291. "regexp_like",
  292. "regexp_position",
  293. "regexp_replace",
  294. "contains",
  295. "initcap",
  296. "length",
  297. "lower",
  298. "ltrim",
  299. "position",
  300. "repeat",
  301. "replace",
  302. "rtrim",
  303. "split",
  304. "substr",
  305. "title",
  306. "trim",
  307. "upper",
  308. "isarray",
  309. "isatom",
  310. "isboolean",
  311. "isnumber",
  312. "isobject",
  313. "isstring",
  314. "type",
  315. "toarray",
  316. "toatom",
  317. "toboolean",
  318. "tonumber",
  319. "toobject",
  320. "tostring"
  321. ];
  322. return {
  323. name: 'N1QL',
  324. case_insensitive: true,
  325. contains: [
  326. {
  327. beginKeywords:
  328. 'build create index delete drop explain infer|10 insert merge prepare select update upsert|10',
  329. end: /;/,
  330. keywords: {
  331. keyword: KEYWORDS,
  332. literal: LITERALS,
  333. built_in: BUILT_INS
  334. },
  335. contains: [
  336. {
  337. className: 'string',
  338. begin: '\'',
  339. end: '\'',
  340. contains: [ hljs.BACKSLASH_ESCAPE ]
  341. },
  342. {
  343. className: 'string',
  344. begin: '"',
  345. end: '"',
  346. contains: [ hljs.BACKSLASH_ESCAPE ]
  347. },
  348. {
  349. className: 'symbol',
  350. begin: '`',
  351. end: '`',
  352. contains: [ hljs.BACKSLASH_ESCAPE ]
  353. },
  354. hljs.C_NUMBER_MODE,
  355. hljs.C_BLOCK_COMMENT_MODE
  356. ]
  357. },
  358. hljs.C_BLOCK_COMMENT_MODE
  359. ]
  360. };
  361. }
  362. module.exports = n1ql;