Skip to content

Commit

Permalink
Updates parser to Cypher 25 (#329)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Nacho Cordon <nacho.cordon@neotechnology.com>
  • Loading branch information
anderson4j and ncordon authored Jan 20, 2025
1 parent c6e0691 commit bad96d7
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 221 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ unescapedLabelSymbolicNameString:
| DISCONNECT
| WELCOME
| SYSINFO
| unescapedLabelSymbolicNameString_
| unescapedSymbolicNameString_
;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lexer grammar CypherPreLexer;

import Cypher5Lexer;
import Cypher25Lexer;

EXPLAIN:
E X P L A I N;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parser grammar CypherPreParser;

import Cypher5Parser;
import Cypher25Parser;

options { tokenVocab = CypherPreLexer; }

Expand Down
9 changes: 2 additions & 7 deletions packages/language-support/src/lexerSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const lexerGarbage = [
export const identifier = [
CypherLexer.IDENTIFIER,
CypherLexer.ESCAPED_SYMBOLIC_NAME,
CypherLexer.EXTENDED_IDENTIFIER,
];

export const lexerComment = [
Expand All @@ -114,7 +115,6 @@ export const lexerKeywords = [
CypherLexer.AS,
CypherLexer.ASC,
CypherLexer.ASCENDING,
CypherLexer.ASSERT,
CypherLexer.ASSIGN,
CypherLexer.AT,
CypherLexer.AUTH,
Expand All @@ -124,8 +124,6 @@ export const lexerKeywords = [
CypherLexer.BOOSTED,
CypherLexer.BOTH,
CypherLexer.BREAK,
CypherLexer.BRIEF,
CypherLexer.BTREE,
CypherLexer.BUILT,
CypherLexer.BY,
CypherLexer.CALL,
Expand All @@ -136,7 +134,6 @@ export const lexerKeywords = [
CypherLexer.COLLECT,
CypherLexer.COMMAND,
CypherLexer.COMMANDS,
CypherLexer.COMMIT,
CypherLexer.COMPOSITE,
CypherLexer.CONSTRAINT,
CypherLexer.CONSTRAINTS,
Expand Down Expand Up @@ -185,6 +182,7 @@ export const lexerKeywords = [
CypherLexer.EXIST,
CypherLexer.EXISTENCE,
CypherLexer.EXISTS,
CypherLexer.EXTENDED_IDENTIFIER,
CypherLexer.FAIL,
CypherLexer.FALSE,
CypherLexer.FIELDTERMINATOR,
Expand Down Expand Up @@ -257,12 +255,10 @@ export const lexerKeywords = [
CypherLexer.OPTIONS,
CypherLexer.OR,
CypherLexer.ORDER,
CypherLexer.OUTPUT,
CypherLexer.PASSWORD,
CypherLexer.PASSWORDS,
CypherLexer.PATH,
CypherLexer.PATHS,
CypherLexer.PERIODIC,
CypherLexer.PLAINTEXT,
CypherLexer.POINT,
CypherLexer.POPULATED,
Expand Down Expand Up @@ -352,7 +348,6 @@ export const lexerKeywords = [
CypherLexer.USING,
CypherLexer.VALUE,
CypherLexer.VECTOR,
CypherLexer.VERBOSE,
CypherLexer.VERTEX,
CypherLexer.WAIT,
CypherLexer.WHEN,
Expand Down
5 changes: 2 additions & 3 deletions packages/language-support/src/parserWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
default as CypherParser,
FunctionNameContext,
LabelNameContext,
LabelNameIsContext,
LabelOrRelTypeContext,
ProcedureNameContext,
ProcedureResultItemContext,
Expand Down Expand Up @@ -230,7 +229,7 @@ class LabelAndRelTypesCollector extends ParseTreeListener {
}

exitEveryRule(ctx: unknown) {
if (ctx instanceof LabelNameContext || ctx instanceof LabelNameIsContext) {
if (ctx instanceof LabelNameContext) {
// If the parent ctx start doesn't coincide with this ctx start,
// it means the parser recovered from an error reading the label
// like in the case MATCH (n:) RETURN n
Expand Down Expand Up @@ -310,7 +309,7 @@ class VariableCollector implements ParseTreeListener {
}
}
if (ctx instanceof ProcedureResultItemContext) {
const variable = ctx.symbolicNameString().getText();
const variable = ctx.getText();
if (variable) {
this.variables.push(variable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
FunctionNameContext,
KeywordLiteralContext,
LabelNameContext,
LabelNameIsContext,
LabelOrRelTypeContext,
LabelTypeContext,
LeftArrowContext,
Expand Down Expand Up @@ -127,10 +126,6 @@ class SyntaxHighlighter extends CypherParserListener {
this.addToken(ctx.start, CypherTokenType.label, ctx.getText());
};

exitLabelNameIs = (ctx: LabelNameIsContext) => {
this.addToken(ctx.start, CypherTokenType.label, ctx.getText());
};

exitLabelType = (ctx: LabelTypeContext) => {
const labelName = ctx.symbolicNameString()?.start;
if (labelName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export function completionCoreErrormessage(
const rulesOfInterest: Record<number, string | null> = {
[CypherParser.RULE_expression9]: 'an expression',
[CypherParser.RULE_labelExpression2]: 'a node label / rel type',
[CypherParser.RULE_labelExpression2Is]: 'a node label / rel type',
[CypherParser.RULE_procedureName]: 'a procedure name',
[CypherParser.RULE_stringLiteral]: 'a string',
[CypherParser.RULE_numberLiteral]: 'a number literal',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ describe('Inserts correct text when symbolic name is not display name', () => {
expected: [
{ kind: 14, label: 'IF NOT EXISTS' },
{ kind: 14, label: 'FOR' },
{ kind: 14, label: 'ON' },
],
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('Completes parameters outside of databases, roles, user names', () => {

test('Suggests parameter in options field of create constraint', () => {
const query =
'CREATE CONSTRAINT abc ON (n:person) ASSERT EXISTS n.name OPTIONS ';
'CREATE CONSTRAINT abc FOR (n:person) REQUIRE n.name IS NOT NULL OPTIONS ';
testCompletions({
query,
dbSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('unscoped variable completions', () => {
});

test('suggests variables for index hint rule', () => {
const query = 'match (n) USING BTREE INDEX ';
const query = 'match (n) USING RANGE INDEX ';

testCompletions({
query,
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension/syntaxes/cypher.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"name": "keyword.operator"
},
{
"match": "(?i)\\b(ACCESS|ACTIVE|ADMIN|ADMINISTRATOR|ALIAS|ALIASES|ALL|allShortestPaths|ALTER|AND|ANY|ARRAY|AS|ASC|ASCENDING|ASSERT|ASSIGN|AT|AUTH|BINDINGS|BOOL|BOOLEAN|BOOSTED|BOTH|BREAK|BRIEF|BTREE|BUILT|BY|CALL|CASCADE|CASE|CIDR|CHANGE|COLLECT|COMMAND|COMMANDS|COMMIT|COMPOSITE|CONSTRAINT|CONSTRAINTS|CONTAINS|CONTINUE|COPY|COUNT|CREATE|CSV|CONCURRENT|CURRENT|DATA|DATABASE|DATABASES|DATE|DATETIME|DBMS|DEALLOCATE|DEFAULT|DEFINED|DELETE|DENY|DESC|DESCENDING|DESTROY|DETACH|DIFFERENT|DISTINCT|DRIVER|DROP|DRYRUN|DUMP|DURATION|EACH|EDGE|ELEMENT|ELEMENTS|ELSE|ENABLE|ENCRYPTED|END|ENDS|ERROR|EXECUTABLE|EXECUTE|EXIST|EXISTENCE|EXISTS|FAIL|FALSE|FIELDTERMINATOR|FINISH|FLOAT|FOR|FOREACH|FROM|FULLTEXT|FUNCTION|FUNCTIONS|GRANT|GRAPH|GRAPHS|GROUP|GROUPS|HEADERS|HOME|ID|IF|IMMUTABLE|IMPERSONATE|IN|INDEX|INDEXES|INF|INFINITY|INSERT|INT|INTEGER|IS|JOIN|KEY|LABEL|LABELS|LEADING|LIMIT|LIST|LOAD|LOCAL|LOOKUP|MANAGEMENT|MAP|MATCH|MERGE|NAME|NAMES|NAN|NEW|NFC|NFD|NFKC|NFKD|NODE|NODETACH|NODES|NONE|NORMALIZE|NORMALIZED|NOT|NOTHING|NOWAIT|NULL|OF|OFFSET|ON|ONLY|OPTION|OPTIONAL|OPTIONS|OR|ORDER|OUTPUT|PASSWORD|PASSWORDS|PATH|PATHS|PERIODIC|PLAINTEXT|POINT|POPULATED|PRIMARY|PRIMARIES|PRIVILEGE|PRIVILEGES|PROCEDURE|PROCEDURES|PROPERTIES|PROPERTY|PROVIDER|PROVIDERS|RANGE|READ|REALLOCATE|REDUCE|REL|RELATIONSHIP|RELATIONSHIPS|REMOVE|RENAME|REPEATABLE|REPLACE|REPORT|REQUIRE|REQUIRED|RESTRICT|RETURN|REVOKE|ROLE|ROLES|ROW|ROWS|SCAN|SECONDARY|SECONDARIES|SEC|SECOND|SECONDS|SEEK|SERVER|SERVERS|SET|SETTING|SETTINGS|SHORTEST|shortestPath|SHOW|SIGNED|SINGLE|SKIP|START|STARTS|STATUS|STOP|VARCHAR|STRING|SUPPORTED|SUSPENDED|TARGET|TERMINATE|TEXT|THEN|TIME|TIMESTAMP|TIMEZONE|TO|TOPOLOGY|TRAILING|TRANSACTION|TRANSACTIONS|TRAVERSE|TRIM|TRUE|TYPE|TYPED|TYPES|UNION|UNIQUE|UNIQUENESS|UNWIND|URL|USE|USER|USERS|USING|VALUE|VECTOR|VERBOSE|VERTEX|WAIT|WHEN|WHERE|WITH|WITHOUT|WRITE|XOR|YIELD|ZONE|ZONED|EXPLAIN|PROFILE|CYPHER)\\b",
"match": "(?i)\\b(ACCESS|ACTIVE|ADMIN|ADMINISTRATOR|ALIAS|ALIASES|ALL|allShortestPaths|ALTER|AND|ANY|ARRAY|AS|ASC|ASCENDING|ASSIGN|AT|AUTH|BINDINGS|BOOL|BOOLEAN|BOOSTED|BOTH|BREAK|BUILT|BY|CALL|CASCADE|CASE|CIDR|CHANGE|COLLECT|COMMAND|COMMANDS|COMPOSITE|CONSTRAINT|CONSTRAINTS|CONTAINS|CONTINUE|COPY|COUNT|CREATE|CSV|CONCURRENT|CURRENT|DATA|DATABASE|DATABASES|DATE|DATETIME|DBMS|DEALLOCATE|DEFAULT|DEFINED|DELETE|DENY|DESC|DESCENDING|DESTROY|DETACH|DIFFERENT|DISTINCT|DRIVER|DROP|DRYRUN|DUMP|DURATION|EACH|EDGE|ELEMENT|ELEMENTS|ELSE|ENABLE|ENCRYPTED|END|ENDS|ERROR|EXECUTABLE|EXECUTE|EXIST|EXISTENCE|EXISTS|EXTENDED_IDENTIFIER|FAIL|FALSE|FIELDTERMINATOR|FINISH|FLOAT|FOR|FOREACH|FROM|FULLTEXT|FUNCTION|FUNCTIONS|GRANT|GRAPH|GRAPHS|GROUP|GROUPS|HEADERS|HOME|ID|IF|IMMUTABLE|IMPERSONATE|IN|INDEX|INDEXES|INF|INFINITY|INSERT|INT|INTEGER|IS|JOIN|KEY|LABEL|LABELS|LEADING|LIMIT|LIST|LOAD|LOCAL|LOOKUP|MANAGEMENT|MAP|MATCH|MERGE|NAME|NAMES|NAN|NEW|NFC|NFD|NFKC|NFKD|NODE|NODETACH|NODES|NONE|NORMALIZE|NORMALIZED|NOT|NOTHING|NOWAIT|NULL|OF|OFFSET|ON|ONLY|OPTION|OPTIONAL|OPTIONS|OR|ORDER|PASSWORD|PASSWORDS|PATH|PATHS|PLAINTEXT|POINT|POPULATED|PRIMARY|PRIMARIES|PRIVILEGE|PRIVILEGES|PROCEDURE|PROCEDURES|PROPERTIES|PROPERTY|PROVIDER|PROVIDERS|RANGE|READ|REALLOCATE|REDUCE|REL|RELATIONSHIP|RELATIONSHIPS|REMOVE|RENAME|REPEATABLE|REPLACE|REPORT|REQUIRE|REQUIRED|RESTRICT|RETURN|REVOKE|ROLE|ROLES|ROW|ROWS|SCAN|SECONDARY|SECONDARIES|SEC|SECOND|SECONDS|SEEK|SERVER|SERVERS|SET|SETTING|SETTINGS|SHORTEST|shortestPath|SHOW|SIGNED|SINGLE|SKIP|START|STARTS|STATUS|STOP|VARCHAR|STRING|SUPPORTED|SUSPENDED|TARGET|TERMINATE|TEXT|THEN|TIME|TIMESTAMP|TIMEZONE|TO|TOPOLOGY|TRAILING|TRANSACTION|TRANSACTIONS|TRAVERSE|TRIM|TRUE|TYPE|TYPED|TYPES|UNION|UNIQUE|UNIQUENESS|UNWIND|URL|USE|USER|USERS|USING|VALUE|VECTOR|VERTEX|WAIT|WHEN|WHERE|WITH|WITHOUT|WRITE|XOR|YIELD|ZONE|ZONED|EXPLAIN|PROFILE|CYPHER)\\b",
"name": "keyword"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
},
{
"character": "output",
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher keyword"
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher variable"
},
{
"character": " ",
Expand Down Expand Up @@ -301,7 +301,7 @@
},
{
"character": "output",
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher keyword"
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher variable"
},
{
"character": " ",
Expand Down Expand Up @@ -365,7 +365,7 @@
},
{
"character": "output",
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher keyword"
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher variable"
},
{
"character": " ",
Expand Down Expand Up @@ -417,7 +417,7 @@
},
{
"character": "output",
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher keyword"
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher variable"
},
{
"character": " ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
},
{
"character": "output",
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher keyword"
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher variable"
},
{
"character": " ",
Expand Down Expand Up @@ -225,7 +225,7 @@
},
{
"character": "output",
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher keyword"
"type": "text.html.markdown markup.fenced_code.block.markdown meta.embedded.block.cypher variable"
},
{
"character": " ",
Expand Down

0 comments on commit bad96d7

Please sign in to comment.