Skip to content

Commit

Permalink
added static system d
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Apr 26, 2024
1 parent 8a5a26c commit 7ef703d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
6 changes: 6 additions & 0 deletions server/src/parser/keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)/,
Expand Down
16 changes: 4 additions & 12 deletions server/src/parser/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -83,14 +79,6 @@ const qdoc = {
},
],
},
{
name: "variable.other.qdoc",
match: "[\\w.]+?(?=\\s*{.+})",
},
{
name: "variable.other.qdoc",
match: "\\s\\.[\\w.]+?\\s",
},
],
},
],
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion server/src/parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -83,6 +83,7 @@ const QTokens = [
BinaryLiteral,
ByteLiteral,
NumberLiteral,
System,
LSql,
RSql,
Keyword,
Expand Down
26 changes: 22 additions & 4 deletions server/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 0 additions & 8 deletions syntaxes/q.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
Expand Down

0 comments on commit 7ef703d

Please sign in to comment.