Skip to content

Commit

Permalink
Merge pull request #156 from KxSystems/ecmel-parser
Browse files Browse the repository at this point in the history
[LS] q parser
  • Loading branch information
ecmel authored Oct 26, 2023
2 parents 4dee802 + 3c19fef commit b8ff791
Show file tree
Hide file tree
Showing 9 changed files with 700 additions and 31 deletions.
95 changes: 95 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@
"antlr4ts": "^0.5.0-alpha.4",
"axios": "^1.4.0",
"azure-arm-resource": "^7.4.0",
"chevrotain": "^10.5.0",
"csv-parser": "^3.0.0",
"esbuild-plugin-copy": "^2.1.1",
"extract-zip": "^2.0.1",
Expand Down
87 changes: 87 additions & 0 deletions server/src/parser/lexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 1998-2023 Kx Systems Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

import { Lexer } from "chevrotain";
import {
BinaryLiteral,
ByteLiteral,
CharLiteral,
DateLiteral,
DateTimeLiteral,
FloatLiteral,
IntegerLiteral,
MiliTimeLiteral,
MinuteLiteral,
MonthLiteral,
NanoTimeLiteral,
SecondLiteral,
TimeStampLiteral,
} from "./literals";
import {
BinaryColon,
BlockComment,
Colon,
Dot,
EndOfLine,
Identifier,
Infix,
Keyword,
LBracket,
LCurly,
LParen,
LineComment,
Quote,
RBracket,
RCurly,
RParen,
SemiColon,
Underscore,
WhiteSpace,
} from "./tokens";

export const QTokens = [
BlockComment,
LineComment,
CharLiteral,
WhiteSpace,
EndOfLine,
Quote,
SemiColon,
LParen,
RParen,
LBracket,
RBracket,
LCurly,
RCurly,
Dot,
Underscore,
TimeStampLiteral,
DateTimeLiteral,
MiliTimeLiteral,
NanoTimeLiteral,
DateLiteral,
MonthLiteral,
SecondLiteral,
MinuteLiteral,
FloatLiteral,
BinaryLiteral,
ByteLiteral,
IntegerLiteral,
Infix,
BinaryColon,
Colon,
Keyword,
Identifier,
];

export const QLexer = new Lexer(QTokens);
81 changes: 81 additions & 0 deletions server/src/parser/literals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 1998-2023 Kx Systems Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

import { createToken } from "chevrotain";

export const CharLiteral = createToken({
name: "CharLiteral",
pattern: /"(?:\\.|(?:(?!\r?\n\S)[^"]))*"/,
});

export const FloatLiteral = createToken({
name: "FloatLiteral",
pattern: /-?(?:\d+\.\d+|\.\d+|\d+\.)(?:e[+-]?\d?\d)?e?/,
});

export const IntegerLiteral = createToken({
name: "IntegerLiteral",
pattern: /-?\d+[jhi]?/,
});

export const BinaryLiteral = createToken({
name: "BinaryLiteral",
pattern: /[01]+b/,
});

export const ByteLiteral = createToken({
name: "ByteLiteral",
pattern: /0x(?:[0-9a-fA-F]{2})+/,
});

export const DateLiteral = createToken({
name: "DateLiteral",
pattern: /\d{4}\.\d{2}\.\d{2}/,
});

export const MiliTimeLiteral = createToken({
name: "MiliTimeLiteral",
pattern: /\d{2}:\d{2}:\d{2}\.\d{3}/,
});

export const NanoTimeLiteral = createToken({
name: "NanoTimeLiteral",
pattern: /(?:0D)?\d{2}:\d{2}:\d{2}\.\d{9}/,
});

export const DateTimeLiteral = createToken({
name: "DateTimeLiteral",
pattern: /\d{4}\.\d{2}\.\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/,
});

export const TimeStampLiteral = createToken({
name: "TimeStampLiteral",
pattern: /\d{4}\.\d{2}\.\d{2}D\d{2}:\d{2}:\d{2}\.\d{9}/,
});

export const MonthLiteral = createToken({
name: "MonthLiteral",
pattern: /\d{4}\.\d{2}m/,
longer_alt: DateLiteral,
});

export const SecondLiteral = createToken({
name: "SecondLiteral",
pattern: /\d{2}:\d{2}:\d{2}/,
});

export const MinuteLiteral = createToken({
name: "MinuteLiteral",
pattern: /\d{2}:\d{2}/,
longer_alt: SecondLiteral,
});
Loading

0 comments on commit b8ff791

Please sign in to comment.