diff --git a/server/src/parser/keywords.ts b/server/src/parser/keywords.ts index 8c5863e4..c913f15f 100644 --- a/server/src/parser/keywords.ts +++ b/server/src/parser/keywords.ts @@ -20,6 +20,12 @@ export const Identifier = createToken({ pattern: IdentifierPattern, }); +export const System = createToken({ + name: "System", + pattern: /system/, + longer_alt: Identifier, +}); + export const LSql = createToken({ name: "LSql", pattern: /(?:select|exec|update|delete)/, diff --git a/server/src/parser/language.ts b/server/src/parser/language.ts index 5e3c7447..9f4d2408 100644 --- a/server/src/parser/language.ts +++ b/server/src/parser/language.ts @@ -40,10 +40,6 @@ import { writeFileSync } from "fs"; import { resolve } from "path"; import { Quke, qukeNoDescription, qukeWithDescription } from "./quke"; -function _(token: TokenType | RegExp) { - return ("PATTERN" in token ? `${token.PATTERN}` : `${token}`).slice(1, -1); -} - const includes = [ { include: "#multiline", @@ -83,14 +79,6 @@ const qdoc = { }, ], }, - { - name: "variable.other.qdoc", - match: "[\\w.]+?(?=\\s*{.+})", - }, - { - name: "variable.other.qdoc", - match: "\\s\\.[\\w.]+?\\s", - }, ], }, ], @@ -278,6 +266,10 @@ const language = { repository, }; +function _(token: TokenType | RegExp) { + return ("PATTERN" in token ? `${token.PATTERN}` : `${token}`).slice(1, -1); +} + export function generateTextMateGrammar() { const grammar = JSON.stringify(language, null, 2); writeFileSync(resolve("syntaxes", "q.tmLanguage.json"), grammar); diff --git a/server/src/parser/lexer.ts b/server/src/parser/lexer.ts index f8c7f823..5beaed53 100644 --- a/server/src/parser/lexer.ts +++ b/server/src/parser/lexer.ts @@ -12,7 +12,7 @@ */ import { Lexer } from "chevrotain"; -import { RSql, Identifier, Keyword, LSql, Reserved } from "./keywords"; +import { RSql, Identifier, Keyword, LSql, Reserved, System } from "./keywords"; import { BinaryLiteral, ByteLiteral, @@ -83,6 +83,7 @@ const QTokens = [ BinaryLiteral, ByteLiteral, NumberLiteral, + System, LSql, RSql, Keyword, diff --git a/server/src/parser/parser.ts b/server/src/parser/parser.ts index 5f0b08be..96a18f8b 100644 --- a/server/src/parser/parser.ts +++ b/server/src/parser/parser.ts @@ -24,7 +24,7 @@ import { RCurly, RParen, } from "./tokens"; -import { Identifier, IdentifierPattern, LSql, RSql } from "./keywords"; +import { Identifier, IdentifierPattern, LSql, RSql, System } from "./keywords"; import { After, AfterEach, @@ -45,6 +45,7 @@ import { ToMatch, Tolerance, } from "./quke"; +import { CharLiteral } from "./literals"; function args(image: string, count: number): string[] { return image.split(/\s+/, count); @@ -96,6 +97,12 @@ export function parse(text: string): Token[] { let argument = 0; let token, prev, next: IToken; + const _namespace = (arg: string) => { + if (arg?.startsWith(".") && isIdentifier(arg)) { + namespace = arg === "." ? "" : arg; + } + }; + for (let i = 0; i < tokens.length; i++) { token = tokens[i]; switch (token.tokenType) { @@ -170,12 +177,23 @@ export function parse(text: string): Token[] { const [cmd, arg] = args(token.image, 2); switch (cmd) { case "\\d": - if (arg?.startsWith(".") && isIdentifier(arg)) { - namespace = arg === "." ? "" : arg; - } + _namespace(arg); break; } break; + case System: + next = tokens[i + 1]; + if (next?.tokenType === CharLiteral) { + const [cmd, arg] = args(next.image.slice(1, -1), 2); + switch (cmd) { + case "d": + if (token.startColumn === 1) { + _namespace(arg); + } + break; + } + } + break; case Bench: case Feature: case Replicate: diff --git a/syntaxes/q.tmLanguage.json b/syntaxes/q.tmLanguage.json index 7daf63fa..f8e5176e 100644 --- a/syntaxes/q.tmLanguage.json +++ b/syntaxes/q.tmLanguage.json @@ -198,14 +198,6 @@ "match": "\\b(type|atom|anything|dict|enum|function|hsym|option|string|table|tuple|typedef|vector|bool|boolean|byte|char|character|date|datetime|float|guid|int|integer|long|minute|month|real|second|short|string|symbol|time|timespan|timestamp)\\b" } ] - }, - { - "name": "variable.other.qdoc", - "match": "[\\w.]+?(?=\\s*{.+})" - }, - { - "name": "variable.other.qdoc", - "match": "\\s\\.[\\w.]+?\\s" } ] }