From 7fe3a19d323ba86f5fff684327aae39ed9000382 Mon Sep 17 00:00:00 2001 From: Isak Date: Thu, 28 Nov 2024 10:20:12 +0100 Subject: [PATCH 01/12] added parsing of preparser options for cypher versions and key=value --- .../src/antlr-grammar/CypherPreLexer.g4 | 5 +- .../src/antlr-grammar/CypherPreParser.g4 | 2 +- .../semanticValidation.test.ts | 180 ++++++++++++++++++ 3 files changed, 185 insertions(+), 2 deletions(-) diff --git a/packages/language-support/src/antlr-grammar/CypherPreLexer.g4 b/packages/language-support/src/antlr-grammar/CypherPreLexer.g4 index a2438d6b..91777d5d 100644 --- a/packages/language-support/src/antlr-grammar/CypherPreLexer.g4 +++ b/packages/language-support/src/antlr-grammar/CypherPreLexer.g4 @@ -6,4 +6,7 @@ EXPLAIN: E X P L A I N; PROFILE: - P R O F I L E; \ No newline at end of file + P R O F I L E; + +CYPHER: + C Y P H E R; \ No newline at end of file diff --git a/packages/language-support/src/antlr-grammar/CypherPreParser.g4 b/packages/language-support/src/antlr-grammar/CypherPreParser.g4 index bceb0919..2a1b34ba 100644 --- a/packages/language-support/src/antlr-grammar/CypherPreParser.g4 +++ b/packages/language-support/src/antlr-grammar/CypherPreParser.g4 @@ -8,4 +8,4 @@ preparsedStatement: preparserOption? statement; preparserOption: - EXPLAIN | PROFILE; \ No newline at end of file + EXPLAIN | PROFILE | CYPHER (UNSIGNED_DECIMAL_INTEGER | IDENTIFIER EQ (IDENTIFIER | numberLiteral))*; \ No newline at end of file diff --git a/packages/language-support/src/tests/syntaxValidation/semanticValidation.test.ts b/packages/language-support/src/tests/syntaxValidation/semanticValidation.test.ts index 58f532c4..312edffd 100644 --- a/packages/language-support/src/tests/syntaxValidation/semanticValidation.test.ts +++ b/packages/language-support/src/tests/syntaxValidation/semanticValidation.test.ts @@ -100,6 +100,186 @@ describe('Semantic validation spec', () => { ]); }); + test('Semantic errors work using empty preparser options. Like CYPHER { + const query = `CYPHER MATCH (n); + CYPHER MATCH (m) RETURN n`; + + expect(getDiagnosticsForQuery({ query })).toEqual([ + { + message: + 'Query cannot conclude with MATCH (must be a RETURN clause, a FINISH clause, an update clause, a unit subquery call, or a procedure call with no YIELD).', + offsets: { + end: 16, + start: 7, + }, + range: { + end: { + character: 16, + line: 0, + }, + start: { + character: 7, + line: 0, + }, + }, + severity: 1, + }, + { + message: 'Variable `n` not defined', + offsets: { + end: 62, + start: 61, + }, + range: { + end: { + character: 44, + line: 1, + }, + start: { + character: 43, + line: 1, + }, + }, + severity: 1, + }, + ]); + }); + + test('Semantic errors work using both version syntax and key-value syntax for preparser options. Like CYPHER