Skip to content

Commit

Permalink
update language
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Apr 26, 2024
1 parent dbe2806 commit 8a5a26c
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 364 deletions.
291 changes: 136 additions & 155 deletions server/src/parser/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Identifier, Keyword, Reserved } from "./keywords";
import {
Colon,
Command,
Comparator,
DoubleColon,
Iterator,
LineComment,
Expand All @@ -45,10 +46,7 @@ function _(token: TokenType | RegExp) {

const includes = [
{
include: "#comments",
},
{
include: "#strings",
include: "#multiline",
},
{
include: "#literals",
Expand All @@ -57,13 +55,7 @@ const includes = [
include: "#keywords",
},
{
include: "#identifiers",
},
{
include: "#commands",
},
{
include: "#operators",
include: "#tokens",
},
];

Expand Down Expand Up @@ -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",
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions server/src/parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {
Tolerance,
} from "./quke";

const Prelude = [BlockComment, LastComment, LineComment, CharLiteral];
const MultiLine = [BlockComment, LastComment, LineComment, CharLiteral];

const QTokens = [
Command,
Expand Down Expand Up @@ -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 },
Expand Down
3 changes: 1 addition & 2 deletions server/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export interface Token extends IToken {
identifierKind?: IdentifierKind;
scope?: Token;
lambda?: Token;
description?: string;
}

export function parse(text: string): Token[] {
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 8a5a26c

Please sign in to comment.