@apexdevtools/apex-parser 4.4.0 → 5.0.0-beta.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/README.md +98 -42
  3. package/lib/ApexErrorListener.d.ts +25 -0
  4. package/lib/ApexErrorListener.js +64 -0
  5. package/lib/ApexErrorListener.js.map +1 -0
  6. package/lib/ApexParserFactory.d.ts +69 -0
  7. package/lib/ApexParserFactory.js +125 -0
  8. package/lib/ApexParserFactory.js.map +1 -0
  9. package/lib/CaseInsensitiveInputStream.d.ts +11 -13
  10. package/lib/CaseInsensitiveInputStream.js +22 -28
  11. package/lib/CaseInsensitiveInputStream.js.map +1 -1
  12. package/lib/Check.d.ts +36 -0
  13. package/lib/Check.js +212 -0
  14. package/lib/Check.js.map +1 -0
  15. package/lib/{ApexLexer.d.ts → antlr/ApexLexer.d.ts} +11 -18
  16. package/lib/antlr/ApexLexer.js +1575 -0
  17. package/lib/antlr/ApexLexer.js.map +1 -0
  18. package/lib/{ApexParser.d.ts → antlr/ApexParser.d.ts} +1344 -1304
  19. package/lib/antlr/ApexParser.js +20976 -0
  20. package/lib/antlr/ApexParser.js.map +1 -0
  21. package/lib/{ApexParserListener.d.ts → antlr/ApexParserListener.d.ts} +708 -686
  22. package/lib/antlr/ApexParserListener.js +12 -0
  23. package/lib/antlr/ApexParserListener.js.map +1 -0
  24. package/lib/{ApexParserVisitor.d.ts → antlr/ApexParserVisitor.d.ts} +420 -406
  25. package/lib/antlr/ApexParserVisitor.js +15 -0
  26. package/lib/antlr/ApexParserVisitor.js.map +1 -0
  27. package/lib/index.d.ts +8 -24
  28. package/lib/index.js +13 -140
  29. package/lib/index.js.map +1 -1
  30. package/package.json +30 -27
  31. package/lib/ApexLexer.js +0 -1704
  32. package/lib/ApexLexer.js.map +0 -1
  33. package/lib/ApexParser.js +0 -19514
  34. package/lib/ApexParser.js.map +0 -1
  35. package/lib/ApexParserListener.js +0 -4
  36. package/lib/ApexParserListener.js.map +0 -1
  37. package/lib/ApexParserVisitor.js +0 -4
  38. package/lib/ApexParserVisitor.js.map +0 -1
  39. package/lib/ThrowingErrorListener.d.ts +0 -10
  40. package/lib/ThrowingErrorListener.js +0 -18
  41. package/lib/ThrowingErrorListener.js.map +0 -1
  42. package/lib/__tests__/ApexLexerTest.d.ts +0 -1
  43. package/lib/__tests__/ApexLexerTest.js +0 -48
  44. package/lib/__tests__/ApexLexerTest.js.map +0 -1
  45. package/lib/__tests__/ApexListenerTest.d.ts +0 -1
  46. package/lib/__tests__/ApexListenerTest.js +0 -41
  47. package/lib/__tests__/ApexListenerTest.js.map +0 -1
  48. package/lib/__tests__/ApexParserTest.d.ts +0 -1
  49. package/lib/__tests__/ApexParserTest.js +0 -199
  50. package/lib/__tests__/ApexParserTest.js.map +0 -1
  51. package/lib/__tests__/ApexTriggerTest.d.ts +0 -1
  52. package/lib/__tests__/ApexTriggerTest.js +0 -66
  53. package/lib/__tests__/ApexTriggerTest.js.map +0 -1
  54. package/lib/__tests__/ApexVisitorTest.d.ts +0 -1
  55. package/lib/__tests__/ApexVisitorTest.js +0 -46
  56. package/lib/__tests__/ApexVisitorTest.js.map +0 -1
  57. package/lib/__tests__/SOQLParserTest.d.ts +0 -1
  58. package/lib/__tests__/SOQLParserTest.js +0 -121
  59. package/lib/__tests__/SOQLParserTest.js.map +0 -1
  60. package/lib/__tests__/SOSLParserTest.d.ts +0 -1
  61. package/lib/__tests__/SOSLParserTest.js +0 -101
  62. package/lib/__tests__/SOSLParserTest.js.map +0 -1
  63. package/lib/__tests__/SyntaxErrorCounter.d.ts +0 -10
  64. package/lib/__tests__/SyntaxErrorCounter.js +0 -52
  65. package/lib/__tests__/SyntaxErrorCounter.js.map +0 -1
  66. package/lib/__tests__/system/SampleParseSys.d.ts +0 -1
  67. package/lib/__tests__/system/SampleParseSys.js +0 -75
  68. package/lib/__tests__/system/SampleParseSys.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,110 @@
1
+ # apex-parser - Changelog
2
+
3
+ ## 5.0.0
4
+
5
+ ## General
6
+
7
+ - **(BREAKING)** Updated to ANTLR runtime `4.13.2`, using the ANTLR tool to generate both target languages.
8
+
9
+ - Enabled `caseInsensitive` option for lexers (added in ANTLR 4.10).
10
+ - As a result, `CaseInsensitiveInputStream` is deprecated and should no longer be required.
11
+
12
+ - Added `ApexParserFactory` class to create parsers, token streams, and lexers.
13
+ - Primarily for TS to avoid directly creating `antlr4` class instances.
14
+ - In Java, it still requires passing a `CharStream` or `CommonTokenStream` to create parsers.
15
+
16
+ - Added abstract class `ApexErrorListener`:
17
+ - Implement method `apexSyntaxError(line, column, message)` to avoid antlr specific types.
18
+
19
+ - Added support for parsing Anonymous Apex via `anonymousUnit` (.apex files) and `anonymousBlock` parser rules.
20
+
21
+ ### Java
22
+
23
+ - Added `Check.run` to programmatically run syntax check operation on a path.
24
+
25
+ ### TypeScript/NPM
26
+
27
+ - **(BREAKING)** Migrated from `antlr4ts` to official `antlr4` runtime package.
28
+ - Some lesser used methods are missing in the type definitions, refer to the [antlr4 Javascript code](https://github.com/antlr/antlr4/tree/dev/runtime/JavaScript/src/antlr4) if you need to cast types.
29
+ - Generated `Listener`/`Visitor` interfaces are now abstract classes.
30
+ - Introduced `Base` classes to extend instead, following pattern of Java classes of the same name. Change:
31
+ - `implements ApexParserListener` to `extends ApexParserBaseListener`
32
+ - `implements ApexParserVisitor<T>` to `extends ApexParserBaseVisitor<T>`
33
+ - Parser rule contexts now have `_list()` methods for multi rules.
34
+ - A rule `expr*` generates `expr_list()` and `expr(number)`.
35
+ - By contrast Java would have overloads of `expr()`/`expr(int)` returning list or value.
36
+
37
+ - **(BREAKING)** Re-exported antlr classes `CommonTokenStream` and `ParseTreeWalker` removed.
38
+ - Added type aliases like `ApexTokenStream`, `ApexParseTree`, and more to use with listener/visitor/walker.
39
+ - For the walker, use `ApexParseTreeWalker.DEFAULT`. Same instance but typed for `ApexParserListener` and `ApexParseTree`.
40
+ - It should no longer be required to depend on `antlr4` package directly.
41
+ - Can still add the package as a dependency, but remember to match the version `apex-parser` uses.
42
+
43
+ - **(BREAKING)** Updated output to `ES2020` and increased min node version to 16.
44
+
45
+ - `CaseInsensitiveInputStream` (deprecated) type now extends `CharStream` and can be constructed from `string`.
46
+ - Constructor passing in `CharStream` retained to match Java version.
47
+
48
+ - Removed `node-dir` dependency - replaced with node fs api.
49
+
50
+ ## 4.4.0 - 2024-12-14
51
+
52
+ - Support `TimeLiteral` for `Time` fields, e.g. `WHERE TimeField__c = 01:00:00.000Z` for SOQL queries
53
+
54
+ ## 4.3.1 - 2024-11-12
55
+
56
+ - Fix Lexer support for uppercase Hex
57
+ - Fix parser `whenValue` to support type refs
58
+
59
+ ## 4.3.0 - 2024-09-26
60
+
61
+ - Add `convertCurrency` and `FORMAT` SOQL/SOSL functions
62
+ - Support nested functions in `FORMAT`
63
+ - Support aliases on SOSL functions
64
+
65
+ ## 4.2.0 - 2024-09-02
66
+
67
+ - Add support for multiple nested SOQL sub queries
68
+ - Add support for `GROUPING` in SOQL query
69
+ - Add support for `toLabel` in SOSL query
70
+
71
+ ## 4.1.0 - 2024-05-12
72
+
73
+ - Allow WITH USER_MODE or SYSTEM_MODE on SOSL queries
74
+
75
+ ## 4.0.0 - 2024-03-28
76
+
77
+ - Correct trigger body parsing to allow member declarations
78
+ - Add support for TYPEOF in SOQL subqueries
79
+ - Change com.nawforce.apexparser packages to io.github.apexdevtools.apexparser
80
+
81
+ ## 3.6.0 - 2024-02-15
82
+
83
+ - Add null coalesce operator and expression
84
+
85
+ ## 3.5.0 - 2023-10-15
86
+
87
+ - Correct do-while to require block rather than statement
88
+
89
+ ## 3.4.0 - 2023-08-22
90
+
91
+ - Support +/- sequences on numeric literals in switch 'when' expressions
92
+
93
+ ## 3.3.0 - 2023-04-30
94
+
95
+ - Update to ANTLR 4.9.1
96
+
97
+ ## 3.2.0 - 2023-01-24
98
+
99
+ - Adds user/system mode on DML and within SOQL queries
100
+
101
+ ## 3.1.0 - 2022-11-17
102
+
103
+ - Adds DISTANCE and GEOLOCATION literals for SOQL.
104
+ - Removes support for modulus operator to match apex.
105
+ - Use of `void.class` no longer causes syntax error.
106
+ - Now supports newer Date literals from API 55.
107
+
108
+ ## 3.0.0 - 2022-06-14
109
+
110
+ - Initial github release.
package/README.md CHANGED
@@ -1,79 +1,135 @@
1
1
  # apex-parser
2
2
 
3
- Parser for Salesforce Apex (including Triggers & inline SOQL/SOQL). This is based on an [ANTLR4](https://www.antlr.org/) grammar, see antlr/ApexParser.g4.
3
+ Parser for Salesforce Apex (including Triggers & inline SOQL/SOQL). This is based on an [ANTLR4](https://www.antlr.org/) grammar, see [`antlr/BaseApexParser.g4`](./antlr/BaseApexParser.g4). Currently packaged for Java and JavaScript/TypeScript targets.
4
4
 
5
- There are two builds of the parser available, a NPM module for use with Node and a Maven package for use on JVMs.
5
+ The packages include ANTLR4 generated types plus optional extras for convenience. The TypeScript package exports type aliases for ANTLR types, while both packages have abstractions like `ApexParserFactory` and `ApexErrorListener`. There are minimal examples below and in the test classes.
6
6
 
7
- These builds just contain the Parser & Lexer and provides no further support for analysing the generated parse trees beyond what is provided by ANTLR4.
7
+ ## Installation
8
8
 
9
- As Apex & SOQL/SOQL are case-insenstive languages you need to use the provided CaseInsensitiveInputStream for the parser to function correctly. When parsing Apex, inline SOQL/SOSL is automtaically parsed, but you can also parse SOQL/SOQL directly. You can find some minimal examples in the test classes.
9
+ ### Maven
10
10
 
11
- ## Example
11
+ ```xml
12
+ <dependency>
13
+ <groupId>io.github.apex-dev-tools</groupId>
14
+ <artifactId>apex-parser</artifactId>
15
+ <version><!-- version --></version>
16
+ </dependency>
17
+ ```
12
18
 
13
- To parse a class file (NPM version):
19
+ ### NPM
14
20
 
15
- let lexer = new ApexLexer(new CaseInsensitiveInputStream("public class Hello {}"))
16
- let tokens = new CommonTokenStream(lexer);
21
+ ```sh
22
+ # Optionally install `antlr4` to use runtime types
23
+ npm i @apexdevtools/apex-parser
24
+ ```
17
25
 
18
- let parser = new ApexParser(tokens)
19
- let context = parser.compilationUnit()
26
+ ## Usage
20
27
 
21
- The 'context' is a CompilationUnitContext object which is the root of the parsed representation of the class. You can access the parse tree via functions on it.
28
+ `ApexParser` entry points to access tree:
22
29
 
23
- ## Unicode handling
30
+ - `compilationUnit()`, a class file.
31
+ - `triggerUnit()`, a trigger file.
32
+ - `anonymousUnit()`, an apex script file.
33
+ - `query()`, a raw SOQL query.
24
34
 
25
- Prior to 2.12.0 the use of ANTLRInputStream for reading data in CaseInsensitiveStream would result character positions being given for UTF-16. The switch to CharStream input in 2.12.0 for JVM and 2.14.0 for node results in character positions reflecting Unicode code points.
35
+ ### Explore Parse Tree (TypeScript)
26
36
 
27
- ## antlr4ts versions
37
+ ```typescript
38
+ import { ApexParserFactory, ApexParserBaseVisitor } from "@apexdevtools/apex-parser";
28
39
 
29
- The npm module uses antlr4ts 0.5.0-alpha.4, this was updated from 0.5.0-alpha.3 in the 2.9.1 version. You should make
30
- sure that if you are using a matching versions of this dependency if you use it directly. To avoid issues you can
31
- import 'CommonTokenStream' & 'ParseTreeWalker' from 'apex-parser' instead of from antlr4ts.
40
+ const parser = ApexParserFactory.createParser("public class Hello {}");
32
41
 
33
- import { CommonTokenStream} from "apex-parser";
34
- import { ParseTreeWalker } from "apex-parser";
42
+ /*
43
+ * Use a visitor. Return value and manual control.
44
+ */
45
+ class Visitor extends ApexParserBaseVisitor<any> {}
35
46
 
36
- ## SOSL FIND quoting
47
+ const visitor = new Visitor();
48
+ visitor.visit(parser.compilationUnit());
49
+
50
+
51
+ /*
52
+ * Or walk with listener. Enter/exit operations - for whole tree.
53
+ */
54
+ class Listener extends ApexParserBaseListener {}
55
+
56
+ const listener = new Listener();
57
+ ApexParseTreeWalker.DEFAULT.walk(listener, parser.compilationUnit());
58
+ ```
59
+
60
+ ### SOSL FIND quoting
37
61
 
38
62
  SOSL FIND uses ' as a quoting character when embedded in Apex, in the API braces are used:
39
63
 
40
- Find {something} RETURNING Account
64
+ ```sosl
65
+ Find {something} RETURNING Account
66
+ ```
67
+
68
+ To parse the API format there is an alternative parser rule, `soslLiteralAlt`, that you can use instead of `soslLiteral`. See `SOSLParserTest` for some examples of how these differ.
69
+
70
+ ## Development
71
+
72
+ ### Prerequisites
73
+
74
+ - JDK 11+ (for ANTLR tool)
75
+ - Maven
76
+ - NodeJS LTS
77
+
78
+ ### Building
79
+
80
+ The outer package contains scripts to build both distributions:
81
+
82
+ ```shell
83
+ # Run once - prepare for dev (installs deps, runs antlr gen)
84
+ npm run init
41
85
 
42
- To parse the API format there is an alternative parser rule, soslLiteralAlt, that you can use instead of soslLiteral. See SOSLParserTest for some examples of how these differ.
86
+ # Run antlr gen, compile and test
87
+ npm run build
88
+ ```
43
89
 
44
- ## Packages
90
+ Or you can setup and later build each distribution separately:
45
91
 
46
- Maven
92
+ ```shell
93
+ npm run init:npm
94
+ npm run build:npm
47
95
 
48
- <dependency>
49
- <groupId>io.github.apex-dev-tools</groupId>
50
- <artifactId>apex-parser</artifactId>
51
- <version>4.4.0</version>
52
- </dependency>
96
+ npm run init:jvm
97
+ npm run build:jvm
98
+ ```
53
99
 
54
- NPM
100
+ ### Testing
55
101
 
56
- "@apexdevtools/apex-parser": "^4.4.0"
102
+ #### Unit Tests
57
103
 
58
- ## Building
104
+ More options for testing:
59
105
 
60
- To build both distributions:
106
+ ```shell
107
+ # From ./npm
108
+ npm run build
109
+ npm test
110
+ # File and test name regex filtering
111
+ npm test -- ApexParserTest -t Expression
61
112
 
62
- npm run build
113
+ # From ./jvm
114
+ mvn test
115
+ ```
63
116
 
64
- ## Testing
117
+ #### System Tests
65
118
 
66
- Unit tests are executed during the respective package builds. The system tests require both packages to be built, as the js test also spawns the jar version. They use a collection of sample projects located in the [apex-samples](https://github.com/apex-dev-tools/apex-samples) repository. Follow the README instructions in apex-samples to checkout the submodules. To run the tests:
119
+ The system tests use a collection of sample projects located in the [`apex-samples`](https://github.com/apex-dev-tools/apex-samples) repository. Follow the README instructions in `apex-samples` to checkout the submodules at the version tag used by the [build workflow](.github/workflows/Build.yml). Both packages must be built beforehand, as the js system test spawns the jar as well.
67
120
 
68
- # Set SAMPLES env var to samples repo location
69
- export SAMPLES=<abs path to apex-samples>
121
+ To run the tests:
70
122
 
71
- # Exec test script
72
- npm run test-samples
123
+ ```shell
124
+ # Set SAMPLES env var to samples repo location
125
+ export SAMPLES=<abs path to apex-samples>
73
126
 
74
- System test failures relating to the snapshots may highlight regressions. Though if an error is expected or the samples have changed, instead use `npm run test-snapshot` to update the snapshots, then commit the changes.
127
+ # From root dir
128
+ npm run build
129
+ npm run systest
130
+ ```
75
131
 
76
- The tag version of apex-samples used by builds is set in the [build file](.github/workflows/Build.yml).
132
+ System test failures relating to the snapshots may highlight regressions. Though if an error is expected or the samples have changed, instead use `npm run systest:update` to update the snapshots, then commit the changes.
77
133
 
78
134
  ## Source & Licenses
79
135
 
@@ -0,0 +1,25 @@
1
+ import { ErrorListener, RecognitionException, Recognizer, Token } from "antlr4";
2
+ /**
3
+ * Base `ErrorListener` for Apex parsers.
4
+ *
5
+ * Implement `apexSyntaxError()` to set behaviour.
6
+ */
7
+ export declare abstract class ApexErrorListener extends ErrorListener<Token> {
8
+ abstract apexSyntaxError(line: number, column: number, msg: string): void;
9
+ syntaxError(recognizer: Recognizer<Token>, offendingSymbol: Token, line: number, column: number, msg: string, e: RecognitionException | undefined): void;
10
+ }
11
+ export declare class ApexSyntaxError extends Error {
12
+ line: number;
13
+ column: number;
14
+ message: string;
15
+ constructor(line: number, column: number, message: string);
16
+ }
17
+ /**
18
+ * `ApexErrorListener` that throws an `ApexSyntaxError` on first reported error.
19
+ *
20
+ * Use ThrowingErrorListener.INSTANCE to share across parsers.
21
+ */
22
+ export declare class ThrowingErrorListener extends ApexErrorListener {
23
+ static readonly INSTANCE: ThrowingErrorListener;
24
+ apexSyntaxError(line: number, column: number, msg: string): void;
25
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThrowingErrorListener = exports.ApexSyntaxError = exports.ApexErrorListener = void 0;
4
+ /*
5
+ [The "BSD licence"]
6
+ Copyright (c) 2025 Kevin Jones, Certinia Inc.
7
+ All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions
11
+ are met:
12
+ 1. Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+ 2. Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+ 3. The name of the author may not be used to endorse or promote products
18
+ derived from this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ */
31
+ const antlr4_1 = require("antlr4");
32
+ /**
33
+ * Base `ErrorListener` for Apex parsers.
34
+ *
35
+ * Implement `apexSyntaxError()` to set behaviour.
36
+ */
37
+ class ApexErrorListener extends antlr4_1.ErrorListener {
38
+ syntaxError(recognizer, offendingSymbol, line, column, msg, e) {
39
+ this.apexSyntaxError(line, column, msg);
40
+ }
41
+ }
42
+ exports.ApexErrorListener = ApexErrorListener;
43
+ class ApexSyntaxError extends Error {
44
+ constructor(line, column, message) {
45
+ super(message);
46
+ this.line = line;
47
+ this.column = column;
48
+ this.name = this.constructor.name;
49
+ }
50
+ }
51
+ exports.ApexSyntaxError = ApexSyntaxError;
52
+ /**
53
+ * `ApexErrorListener` that throws an `ApexSyntaxError` on first reported error.
54
+ *
55
+ * Use ThrowingErrorListener.INSTANCE to share across parsers.
56
+ */
57
+ class ThrowingErrorListener extends ApexErrorListener {
58
+ apexSyntaxError(line, column, msg) {
59
+ throw new ApexSyntaxError(line, column, msg);
60
+ }
61
+ }
62
+ exports.ThrowingErrorListener = ThrowingErrorListener;
63
+ ThrowingErrorListener.INSTANCE = new ThrowingErrorListener();
64
+ //# sourceMappingURL=ApexErrorListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApexErrorListener.js","sourceRoot":"","sources":["../src/ApexErrorListener.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BE;AACF,mCAAgF;AAEhF;;;;GAIG;AACH,MAAsB,iBAAkB,SAAQ,sBAAoB;IAGlE,WAAW,CACT,UAA6B,EAC7B,eAAsB,EACtB,IAAY,EACZ,MAAc,EACd,GAAW,EACX,CAAmC;QAEnC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1C,CAAC;CACF;AAbD,8CAaC;AAED,MAAa,eAAgB,SAAQ,KAAK;IAKxC,YAAY,IAAY,EAAE,MAAc,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAZD,0CAYC;AAED;;;;GAIG;AACH,MAAa,qBAAsB,SAAQ,iBAAiB;IAG1D,eAAe,CAAC,IAAY,EAAE,MAAc,EAAE,GAAW;QACvD,MAAM,IAAI,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC;;AALH,sDAMC;AALiB,8BAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { CommonTokenStream, ErrorNode, ParserRuleContext, ParseTree, ParseTreeListener, ParseTreeVisitor, ParseTreeWalker, RuleNode, TerminalNode, Token } from "antlr4";
2
+ import ApexParserListener from "./antlr/ApexParserListener";
3
+ import ApexParserVisitor from "./antlr/ApexParserVisitor";
4
+ import ApexLexer from "./antlr/ApexLexer";
5
+ import ApexParser from "./antlr/ApexParser";
6
+ export type ApexParserRuleContext = ParserRuleContext;
7
+ export type ApexErrorNode = ErrorNode;
8
+ export type ApexParseTree = ParseTree;
9
+ export type ApexRuleNode = RuleNode;
10
+ export type ApexTerminalNode = TerminalNode;
11
+ export type ApexTokenStream = CommonTokenStream;
12
+ export type ApexToken = Token;
13
+ /**
14
+ * A factory for `ApexParser` and its components. Abstracts interaction
15
+ * with core ANTLR types like `CommonTokenStream`.
16
+ */
17
+ export declare class ApexParserFactory {
18
+ private constructor();
19
+ static createParser(source: string | ApexTokenStream, throwOnFirstError?: boolean): ApexParser;
20
+ static createTokenStream(source: string | ApexLexer): ApexTokenStream;
21
+ static createLexer(source: string): ApexLexer;
22
+ }
23
+ /**
24
+ * A base visitor for an Apex parse tree produced by `ApexParser`. Extend this
25
+ * class to define a subset of visitor operations.
26
+ *
27
+ * @see ApexParserVisitor for tree context visit operations.
28
+ * @param Result The return type of the visit operation. Use `void` for
29
+ * operations with no return type.
30
+ * @example
31
+ * // Implementations can be property or method styles.
32
+ * visitCompilationUnit = (ctx: CompilationUnitContext) => { return result; }
33
+ * visitCompilationUnit(ctx: CompilationUnitContext) { return result; }
34
+ */
35
+ export declare class ApexParserBaseVisitor<Result> extends ParseTreeVisitor<Result> implements ApexParserVisitor<Result> {
36
+ visit(tree: ApexParseTree): Result;
37
+ visitChildren(node: ApexRuleNode): Result;
38
+ visitTerminal(node: ApexTerminalNode): Result;
39
+ visitErrorNode(node: ApexErrorNode): Result;
40
+ }
41
+ /**
42
+ * A base listener for an Apex parse tree produced by `ApexParser`. Extend this
43
+ * class to define a subset of listener operations.
44
+ *
45
+ * @see ApexParserListener for tree context listen operations.
46
+ * @example
47
+ * // Implementations can be property or method styles.
48
+ * enterCompilationUnit = (ctx: CompilationUnitContext) => {}
49
+ * enterCompilationUnit(ctx: CompilationUnitContext) {}
50
+ */
51
+ export declare class ApexParserBaseListener extends ParseTreeListener implements ApexParserListener {
52
+ visitTerminal(node: ApexTerminalNode): void;
53
+ visitErrorNode(node: ApexErrorNode): void;
54
+ enterEveryRule(ctx: ApexParserRuleContext): void;
55
+ exitEveryRule(ctx: ApexParserRuleContext): void;
56
+ }
57
+ /**
58
+ * Walker for a parse tree starting at the root and going down recursively
59
+ * with depth-first search.
60
+ *
61
+ * @example
62
+ * const parser = ApexParserFactory.createParser("public class Foo {}");
63
+ * const listener = new MyListener(); // extends ApexParseTreeListener
64
+ * ApexParseTreeWalker.DEFAULT.walk(listener, parser.compilationUnit());
65
+ */
66
+ export declare class ApexParseTreeWalker extends ParseTreeWalker {
67
+ static DEFAULT: ApexParseTreeWalker;
68
+ walk<T extends ApexParserListener>(listener: T, t: ApexParseTree): void;
69
+ }
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ /*
3
+ [The "BSD licence"]
4
+ Copyright (c) 2025 Kevin Jones, Certinia Inc.
5
+ All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions
9
+ are met:
10
+ 1. Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
+ 2. Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+ 3. The name of the author may not be used to endorse or promote products
16
+ derived from this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+ var _a, _b;
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.ApexParseTreeWalker = exports.ApexParserBaseListener = exports.ApexParserBaseVisitor = exports.ApexParserFactory = void 0;
32
+ const antlr4_1 = require("antlr4");
33
+ const ApexLexer_1 = require("./antlr/ApexLexer");
34
+ const ApexParser_1 = require("./antlr/ApexParser");
35
+ const ApexErrorListener_1 = require("./ApexErrorListener");
36
+ /**
37
+ * A factory for `ApexParser` and its components. Abstracts interaction
38
+ * with core ANTLR types like `CommonTokenStream`.
39
+ */
40
+ class ApexParserFactory {
41
+ constructor() { }
42
+ static createParser(source, throwOnFirstError = false) {
43
+ const parser = new ApexParser_1.default(typeof source === "string"
44
+ ? new antlr4_1.CommonTokenStream(this.createLexer(source))
45
+ : source);
46
+ // always remove default console listener
47
+ parser.removeErrorListeners();
48
+ if (throwOnFirstError) {
49
+ parser.addErrorListener(ApexErrorListener_1.ThrowingErrorListener.INSTANCE);
50
+ }
51
+ return parser;
52
+ }
53
+ static createTokenStream(source) {
54
+ return new antlr4_1.CommonTokenStream(typeof source === "string" ? this.createLexer(source) : source);
55
+ }
56
+ static createLexer(source) {
57
+ const lexer = new ApexLexer_1.default(antlr4_1.CharStreams.fromString(source));
58
+ // always remove default console listener
59
+ lexer.removeErrorListeners();
60
+ return lexer;
61
+ }
62
+ }
63
+ exports.ApexParserFactory = ApexParserFactory;
64
+ /**
65
+ * A base visitor for an Apex parse tree produced by `ApexParser`. Extend this
66
+ * class to define a subset of visitor operations.
67
+ *
68
+ * @see ApexParserVisitor for tree context visit operations.
69
+ * @param Result The return type of the visit operation. Use `void` for
70
+ * operations with no return type.
71
+ * @example
72
+ * // Implementations can be property or method styles.
73
+ * visitCompilationUnit = (ctx: CompilationUnitContext) => { return result; }
74
+ * visitCompilationUnit(ctx: CompilationUnitContext) { return result; }
75
+ */
76
+ class ApexParserBaseVisitor extends antlr4_1.ParseTreeVisitor {
77
+ visit(tree) {
78
+ return super.visit(tree);
79
+ }
80
+ visitChildren(node) {
81
+ return super.visitChildren(node);
82
+ }
83
+ visitTerminal(node) {
84
+ return super.visitTerminal(node);
85
+ }
86
+ visitErrorNode(node) {
87
+ return super.visitErrorNode(node);
88
+ }
89
+ }
90
+ exports.ApexParserBaseVisitor = ApexParserBaseVisitor;
91
+ /**
92
+ * A base listener for an Apex parse tree produced by `ApexParser`. Extend this
93
+ * class to define a subset of listener operations.
94
+ *
95
+ * @see ApexParserListener for tree context listen operations.
96
+ * @example
97
+ * // Implementations can be property or method styles.
98
+ * enterCompilationUnit = (ctx: CompilationUnitContext) => {}
99
+ * enterCompilationUnit(ctx: CompilationUnitContext) {}
100
+ */
101
+ class ApexParserBaseListener extends antlr4_1.ParseTreeListener {
102
+ visitTerminal(node) { }
103
+ visitErrorNode(node) { }
104
+ enterEveryRule(ctx) { }
105
+ exitEveryRule(ctx) { }
106
+ }
107
+ exports.ApexParserBaseListener = ApexParserBaseListener;
108
+ /**
109
+ * Walker for a parse tree starting at the root and going down recursively
110
+ * with depth-first search.
111
+ *
112
+ * @example
113
+ * const parser = ApexParserFactory.createParser("public class Foo {}");
114
+ * const listener = new MyListener(); // extends ApexParseTreeListener
115
+ * ApexParseTreeWalker.DEFAULT.walk(listener, parser.compilationUnit());
116
+ */
117
+ class ApexParseTreeWalker extends (_b = antlr4_1.ParseTreeWalker) {
118
+ walk(listener, t) {
119
+ super.walk(listener, t);
120
+ }
121
+ }
122
+ exports.ApexParseTreeWalker = ApexParseTreeWalker;
123
+ _a = ApexParseTreeWalker;
124
+ ApexParseTreeWalker.DEFAULT = Reflect.get(_b, "DEFAULT", _a);
125
+ //# sourceMappingURL=ApexParserFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApexParserFactory.js","sourceRoot":"","sources":["../src/ApexParserFactory.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BE;;;;AAEF,mCAYgB;AAGhB,iDAA0C;AAC1C,mDAA4C;AAC5C,2DAA4D;AAU5D;;;GAGG;AACH,MAAa,iBAAiB;IAC5B,gBAAuB,CAAC;IAExB,MAAM,CAAC,YAAY,CACjB,MAAgC,EAChC,oBAA6B,KAAK;QAElC,MAAM,MAAM,GAAG,IAAI,oBAAU,CAC3B,OAAO,MAAM,KAAK,QAAQ;YACxB,CAAC,CAAC,IAAI,0BAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACjD,CAAC,CAAC,MAAM,CACX,CAAC;QAEF,yCAAyC;QACzC,MAAM,CAAC,oBAAoB,EAAE,CAAC;QAC9B,IAAI,iBAAiB,EAAE;YACrB,MAAM,CAAC,gBAAgB,CAAC,yCAAqB,CAAC,QAAQ,CAAC,CAAC;SACzD;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,MAA0B;QACjD,OAAO,IAAI,0BAAiB,CAC1B,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAC/D,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,MAAc;QAC/B,MAAM,KAAK,GAAG,IAAI,mBAAS,CAAC,oBAAW,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QAE5D,yCAAyC;QACzC,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlCD,8CAkCC;AAED;;;;;;;;;;;GAWG;AACH,MAAa,qBACX,SAAQ,yBAAwB;IAGhC,KAAK,CAAC,IAAmB;QACvB,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,aAAa,CAAC,IAAkB;QAC9B,OAAO,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,aAAa,CAAC,IAAsB;QAClC,OAAO,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,cAAc,CAAC,IAAmB;QAChC,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACF;AAnBD,sDAmBC;AAED;;;;;;;;;GASG;AACH,MAAa,sBACX,SAAQ,0BAAiB;IAGzB,aAAa,CAAC,IAAsB,IAAS,CAAC;IAC9C,cAAc,CAAC,IAAmB,IAAS,CAAC;IAC5C,cAAc,CAAC,GAA0B,IAAS,CAAC;IACnD,aAAa,CAAC,GAA0B,IAAS,CAAC;CACnD;AARD,wDAQC;AAED;;;;;;;;GAQG;AACH,MAAa,mBAAoB,SAAQ,MAAA,wBAAe,CAAA;IAGtD,IAAI,CAA+B,QAAW,EAAE,CAAgB;QAC9D,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC1B,CAAC;;AALH,kDAMC;;AALQ,2BAAO,GAAG,8BAAoC,CAAC"}
@@ -1,16 +1,14 @@
1
- import { CharStream } from "antlr4ts";
2
- import { Interval } from "antlr4ts/misc/Interval";
3
- export declare class CaseInsensitiveInputStream implements CharStream {
4
- private src;
5
- constructor(src: CharStream);
6
- getText(interval: Interval): string;
7
- consume(): void;
1
+ import { CharStream } from "antlr4";
2
+ /**
3
+ * Converts char stream to lower case for case insensitive usage.
4
+ *
5
+ * @deprecated since 5.0.0. ApexLexer is generated with ANTLR 4.10
6
+ * `caseInsensitive` option enabled.
7
+ */
8
+ export declare class CaseInsensitiveInputStream extends CharStream {
9
+ constructor(data: string, decodeToUnicodeCodePoints?: boolean);
10
+ constructor(stream: CharStream, decodeToUnicodeCodePoints?: boolean);
8
11
  LA(i: number): number;
9
- mark(): number;
10
- release(marker: number): void;
11
- get index(): number;
12
- seek(index: number): void;
13
- get size(): number;
14
- get sourceName(): string;
12
+ LT(offset: number): number;
15
13
  private toLower;
16
14
  }