@gooddata/maql-antlr4ts 0.6.1-0c023234.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +30 -28
- package/README.md +42 -27
- package/esm/antlr/CaseInsensitiveCharStream.d.ts +3 -3
- package/esm/antlr/CaseInsensitiveCharStream.js +7 -13
- package/esm/antlr/SyntaxErrorListener.d.ts +3 -4
- package/esm/antlr/SyntaxErrorListener.js +5 -6
- package/esm/gen/antlr/MaqlLexer.d.ts +14 -18
- package/esm/gen/antlr/MaqlLexer.js +685 -855
- package/esm/gen/antlr/MaqlParser.d.ts +626 -632
- package/esm/gen/antlr/MaqlParser.js +2483 -2620
- package/esm/gen/antlr/MaqlParserListener.d.ts +283 -400
- package/esm/gen/antlr/MaqlParserListener.js +1047 -2
- package/esm/gen/antlr/MaqlParserVisitor.d.ts +162 -239
- package/esm/gen/antlr/MaqlParserVisitor.js +627 -2
- package/esm/gen.d.ts +2 -2
- package/esm/gen.js +2 -0
- package/esm/visitor/parser/MaqlAstVisitor.d.ts +77 -79
- package/esm/visitor/parser/MaqlAstVisitor.js +246 -242
- package/package.json +4 -4
package/NOTICE
CHANGED
|
@@ -9,7 +9,7 @@ The following 3rd-party software packages may be used by or distributed with
|
|
|
9
9
|
@gooddata/maql-antlr4ts. Any information relevant to third-party vendors listed
|
|
10
10
|
below are collected using common, reasonable means.
|
|
11
11
|
|
|
12
|
-
Date generated: 2026-10-
|
|
12
|
+
Date generated: 2026-10-27
|
|
13
13
|
|
|
14
14
|
================================================================================
|
|
15
15
|
================================================================================
|
|
@@ -21,13 +21,13 @@ Date generated: 2026-10-20
|
|
|
21
21
|
|
|
22
22
|
================================================================================
|
|
23
23
|
|
|
24
|
-
-
|
|
24
|
+
- antlr4ng (3.0.16) [BSD-3-Clause]
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
--------------------------------------------------------------------------------
|
|
28
|
-
Package Title:
|
|
28
|
+
Package Title: antlr4ng (3.0.16)
|
|
29
29
|
|
|
30
|
-
Package Locator: npm+
|
|
30
|
+
Package Locator: npm+antlr4ng$3.0.16
|
|
31
31
|
|
|
32
32
|
Package Depth: Direct
|
|
33
33
|
--------------------------------------------------------------------------------
|
|
@@ -37,40 +37,42 @@ BSD-3-Clause
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
[The "BSD license"]
|
|
40
|
-
Copyright (c)
|
|
41
|
-
All rights reserved.
|
|
40
|
+
Copyright (c) 2012-2023 The ANTLR Project. All rights reserved.
|
|
42
41
|
|
|
43
42
|
Redistribution and use in source and binary forms, with or without
|
|
44
43
|
modification, are permitted provided that the following conditions
|
|
45
44
|
are met:
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
1. Redistributions of source code must retain the above copyright
|
|
47
|
+
notice, this list of conditions and the following disclaimer.
|
|
48
|
+
|
|
49
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
50
|
+
notice, this list of conditions and the following disclaimer in the
|
|
51
|
+
documentation and/or other materials provided with the distribution.
|
|
52
|
+
|
|
53
|
+
3. Neither name of copyright holders nor the names of its contributors
|
|
54
|
+
may be used to endorse or promote products derived from this software
|
|
55
|
+
without specific prior written permission.
|
|
56
|
+
|
|
57
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
58
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
59
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
60
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
|
|
61
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
62
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
63
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
64
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
65
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
66
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
67
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
66
68
|
|
|
67
69
|
|
|
68
70
|
* Package Info *
|
|
69
71
|
|
|
70
|
-
Authors:
|
|
72
|
+
Authors: Mike Lischke and The ANTLR Project
|
|
71
73
|
|
|
72
|
-
Package Homepage: https://github.com/
|
|
74
|
+
Package Homepage: https://github.com/mike-lischke/antlr4ng
|
|
73
75
|
|
|
74
|
-
Package Download URL: https://registry.npmjs.org/
|
|
76
|
+
Package Download URL: https://registry.npmjs.org/antlr4ng/-/antlr4ng-3.0.16.tgz
|
|
75
77
|
|
|
76
78
|
--------------------------------------------------------------------------------
|
package/README.md
CHANGED
|
@@ -3,54 +3,70 @@
|
|
|
3
3
|
The module bundles TypeScript MAQL lexer and parser generated from MAQL grammar,
|
|
4
4
|
a visitor to create MAQL AST, and an abstract AST visitor to work with MAQL AST.
|
|
5
5
|
|
|
6
|
-
The
|
|
7
|
-
|
|
6
|
+
The lexer and parser are generated by [antlr-ng](https://github.com/mike-lischke/antlr-ng) and run on the
|
|
7
|
+
[antlr4ng](https://github.com/mike-lischke/antlr4ng) runtime, which is declared as a dependency of this package.
|
|
8
|
+
The runtime has no dependencies of its own and no Node.js built-in requirements, so the package works in browsers
|
|
9
|
+
without polyfills.
|
|
10
|
+
|
|
11
|
+
> Note: `antlr4ng` must resolve to a single copy in the consuming application. If the application depends on
|
|
12
|
+
> `antlr4ng` directly or through another package (for example `antlr4-c3`), it must use the exact same version as
|
|
13
|
+
> this package, otherwise `instanceof` checks between the runtime copies fail.
|
|
14
|
+
|
|
15
|
+
The package name keeps the historical `antlr4ts` suffix; the `antlr4ts` runtime is no longer used.
|
|
8
16
|
|
|
9
17
|
Example usage:
|
|
10
18
|
|
|
11
19
|
```typescript
|
|
12
|
-
import { CommonTokenStream } from "
|
|
20
|
+
import { CharStream, CommonTokenStream } from "antlr4ng";
|
|
13
21
|
|
|
14
|
-
import {
|
|
15
|
-
CaseInsensitiveCharStream,
|
|
16
|
-
MaqlLexer,
|
|
17
|
-
MaqlParser,
|
|
18
|
-
MaqlAstVisitor,
|
|
19
|
-
AstNormalizer,
|
|
20
|
-
} from "@gooddata/maql-antlr4ts";
|
|
22
|
+
import { MaqlLexer, MaqlParser, MaqlAstVisitor, AstNormalizer } from "@gooddata/maql-antlr4ts";
|
|
21
23
|
|
|
22
24
|
const maql =
|
|
23
25
|
"parse metric SELECT SUM(0.81 * {fact/price} * {fact/quantity}) BY {attribute/country} WITHOUT PF";
|
|
24
|
-
const charStream =
|
|
26
|
+
const charStream = CharStream.fromString(maql);
|
|
25
27
|
const lexer = new MaqlLexer(charStream);
|
|
26
28
|
const tokenStream = new CommonTokenStream(lexer);
|
|
27
29
|
const parser = new MaqlParser(tokenStream);
|
|
28
30
|
const parseTree = parser.maql();
|
|
29
|
-
const astVisitor = new MaqlAstVisitor(workspace);
|
|
31
|
+
const astVisitor = new MaqlAstVisitor(workspace, tokenStream);
|
|
30
32
|
const ast = astVisitor.visit(parseTree);
|
|
31
33
|
const normalizer = new AstNormalizer();
|
|
32
34
|
const normalizedAst = normalizer.visit(ast);
|
|
33
35
|
```
|
|
34
36
|
|
|
37
|
+
The grammar declares the `caseInsensitive` option and the generated lexer honors it, so MAQL keywords may be
|
|
38
|
+
written in any letter case with a plain `CharStream`. The exported `CaseInsensitiveCharStream` is kept for
|
|
39
|
+
backward compatibility and can still be used in place of `CharStream.fromString`.
|
|
40
|
+
|
|
35
41
|
## Local development
|
|
36
42
|
|
|
37
43
|
> Requirements: [`pnpm`](https://pnpm.io)
|
|
38
44
|
|
|
39
|
-
| command
|
|
40
|
-
|
|
|
41
|
-
| `pnpm install`
|
|
42
|
-
| `pnpm build`
|
|
43
|
-
| `pnpm
|
|
44
|
-
| `pnpm
|
|
45
|
-
| `pnpm
|
|
46
|
-
| `pnpm
|
|
47
|
-
| `pnpm
|
|
48
|
-
| `pnpm
|
|
49
|
-
| `pnpm
|
|
45
|
+
| command | effect |
|
|
46
|
+
| ------------------ | ------------------------------------------------------------------ |
|
|
47
|
+
| `pnpm install` | install all dependencies |
|
|
48
|
+
| `pnpm build` | generate source files, type-check, and compile into `esm/` |
|
|
49
|
+
| `pnpm codegen` | generate source files from MAQL grammar and function definitions |
|
|
50
|
+
| `pnpm antlr4` | generate lexer, parser, listener and visitor from the MAQL grammar |
|
|
51
|
+
| `pnpm funcdef` | generate source files from MAQL function definitions |
|
|
52
|
+
| `pnpm build-check` | type-check all sources, including tests |
|
|
53
|
+
| `pnpm build-ts` | compile `src/` into `esm/` without type-checking |
|
|
54
|
+
| `pnpm clean` | remove the `esm/` output |
|
|
55
|
+
| `pnpm test` | run all tests in watch mode |
|
|
56
|
+
| `pnpm test-once` | run all tests once |
|
|
57
|
+
| `pnpm test-ci` | run all tests once with a junit.xml output file |
|
|
58
|
+
| `pnpm lint` | run oxlint and ESLint |
|
|
59
|
+
| `pnpm lint-fix` | automatically fix oxlint and ESLint errors |
|
|
60
|
+
| `pnpm format` | check formatting with oxfmt |
|
|
61
|
+
| `pnpm format-fix` | automatically fix formatting with oxfmt |
|
|
62
|
+
| `pnpm validate` | run `pnpm lint` and `pnpm format` |
|
|
63
|
+
|
|
64
|
+
The ANTLR grammar lives in `../maql-parser/src/main/antlr`. Generated sources go to `src/gen/` and are not
|
|
65
|
+
committed; `pnpm build` regenerates them. The generator runs on Node.js, no Java is required.
|
|
50
66
|
|
|
51
67
|
## Linking the package to other modules
|
|
52
68
|
|
|
53
|
-
First install the dependencies, then build
|
|
69
|
+
First install the dependencies, then build the module.
|
|
54
70
|
|
|
55
71
|
`pnpm install`
|
|
56
72
|
|
|
@@ -58,9 +74,8 @@ First install the dependencies, then build and bundle the module.
|
|
|
58
74
|
|
|
59
75
|
> Warning: Do not use `pnpm link` or `npm link`.
|
|
60
76
|
>
|
|
61
|
-
>
|
|
62
|
-
>
|
|
63
|
-
> because it results in every single token having index of -1.
|
|
77
|
+
> Symbolically linking this package can make the consuming application load a second copy of the `antlr4ng`
|
|
78
|
+
> runtime, which breaks `instanceof` checks between the two copies at runtime.
|
|
64
79
|
|
|
65
80
|
Use [yalc](https://github.com/wclr/yalc) to link the package to other repositories.
|
|
66
81
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CharStreamImpl } from "antlr4ng";
|
|
2
2
|
/**
|
|
3
3
|
* ANTLR4 CharStream extension that sees all characters as lowercase
|
|
4
4
|
*/
|
|
5
|
-
export declare class CaseInsensitiveCharStream extends
|
|
5
|
+
export declare class CaseInsensitiveCharStream extends CharStreamImpl {
|
|
6
6
|
constructor(s: string, sourceName?: string);
|
|
7
7
|
/**
|
|
8
8
|
* Modified lookahead method.
|
|
9
9
|
* Transform the character to lowercase before passing it to the caller.
|
|
10
10
|
* The input string is not modified.
|
|
11
11
|
*/
|
|
12
|
-
LA(
|
|
12
|
+
LA(offset: number): number;
|
|
13
13
|
}
|
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
// (C) 2022 GoodData Corporation
|
|
2
|
-
import {
|
|
2
|
+
import { CharStreamImpl } from "antlr4ng";
|
|
3
3
|
/**
|
|
4
4
|
* ANTLR4 CharStream extension that sees all characters as lowercase
|
|
5
5
|
*/
|
|
6
|
-
export class CaseInsensitiveCharStream extends
|
|
6
|
+
export class CaseInsensitiveCharStream extends CharStreamImpl {
|
|
7
7
|
constructor(s, sourceName) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (let i = 0; i < s.length; i++) {
|
|
12
|
-
// as we are within the string length the result of codePointAt will never be undefined
|
|
13
|
-
chars[i] = s.codePointAt(i);
|
|
8
|
+
super(s);
|
|
9
|
+
if (sourceName !== undefined) {
|
|
10
|
+
this.name = sourceName;
|
|
14
11
|
}
|
|
15
|
-
bufferBuilder.append(chars);
|
|
16
|
-
const buffer = bufferBuilder.build();
|
|
17
|
-
super(buffer.array(), buffer.position, buffer.remaining, sourceName ?? IntStream.UNKNOWN_SOURCE_NAME);
|
|
18
12
|
}
|
|
19
13
|
/**
|
|
20
14
|
* Modified lookahead method.
|
|
21
15
|
* Transform the character to lowercase before passing it to the caller.
|
|
22
16
|
* The input string is not modified.
|
|
23
17
|
*/
|
|
24
|
-
LA(
|
|
25
|
-
const c = super.LA(
|
|
18
|
+
LA(offset) {
|
|
19
|
+
const c = super.LA(offset);
|
|
26
20
|
if (c < 0) {
|
|
27
21
|
return c;
|
|
28
22
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { RecognitionException } from "antlr4ts/RecognitionException.js";
|
|
1
|
+
import { type ATNSimulator, BaseErrorListener, type RecognitionException, type Recognizer, type Token } from "antlr4ng";
|
|
3
2
|
import type { IPosition } from "../ast/Range.js";
|
|
4
3
|
/**
|
|
5
4
|
* ANTLR error listener that saves encountered errors
|
|
6
5
|
*/
|
|
7
|
-
export declare class SyntaxErrorListener
|
|
6
|
+
export declare class SyntaxErrorListener extends BaseErrorListener {
|
|
8
7
|
readonly antlrErrors: IAntlrError[];
|
|
9
|
-
syntaxError(_recognizer: Recognizer<
|
|
8
|
+
syntaxError<S extends Token, T extends ATNSimulator>(_recognizer: Recognizer<T>, offendingToken: S | null, line: number, startCharacter: number, msg: string, error: RecognitionException | null): void;
|
|
10
9
|
}
|
|
11
10
|
export interface IAntlrError {
|
|
12
11
|
position: IPosition;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
// (C) 2022 GoodData Corporation
|
|
2
|
+
import { BaseErrorListener, } from "antlr4ng";
|
|
2
3
|
/**
|
|
3
4
|
* ANTLR error listener that saves encountered errors
|
|
4
5
|
*/
|
|
5
|
-
export class SyntaxErrorListener {
|
|
6
|
+
export class SyntaxErrorListener extends BaseErrorListener {
|
|
6
7
|
antlrErrors = [];
|
|
7
|
-
syntaxError(
|
|
8
|
-
// oxlint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
_recognizer, offendingToken, line, startCharacter, msg, error) {
|
|
8
|
+
syntaxError(_recognizer, offendingToken, line, startCharacter, msg, error) {
|
|
10
9
|
this.antlrErrors.push({
|
|
11
10
|
position: { line: line - 1, character: startCharacter },
|
|
12
11
|
message: msg,
|
|
13
|
-
offendingToken,
|
|
14
|
-
error,
|
|
12
|
+
offendingToken: offendingToken ?? undefined,
|
|
13
|
+
error: error ?? undefined,
|
|
15
14
|
});
|
|
16
15
|
}
|
|
17
16
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { Lexer } from "antlr4ts/Lexer.js";
|
|
4
|
-
import { Vocabulary } from "antlr4ts/Vocabulary.js";
|
|
5
|
-
export declare class MaqlLexer extends Lexer {
|
|
1
|
+
import * as antlr from "antlr4ng";
|
|
2
|
+
export declare class MaqlLexer extends antlr.Lexer {
|
|
6
3
|
static readonly ALL = 1;
|
|
7
4
|
static readonly AND = 2;
|
|
8
5
|
static readonly ASC = 3;
|
|
@@ -150,23 +147,22 @@ export declare class MaqlLexer extends Lexer {
|
|
|
150
147
|
static readonly OBJECT_TYPE = 1;
|
|
151
148
|
static readonly OBJECT_ID = 2;
|
|
152
149
|
static readonly channelNames: string[];
|
|
150
|
+
static readonly literalNames: (string | null)[];
|
|
151
|
+
static readonly symbolicNames: (string | null)[];
|
|
153
152
|
static readonly modeNames: string[];
|
|
154
153
|
static readonly ruleNames: string[];
|
|
155
|
-
|
|
156
|
-
private static readonly _SYMBOLIC_NAMES;
|
|
157
|
-
static readonly VOCABULARY: Vocabulary;
|
|
158
|
-
get vocabulary(): Vocabulary;
|
|
159
|
-
constructor(input: CharStream);
|
|
154
|
+
constructor(input: antlr.CharStream);
|
|
160
155
|
get grammarFileName(): string;
|
|
156
|
+
get literalNames(): (string | null)[];
|
|
157
|
+
get symbolicNames(): (string | null)[];
|
|
161
158
|
get ruleNames(): string[];
|
|
162
|
-
get serializedATN():
|
|
159
|
+
get serializedATN(): number[];
|
|
163
160
|
get channelNames(): string[];
|
|
164
161
|
get modeNames(): string[];
|
|
165
|
-
|
|
166
|
-
private static
|
|
167
|
-
|
|
168
|
-
private static readonly
|
|
169
|
-
|
|
170
|
-
static
|
|
171
|
-
static get _ATN(): ATN;
|
|
162
|
+
static readonly _serializedATN: number[];
|
|
163
|
+
private static __ATN;
|
|
164
|
+
static get _ATN(): antlr.ATN;
|
|
165
|
+
private static readonly vocabulary;
|
|
166
|
+
get vocabulary(): antlr.Vocabulary;
|
|
167
|
+
private static readonly decisionsToDFA;
|
|
172
168
|
}
|