n1ql.js 6.0 KB

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