From 8a5a26c14120d5330f035ed623095fd3fe0df215 Mon Sep 17 00:00:00 2001 From: ecmel Date: Fri, 26 Apr 2024 07:53:40 +0300 Subject: [PATCH] update language --- server/src/parser/language.ts | 291 ++++++++++++-------------- server/src/parser/lexer.ts | 6 +- server/src/parser/parser.ts | 3 +- syntaxes/q.tmLanguage.json | 378 ++++++++++++++++------------------ 4 files changed, 314 insertions(+), 364 deletions(-) diff --git a/server/src/parser/language.ts b/server/src/parser/language.ts index 8c2f83b1..5e3c7447 100644 --- a/server/src/parser/language.ts +++ b/server/src/parser/language.ts @@ -28,6 +28,7 @@ import { Identifier, Keyword, Reserved } from "./keywords"; import { Colon, Command, + Comparator, DoubleColon, Iterator, LineComment, @@ -45,10 +46,7 @@ function _(token: TokenType | RegExp) { const includes = [ { - include: "#comments", - }, - { - include: "#strings", + include: "#multiline", }, { include: "#literals", @@ -57,13 +55,7 @@ const includes = [ include: "#keywords", }, { - include: "#identifiers", - }, - { - include: "#commands", - }, - { - include: "#operators", + include: "#tokens", }, ]; @@ -140,7 +132,138 @@ const quke = { const BlockComment = [/^\/\s*$/, /^\\\s*$/]; const StringLiteral = [/"/, /\\["\\]/]; -const ControlKeyword = /[$!?#@'^]/; + +const repository = { + quke, + qdoc, + multiline: { + patterns: [ + { + name: "comment.block.q", + begin: _(BlockComment[0]), + end: _(BlockComment[1]), + }, + { + name: "comment.last.q", + begin: _(BlockComment[1]), + }, + { + include: "#qdoc", + }, + { + name: "comment.line.q", + match: _(LineComment), + }, + { + name: "string.quoted.q", + begin: _(StringLiteral[0]), + end: _(StringLiteral[0]), + patterns: [ + { + name: "constant.character.escape.q", + match: _(StringLiteral[1]), + }, + ], + }, + ], + }, + literals: { + patterns: [ + { + name: "support.type.symbol.q", + match: _(SymbolLiteral), + }, + { + name: "constant.numeric.datetime.q", + match: _(DateTimeLiteral), + }, + { + name: "constant.numeric.timestamp.q", + match: _(TimeStampLiteral), + }, + { + name: "constant.numeric.date.q", + match: _(DateLiteral), + }, + { + name: "constant.numeric.month.q", + match: _(MonthLiteral), + }, + { + name: "constant.numeric.time.q", + match: _(TimeLiteral), + }, + { + name: "constant.numeric.file.q", + match: _(FileLiteral), + }, + { + name: "constant.language.infinity.q", + match: _(InfinityLiteral), + }, + { + name: "constant.numeric.binary.q", + match: _(BinaryLiteral), + }, + { + name: "constant.numeric.byte.q", + match: _(ByteLiteral), + }, + { + name: "constant.numeric.number.q", + match: _(NumberLiteral), + }, + ], + }, + keywords: { + patterns: [ + { + name: "keyword.other.reserved.q", + match: `${_(Reserved)}\\b`, + }, + { + name: "keyword.other.q", + match: `\\b${_(Keyword)}\\b`, + }, + { + name: "variable.other.q", + match: `${_(Identifier)}\\b`, + }, + ], + }, + tokens: { + patterns: [ + { + name: "constant.character.q", + match: _(Command), + }, + { + name: "keyword.other.iterator.q", + match: _(Iterator), + }, + { + name: "punctuation.assignment.q", + match: _(DoubleColon), + }, + { + name: "keyword.operator.arithmetic.q", + match: _(Operator), + }, + { + name: "keyword.operator.arithmetic.q", + match: _(Comparator), + }, + { + name: "punctuation.assignment.q", + match: _(Colon), + }, + { + name: "punctuation.terminator.statement.q", + match: _(SemiColon), + }, + ], + }, +}; const language = { description: "This file is auto generated DO NOT EDIT", @@ -152,149 +275,7 @@ const language = { }, ...includes, ], - repository: { - comments: { - patterns: [ - quke, - qdoc, - { - name: "comment.block.q", - begin: _(BlockComment[0]), - end: _(BlockComment[1]), - }, - { - name: "comment.last.q", - begin: _(BlockComment[1]), - }, - { - include: "#qdoc", - }, - { - name: "comment.line.q", - match: _(LineComment), - }, - ], - }, - strings: { - patterns: [ - { - name: "string.quoted.q", - begin: _(StringLiteral[0]), - end: _(StringLiteral[0]), - patterns: [ - { - name: "constant.character.escape.q", - match: _(StringLiteral[1]), - }, - ], - }, - ], - }, - literals: { - patterns: [ - { - name: "support.type.symbol.q", - match: _(SymbolLiteral), - }, - { - name: "constant.numeric.datetime.q", - match: _(DateTimeLiteral), - }, - { - name: "constant.numeric.timestamp.q", - match: _(TimeStampLiteral), - }, - { - name: "constant.numeric.date.q", - match: _(DateLiteral), - }, - { - name: "constant.numeric.month.q", - match: _(MonthLiteral), - }, - { - name: "constant.numeric.time.q", - match: _(TimeLiteral), - }, - { - name: "constant.numeric.file.q", - match: _(FileLiteral), - }, - { - name: "constant.language.infinity.q", - match: _(InfinityLiteral), - }, - { - name: "constant.numeric.binary.q", - match: _(BinaryLiteral), - }, - { - name: "constant.numeric.byte.q", - match: _(ByteLiteral), - }, - { - name: "constant.numeric.number.q", - match: _(NumberLiteral), - }, - ], - }, - keywords: { - patterns: [ - { - name: "keyword.other.reserved.q", - match: `${_(Reserved)}\\b`, - }, - { - name: "keyword.other.q", - match: `\\b${_(Keyword)}\\b`, - }, - ], - }, - identifiers: { - patterns: [ - { - name: "variable.other.q", - match: `${_(Identifier)}\\b`, - }, - ], - }, - commands: { - patterns: [ - { - name: "constant.character.q", - match: _(Command), - }, - ], - }, - operators: { - patterns: [ - { - name: "keyword.other.iterator.q", - match: _(Iterator), - }, - { - name: "keyword.other.control.q", - match: _(ControlKeyword), - }, - { - name: "keyword.operator.arithmetic.q", - match: _(Operator), - }, - { - name: "punctuation.assignment.q", - match: _(Colon), - }, - { - name: "punctuation.assignment.q", - match: _(DoubleColon), - }, - { - name: "punctuation.terminator.statement.q", - match: _(SemiColon), - }, - ], - }, - }, + repository, }; export function generateTextMateGrammar() { diff --git a/server/src/parser/lexer.ts b/server/src/parser/lexer.ts index c50955e5..f8c7f823 100644 --- a/server/src/parser/lexer.ts +++ b/server/src/parser/lexer.ts @@ -68,7 +68,7 @@ import { Tolerance, } from "./quke"; -const Prelude = [BlockComment, LastComment, LineComment, CharLiteral]; +const MultiLine = [BlockComment, LastComment, LineComment, CharLiteral]; const QTokens = [ Command, @@ -128,8 +128,8 @@ export const QLexer = new Lexer( { defaultMode: "q_mode", modes: { - q_mode: [...Prelude, Quke, ...QTokens], - quke_mode: [...Prelude, ...QukeTokens, ...QTokens], + q_mode: [...MultiLine, Quke, ...QTokens], + quke_mode: [...MultiLine, ...QukeTokens, ...QTokens], }, }, { safeMode: true }, diff --git a/server/src/parser/parser.ts b/server/src/parser/parser.ts index afcf8c34..5f0b08be 100644 --- a/server/src/parser/parser.ts +++ b/server/src/parser/parser.ts @@ -83,7 +83,6 @@ export interface Token extends IToken { identifierKind?: IdentifierKind; scope?: Token; lambda?: Token; - description?: string; } export function parse(text: string): Token[] { @@ -171,7 +170,7 @@ export function parse(text: string): Token[] { const [cmd, arg] = args(token.image, 2); switch (cmd) { case "\\d": - if (arg && arg.startsWith(".") && isIdentifier(arg)) { + if (arg?.startsWith(".") && isIdentifier(arg)) { namespace = arg === "." ? "" : arg; } break; diff --git a/syntaxes/q.tmLanguage.json b/syntaxes/q.tmLanguage.json index ca0fb972..7daf63fa 100644 --- a/syntaxes/q.tmLanguage.json +++ b/syntaxes/q.tmLanguage.json @@ -7,10 +7,7 @@ "include": "#quke" }, { - "include": "#comments" - }, - { - "include": "#strings" + "include": "#multiline" }, { "include": "#literals" @@ -19,22 +16,25 @@ "include": "#keywords" }, { - "include": "#identifiers" - }, - { - "include": "#commands" - }, - { - "include": "#operators" + "include": "#tokens" } ], "repository": { - "comments": { + "quke": { "patterns": [ { + "begin": "(?]" }, { "name": "punctuation.assignment.q", - "match": "::" + "match": ":" }, { "name": "punctuation.terminator.statement.q",