Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add N1QL language support #1620

Merged
merged 4 commits into from
Jan 3, 2019
Merged

Add N1QL language support #1620

merged 4 commits into from
Jan 3, 2019

Conversation

TMWilds
Copy link
Contributor

@TMWilds TMWilds commented Nov 18, 2018

N1QL is a query language for the Couchbase NoSQL database. Fixes #1619.

N1QL, while intentionally similar to SQL, is not an extension or variant of SQL. As such, there are a number of differences in the classification of general keywords, operators and booleans, along with some other differences and structural changes.

This contribution adds syntax highlighting for N1QL, including the full set of builtin functions and operators.

Some examples:
n1qlselectexample
n1qlselectadvancedexample

Implements [N1QL](https://www.couchbase.com/products/n1ql), a query language for Couchbase.
Copy link
Member

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

There are few minor things on which I commented but all in all, it seems like this is a really solid PR.

This is not a full review yet. I just gave it a quick look and will properly review it as soon as I find the time to do so.

components/prism-n1ql.js Outdated Show resolved Hide resolved
components/prism-n1ql.js Outdated Show resolved Hide resolved
'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|ISBOOLEAN|ISNUMBER|ISOBJECT|ISSTRING|IsBitSET|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|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,
'boolean': /\b(?:TRUE|FALSE)\b/i,
'number': /\b[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?\b|\b\d+\.?\d*|\B\.\d+\b/i,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Ignore case flag and [eE]. Please choose one (I recommend the i).
  2. Please remove the first [+\-]?. It will only cause trouble and you don't even match -1.
  3. You don't need to escape the - if it's the last char in a set.
  4. Too bad that my favorite numbers .02e2 and 2. are not matched.

components/prism-n1ql.js Outdated Show resolved Hide resolved
@RunDevelopment
Copy link
Member

Here is my full review:

Your current implementation does not support object construction and array slicing.

These two and my comments are all I could find. Really good work!

@TMWilds
Copy link
Contributor Author

TMWilds commented Nov 19, 2018

@RunDevelopment Thank you for the feedback! Seems to mostly come down to me not being the best with regexes, and a few oversights also...
I'll aim to make the changes and additions you suggested soon. Thanks again!

@TMWilds
Copy link
Contributor Author

TMWilds commented Jan 3, 2019

Took me much longer than I expected to get round to doing this, but the changes @RunDevelopment have been added!

@RunDevelopment
Copy link
Member

Looks really good @TMWilds!

Please resolve the merge conflict, so we can merge this.

Also, could you please add .02e2 and 2. to the number test?

@TMWilds
Copy link
Contributor Author

TMWilds commented Jan 3, 2019

@RunDevelopment maybe an obvious question, but how do you recommend resolving those conflicts given they're generated by the build process? Rebase and then re-build perhaps?

@RunDevelopment
Copy link
Member

The only real conflict is in prism-show-language.js.
To replace

<<<<<<< master
var Languages = /*languages_placeholder[*/{ ... }/*]*/;
======= 
var Languages = /*languages_placeholder[*/{ ... }/*]*/;
>>>>>>> master

with

var Languages = /*languages_placeholder[*/{ ... }/*]*/;

What's between the brackets doesn't really matter, cause gulp will fill it in.

components.js and prism-show-language.min.js are both generated so running gulp will resolve these.

@TMWilds
Copy link
Contributor Author

TMWilds commented Jan 3, 2019

Thanks @RunDevelopment, that seems to have gone well!

@RunDevelopment RunDevelopment merged commit 7def8f5 into PrismJS:master Jan 3, 2019
@RunDevelopment
Copy link
Member

Thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants