Skip to content
Permalink
Browse files
N1QL: Updated keywords + minor improvements (#3229)
  • Loading branch information
RunDevelopment committed Dec 7, 2021
1 parent c1025aa commit 642d93ecfcc916228980074da4d60db56cce73a7
Showing with 86 additions and 8 deletions.
  1. +10 −4 components/prism-n1ql.js
  2. +1 −1 components/prism-n1ql.min.js
  3. +6 −2 tests/languages/n1ql/comment_feature.test
  4. +69 −1 tests/languages/n1ql/keyword_feature.test
@@ -1,6 +1,10 @@
// https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/index.html

Prism.languages.n1ql = {
'comment': /\/\*[\s\S]*?(?:$|\*\/)/,
'parameter': /\$[\w.]+/,
'comment': {
pattern: /\/\*[\s\S]*?(?:$|\*\/)|--.*/,
greedy: true,
},
'string': {
pattern: /(["'])(?:\\[\s\S]|(?!\1)[^\\]|\1\1)*\1/,
greedy: true,
@@ -9,8 +13,10 @@ Prism.languages.n1ql = {
pattern: /`(?:\\[\s\S]|[^\\`]|``)*`/,
greedy: true,
},
'function': /\b(?:ABS|ACOS|ARRAY_AGG|ARRAY_APPEND|ARRAY_AVG|ARRAY_CONCAT|ARRAY_CONTAINS|ARRAY_COUNT|ARRAY_DISTINCT|ARRAY_FLATTEN|ARRAY_IFNULL|ARRAY_INSERT|ARRAY_INTERSECT|ARRAY_LENGTH|ARRAY_MAX|ARRAY_MIN|ARRAY_POSITION|ARRAY_PREPEND|ARRAY_PUT|ARRAY_RANGE|ARRAY_REMOVE|ARRAY_REPEAT|ARRAY_REPLACE|ARRAY_REVERSE|ARRAY_SORT|ARRAY_STAR|ARRAY_SUM|ARRAY_SYMDIFF|ARRAY_SYMDIFFN|ARRAY_UNION|ASIN|ATAN|ATAN2|AVG|BASE64|BASE64_DECODE|BASE64_ENCODE|BITAND|BITCLEAR|BITNOT|BITOR|BITSET|BITSHIFT|BITTEST|BITXOR|CEIL|CLOCK_LOCAL|CLOCK_MILLIS|CLOCK_STR|CLOCK_TZ|CLOCK_UTC|CONTAINS|CONTAINS_TOKEN|CONTAINS_TOKEN_LIKE|CONTAINS_TOKEN_REGEXP|COS|COUNT|CURL|DATE_ADD_MILLIS|DATE_ADD_STR|DATE_DIFF_MILLIS|DATE_DIFF_STR|DATE_FORMAT_STR|DATE_PART_MILLIS|DATE_PART_STR|DATE_RANGE_MILLIS|DATE_RANGE_STR|DATE_TRUNC_MILLIS|DATE_TRUNC_STR|DECODE_JSON|DEGREES|DURATION_TO_STR|E|ENCODED_SIZE|ENCODE_JSON|EXP|FLOOR|GREATEST|HAS_TOKEN|IFINF|IFMISSING|IFMISSINGORNULL|IFNAN|IFNANORINF|IFNULL|INITCAP|ISARRAY|ISATOM|IsBitSET|ISBOOLEAN|ISNUMBER|ISOBJECT|ISSTRING|LEAST|LENGTH|LN|LOG|LOWER|LTRIM|MAX|META|MILLIS|MILLIS_TO_LOCAL|MILLIS_TO_STR|MILLIS_TO_TZ|MILLIS_TO_UTC|MILLIS_TO_ZONE_NAME|MIN|MISSINGIF|NANIF|NEGINFIF|NOW_LOCAL|NOW_MILLIS|NOW_STR|NOW_TZ|NOW_UTC|NULLIF|OBJECT_ADD|OBJECT_CONCAT|OBJECT_INNER_PAIRS|OBJECT_INNER_VALUES|OBJECT_LENGTH|OBJECT_NAMES|OBJECT_PAIRS|OBJECT_PUT|OBJECT_REMOVE|OBJECT_RENAME|OBJECT_REPLACE|OBJECT_UNWRAP|OBJECT_VALUES|PAIRS|PI|POLY_LENGTH|POSINFIF|POSITION|POWER|RADIANS|RANDOM|REGEXP_CONTAINS|REGEXP_LIKE|REGEXP_POSITION|REGEXP_REPLACE|REPEAT|REPLACE|REVERSE|ROUND|RTRIM|SIGN|SIN|SPLIT|SQRT|STR_TO_DURATION|STR_TO_MILLIS|STR_TO_TZ|STR_TO_UTC|STR_TO_ZONE_NAME|SUBSTR|SUFFIXES|SUM|TAN|TITLE|TOARRAY|TOATOM|TOBOOLEAN|TOKENS|TONUMBER|TOOBJECT|TOSTRING|TRIM|TRUNC|TYPE|UPPER|WEEKDAY_MILLIS|WEEKDAY_STR)(?=\s*\()/i,
'keyword': /\b(?:ALL|ALTER|ANALYZE|AS|ASC|BEGIN|BINARY|BOOLEAN|BREAK|BUCKET|BUILD|BY|CALL|CAST|CLUSTER|COLLATE|COLLECTION|COMMIT|CONNECT|CONTINUE|CORRELATE|COVER|CREATE|DATABASE|DATASET|DATASTORE|DECLARE|DECREMENT|DELETE|DERIVED|DESC|DESCRIBE|DISTINCT|DO|DROP|EACH|ELEMENT|EXCEPT|EXCLUDE|EXECUTE|EXPLAIN|FETCH|FLATTEN|FOR|FORCE|FROM|FUNCTION|GRANT|GROUP|GSI|HAVING|IF|IGNORE|ILIKE|INCLUDE|INCREMENT|INDEX|INFER|INLINE|INNER|INSERT|INTERSECT|INTO|IS|JOIN|KEY|KEYS|KEYSPACE|KNOWN|LAST|LEFT|LET|LETTING|LIMIT|LSM|MAP|MAPPING|MATCHED|MATERIALIZED|MERGE|MINUS|MISSING|NAMESPACE|NEST|NULL|NUMBER|OBJECT|OFFSET|ON|OPTION|ORDER|OUTER|OVER|PARSE|PARTITION|PASSWORD|PATH|POOL|PREPARE|PRIMARY|PRIVATE|PRIVILEGE|PROCEDURE|PUBLIC|RAW|REALM|REDUCE|RENAME|RETURN|RETURNING|REVOKE|RIGHT|ROLE|ROLLBACK|SATISFIES|SCHEMA|SELECT|SELF|SEMI|SET|SHOW|SOME|START|STATISTICS|STRING|SYSTEM|TO|TRANSACTION|TRIGGER|TRUNCATE|UNDER|UNION|UNIQUE|UNKNOWN|UNNEST|UNSET|UPDATE|UPSERT|USE|USER|USING|VALIDATE|VALUE|VALUES|VIA|VIEW|WHERE|WHILE|WITH|WORK|XOR)\b/i,
'parameter': /\$[\w.]+/,
// https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/reservedwords.html#n1ql-reserved-words
'keyword': /\b(?:ADVISE|ALL|ALTER|ANALYZE|AS|ASC|AT|BEGIN|BINARY|BOOLEAN|BREAK|BUCKET|BUILD|BY|CALL|CAST|CLUSTER|COLLATE|COLLECTION|COMMIT|COMMITTED|CONNECT|CONTINUE|CORRELATE|CORRELATED|COVER|CREATE|CURRENT|DATABASE|DATASET|DATASTORE|DECLARE|DECREMENT|DELETE|DERIVED|DESC|DESCRIBE|DISTINCT|DO|DROP|EACH|ELEMENT|EXCEPT|EXCLUDE|EXECUTE|EXPLAIN|FETCH|FILTER|FLATTEN|FLUSH|FOLLOWING|FOR|FORCE|FROM|FTS|FUNCTION|GOLANG|GRANT|GROUP|GROUPS|GSI|HASH|HAVING|IF|IGNORE|ILIKE|INCLUDE|INCREMENT|INDEX|INFER|INLINE|INNER|INSERT|INTERSECT|INTO|IS|ISOLATION|JAVASCRIPT|JOIN|KEY|KEYS|KEYSPACE|KNOWN|LANGUAGE|LAST|LEFT|LET|LETTING|LEVEL|LIMIT|LSM|MAP|MAPPING|MATCHED|MATERIALIZED|MERGE|MINUS|MISSING|NAMESPACE|NEST|NL|NO|NTH_VALUE|NULL|NULLS|NUMBER|OBJECT|OFFSET|ON|OPTION|OPTIONS|ORDER|OTHERS|OUTER|OVER|PARSE|PARTITION|PASSWORD|PATH|POOL|PRECEDING|PREPARE|PRIMARY|PRIVATE|PRIVILEGE|PROBE|PROCEDURE|PUBLIC|RANGE|RAW|REALM|REDUCE|RENAME|RESPECT|RETURN|RETURNING|REVOKE|RIGHT|ROLE|ROLLBACK|ROW|ROWS|SATISFIES|SAVEPOINT|SCHEMA|SCOPE|SELECT|SELF|SEMI|SET|SHOW|SOME|START|STATISTICS|STRING|SYSTEM|TIES|TO|TRAN|TRANSACTION|TRIGGER|TRUNCATE|UNBOUNDED|UNDER|UNION|UNIQUE|UNKNOWN|UNNEST|UNSET|UPDATE|UPSERT|USE|USER|USING|VALIDATE|VALUE|VALUES|VIA|VIEW|WHERE|WHILE|WINDOW|WITH|WORK|XOR)\b/i,
'function': /\b[a-z_]\w*(?=\s*\()/i,
'boolean': /\b(?:FALSE|TRUE)\b/i,
'number': /(?:\b\d+\.|\B\.)\d+e[+\-]?\d+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
'operator': /[-+*\/%]|!=|==?|\|\||<[>=]?|>=?|\b(?:AND|ANY|ARRAY|BETWEEN|CASE|ELSE|END|EVERY|EXISTS|FIRST|IN|LIKE|NOT|OR|THEN|VALUED|WHEN|WITHIN)\b/i,

Some generated files are not rendered by default. Learn more.

@@ -2,13 +2,17 @@
/* foo
bar */

-- comment

----------------------------------------------------

[
["comment", "/**/"],
["comment", "/* foo\r\nbar */"]
["comment", "/* foo\r\nbar */"],

["comment", "-- comment"]
]

----------------------------------------------------

Checks for comments.
Checks for comments.
@@ -1,8 +1,10 @@
ADVISE
ALL
ALTER
ANALYZE
AS
ASC
AT
BEGIN
BINARY
BOOLEAN
@@ -16,11 +18,14 @@ CLUSTER
COLLATE
COLLECTION
COMMIT
COMMITTED
CONNECT
CONTINUE
CORRELATE
CORRELATED
COVER
CREATE
CURRENT
DATABASE
DATASET
DATASTORE
@@ -40,14 +45,21 @@ EXCLUDE
EXECUTE
EXPLAIN
FETCH
FILTER
FLATTEN
FLUSH
FOLLOWING
FOR
FORCE
FROM
FTS
FUNCTION
GOLANG
GRANT
GROUP
GROUPS
GSI
HASH
HAVING
IF
IGNORE
@@ -62,15 +74,19 @@ INSERT
INTERSECT
INTO
IS
ISOLATION
JAVASCRIPT
JOIN
KEY
KEYS
KEYSPACE
KNOWN
LANGUAGE
LAST
LEFT
LET
LETTING
LEVEL
LIMIT
LSM
MAP
@@ -82,38 +98,52 @@ MINUS
MISSING
NAMESPACE
NEST
NL
NO
NTH_VALUE
NULL
NULLS
NUMBER
OBJECT
OFFSET
ON
OPTION
OPTIONS
ORDER
OTHERS
OUTER
OVER
PARSE
PARTITION
PASSWORD
PATH
POOL
PRECEDING
PREPARE
PRIMARY
PRIVATE
PRIVILEGE
PROBE
PROCEDURE
PUBLIC
RANGE
RAW
REALM
REDUCE
RENAME
RESPECT
RETURN
RETURNING
REVOKE
RIGHT
ROLE
ROLLBACK
ROW
ROWS
SATISFIES
SAVEPOINT
SCHEMA
SCOPE
SELECT
SELF
SEMI
@@ -124,10 +154,13 @@ START
STATISTICS
STRING
SYSTEM
TIES
TO
TRAN
TRANSACTION
TRIGGER
TRUNCATE
UNBOUNDED
UNDER
UNION
UNIQUE
@@ -146,18 +179,21 @@ VIA
VIEW
WHERE
WHILE
WINDOW
WITH
WORK
XOR

----------------------------------------------------

[
["keyword", "ADVISE"],
["keyword", "ALL"],
["keyword", "ALTER"],
["keyword", "ANALYZE"],
["keyword", "AS"],
["keyword", "ASC"],
["keyword", "AT"],
["keyword", "BEGIN"],
["keyword", "BINARY"],
["keyword", "BOOLEAN"],
@@ -171,11 +207,14 @@ XOR
["keyword", "COLLATE"],
["keyword", "COLLECTION"],
["keyword", "COMMIT"],
["keyword", "COMMITTED"],
["keyword", "CONNECT"],
["keyword", "CONTINUE"],
["keyword", "CORRELATE"],
["keyword", "CORRELATED"],
["keyword", "COVER"],
["keyword", "CREATE"],
["keyword", "CURRENT"],
["keyword", "DATABASE"],
["keyword", "DATASET"],
["keyword", "DATASTORE"],
@@ -195,14 +234,21 @@ XOR
["keyword", "EXECUTE"],
["keyword", "EXPLAIN"],
["keyword", "FETCH"],
["keyword", "FILTER"],
["keyword", "FLATTEN"],
["keyword", "FLUSH"],
["keyword", "FOLLOWING"],
["keyword", "FOR"],
["keyword", "FORCE"],
["keyword", "FROM"],
["keyword", "FTS"],
["keyword", "FUNCTION"],
["keyword", "GOLANG"],
["keyword", "GRANT"],
["keyword", "GROUP"],
["keyword", "GROUPS"],
["keyword", "GSI"],
["keyword", "HASH"],
["keyword", "HAVING"],
["keyword", "IF"],
["keyword", "IGNORE"],
@@ -217,15 +263,19 @@ XOR
["keyword", "INTERSECT"],
["keyword", "INTO"],
["keyword", "IS"],
["keyword", "ISOLATION"],
["keyword", "JAVASCRIPT"],
["keyword", "JOIN"],
["keyword", "KEY"],
["keyword", "KEYS"],
["keyword", "KEYSPACE"],
["keyword", "KNOWN"],
["keyword", "LANGUAGE"],
["keyword", "LAST"],
["keyword", "LEFT"],
["keyword", "LET"],
["keyword", "LETTING"],
["keyword", "LEVEL"],
["keyword", "LIMIT"],
["keyword", "LSM"],
["keyword", "MAP"],
@@ -237,38 +287,52 @@ XOR
["keyword", "MISSING"],
["keyword", "NAMESPACE"],
["keyword", "NEST"],
["keyword", "NL"],
["keyword", "NO"],
["keyword", "NTH_VALUE"],
["keyword", "NULL"],
["keyword", "NULLS"],
["keyword", "NUMBER"],
["keyword", "OBJECT"],
["keyword", "OFFSET"],
["keyword", "ON"],
["keyword", "OPTION"],
["keyword", "OPTIONS"],
["keyword", "ORDER"],
["keyword", "OTHERS"],
["keyword", "OUTER"],
["keyword", "OVER"],
["keyword", "PARSE"],
["keyword", "PARTITION"],
["keyword", "PASSWORD"],
["keyword", "PATH"],
["keyword", "POOL"],
["keyword", "PRECEDING"],
["keyword", "PREPARE"],
["keyword", "PRIMARY"],
["keyword", "PRIVATE"],
["keyword", "PRIVILEGE"],
["keyword", "PROBE"],
["keyword", "PROCEDURE"],
["keyword", "PUBLIC"],
["keyword", "RANGE"],
["keyword", "RAW"],
["keyword", "REALM"],
["keyword", "REDUCE"],
["keyword", "RENAME"],
["keyword", "RESPECT"],
["keyword", "RETURN"],
["keyword", "RETURNING"],
["keyword", "REVOKE"],
["keyword", "RIGHT"],
["keyword", "ROLE"],
["keyword", "ROLLBACK"],
["keyword", "ROW"],
["keyword", "ROWS"],
["keyword", "SATISFIES"],
["keyword", "SAVEPOINT"],
["keyword", "SCHEMA"],
["keyword", "SCOPE"],
["keyword", "SELECT"],
["keyword", "SELF"],
["keyword", "SEMI"],
@@ -279,10 +343,13 @@ XOR
["keyword", "STATISTICS"],
["keyword", "STRING"],
["keyword", "SYSTEM"],
["keyword", "TIES"],
["keyword", "TO"],
["keyword", "TRAN"],
["keyword", "TRANSACTION"],
["keyword", "TRIGGER"],
["keyword", "TRUNCATE"],
["keyword", "UNBOUNDED"],
["keyword", "UNDER"],
["keyword", "UNION"],
["keyword", "UNIQUE"],
@@ -301,11 +368,12 @@ XOR
["keyword", "VIEW"],
["keyword", "WHERE"],
["keyword", "WHILE"],
["keyword", "WINDOW"],
["keyword", "WITH"],
["keyword", "WORK"],
["keyword", "XOR"]
]

----------------------------------------------------

Checks for all keywords.
Checks for all keywords.

0 comments on commit 642d93e

Please sign in to comment.