@apexdevtools/apex-parser 3.0.0 → 3.1.0
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/CHANGELOG.md +12 -0
- package/README.md +37 -14
- package/lib/ApexLexer.d.ts +135 -127
- package/lib/ApexLexer.js +1360 -1266
- package/lib/ApexLexer.js.map +1 -1
- package/lib/ApexParser.d.ts +264 -173
- package/lib/ApexParser.js +3496 -2521
- package/lib/ApexParser.js.map +1 -1
- package/lib/ApexParserListener.d.ts +46 -0
- package/lib/ApexParserVisitor.d.ts +29 -0
- package/lib/__tests__/ApexParserTest.js +47 -78
- package/lib/__tests__/ApexParserTest.js.map +1 -1
- package/lib/__tests__/SOQLParserTest.d.ts +1 -0
- package/lib/__tests__/SOQLParserTest.js +59 -0
- package/lib/__tests__/SOQLParserTest.js.map +1 -0
- package/lib/__tests__/SOSLParserTest.d.ts +1 -0
- package/lib/__tests__/SOSLParserTest.js +35 -0
- package/lib/__tests__/SOSLParserTest.js.map +1 -0
- package/lib/__tests__/SyntaxErrorCounter.d.ts +8 -0
- package/lib/__tests__/SyntaxErrorCounter.js +30 -0
- package/lib/__tests__/SyntaxErrorCounter.js.map +1 -0
- package/lib/__tests__/system/SampleParseSys.d.ts +1 -0
- package/lib/__tests__/system/SampleParseSys.js +72 -0
- package/lib/__tests__/system/SampleParseSys.js.map +1 -0
- package/lib/index.d.ts +25 -9
- package/lib/index.js +99 -11
- package/lib/index.js.map +1 -1
- package/package.json +7 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# apex-parser - Changelog
|
|
2
|
+
|
|
3
|
+
## 3.1.0 - 2022-11-17
|
|
4
|
+
|
|
5
|
+
* Adds DISTANCE and GEOLOCATION literals for SOQL.
|
|
6
|
+
* Removes support for modulus operator to match apex.
|
|
7
|
+
* Use of `void.class` no longer causes syntax error.
|
|
8
|
+
* Now supports newer Date literals from API 55.
|
|
9
|
+
|
|
10
|
+
## 3.0.0 - 2022-06-14
|
|
11
|
+
|
|
12
|
+
* Initial github release.
|
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
apex-parser
|
|
2
|
-
===========
|
|
1
|
+
# apex-parser
|
|
3
2
|
|
|
4
|
-
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/ApexParser.g4.
|
|
5
4
|
|
|
6
5
|
There are two builds of the parser available, a NPM module for use with Node and a Maven package for use on JVMs.
|
|
7
6
|
|
|
8
|
-
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
|
+
These builds just contain the Parser & Lexer and provides no further support for analysing the generated parse trees beyond what is provided by ANTLR4.
|
|
9
8
|
|
|
10
|
-
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
|
+
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.
|
|
10
|
+
|
|
11
|
+
## Example
|
|
11
12
|
|
|
12
|
-
### Example
|
|
13
13
|
To parse a class file (NPM version):
|
|
14
14
|
|
|
15
15
|
let lexer = new ApexLexer(new CaseInsensitiveInputStream("public class Hello {}"))
|
|
@@ -20,19 +20,28 @@ To parse a class file (NPM version):
|
|
|
20
20
|
|
|
21
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.
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
## Unicode handling
|
|
24
|
+
|
|
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.
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
## antlr4ts versions
|
|
27
28
|
|
|
28
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
|
|
29
|
-
sure that if you are using a matching versions of this dependency if you use it directly. To avoid issues you can
|
|
30
|
+
sure that if you are using a matching versions of this dependency if you use it directly. To avoid issues you can
|
|
30
31
|
import 'CommonTokenStream' & 'ParseTreeWalker' from 'apex-parser' instead of from antlr4ts.
|
|
31
32
|
|
|
32
33
|
import { CommonTokenStream} from "apex-parser";
|
|
33
34
|
import { ParseTreeWalker } from "apex-parser";
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
## SOSL FIND quoting
|
|
37
|
+
|
|
38
|
+
SOSL FIND uses ' as a quoting character when embedded in Apex, in the API braces are used:
|
|
39
|
+
|
|
40
|
+
Find {something} RETURNING Account
|
|
41
|
+
|
|
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.
|
|
43
|
+
|
|
44
|
+
## Packages
|
|
36
45
|
|
|
37
46
|
Maven
|
|
38
47
|
|
|
@@ -46,12 +55,26 @@ NPM
|
|
|
46
55
|
|
|
47
56
|
"@apexdevtools/apex-parser": "^3.0.0"
|
|
48
57
|
|
|
49
|
-
|
|
58
|
+
## Building
|
|
59
|
+
|
|
50
60
|
To build both distributions:
|
|
51
61
|
|
|
52
62
|
npm run build
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
## Testing
|
|
65
|
+
|
|
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 or use `git clone --recurse-submodules <repo-url>`. To run the tests:
|
|
67
|
+
|
|
68
|
+
# Set SAMPLES env var to samples repo location
|
|
69
|
+
export SAMPLES=<abs path to apex-samples>
|
|
70
|
+
|
|
71
|
+
# Exec test script
|
|
72
|
+
npm run test-samples
|
|
73
|
+
|
|
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.
|
|
75
|
+
|
|
76
|
+
## History
|
|
77
|
+
|
|
55
78
|
3.0.0 - Move to @apexdevtools/apex-parser
|
|
56
79
|
2.14.0 - Change npm api to replace ANTLRInputStream with CharStream, for Unicode char positions
|
|
57
80
|
2.13.0 - Fixes for negative numerics & Currency literals in SOQL
|
|
@@ -74,6 +97,6 @@ To build both distributions:
|
|
|
74
97
|
2.1.0 - Supports trigger parsing and switch statement parsing syntax was corrected
|
|
75
98
|
1.0.0 - Initial version
|
|
76
99
|
|
|
77
|
-
|
|
100
|
+
## Source & Licenses
|
|
78
101
|
|
|
79
102
|
All the source code included uses a 3-clause BSD license. The only third-party component included is the Apex Antlr4 grammar originally from [Tooling-force.com](https://github.com/neowit/tooling-force.com), although this version used is now markedly different from the original.
|
package/lib/ApexLexer.d.ts
CHANGED
|
@@ -111,133 +111,141 @@ export declare class ApexLexer extends Lexer {
|
|
|
111
111
|
static readonly VIEWSTAT = 106;
|
|
112
112
|
static readonly CUSTOM = 107;
|
|
113
113
|
static readonly STANDARD = 108;
|
|
114
|
-
static readonly
|
|
115
|
-
static readonly
|
|
116
|
-
static readonly
|
|
117
|
-
static readonly
|
|
118
|
-
static readonly
|
|
119
|
-
static readonly
|
|
120
|
-
static readonly
|
|
121
|
-
static readonly
|
|
122
|
-
static readonly
|
|
123
|
-
static readonly
|
|
124
|
-
static readonly
|
|
125
|
-
static readonly
|
|
126
|
-
static readonly
|
|
127
|
-
static readonly
|
|
128
|
-
static readonly
|
|
129
|
-
static readonly
|
|
130
|
-
static readonly
|
|
131
|
-
static readonly
|
|
132
|
-
static readonly
|
|
133
|
-
static readonly
|
|
134
|
-
static readonly
|
|
135
|
-
static readonly
|
|
136
|
-
static readonly
|
|
137
|
-
static readonly
|
|
138
|
-
static readonly
|
|
139
|
-
static readonly
|
|
140
|
-
static readonly
|
|
141
|
-
static readonly
|
|
142
|
-
static readonly
|
|
143
|
-
static readonly
|
|
144
|
-
static readonly
|
|
145
|
-
static readonly
|
|
146
|
-
static readonly
|
|
147
|
-
static readonly
|
|
148
|
-
static readonly
|
|
149
|
-
static readonly
|
|
150
|
-
static readonly
|
|
151
|
-
static readonly
|
|
152
|
-
static readonly
|
|
153
|
-
static readonly
|
|
154
|
-
static readonly
|
|
155
|
-
static readonly
|
|
156
|
-
static readonly
|
|
157
|
-
static readonly
|
|
158
|
-
static readonly
|
|
159
|
-
static readonly
|
|
160
|
-
static readonly
|
|
161
|
-
static readonly
|
|
162
|
-
static readonly
|
|
163
|
-
static readonly
|
|
164
|
-
static readonly
|
|
165
|
-
static readonly
|
|
166
|
-
static readonly
|
|
167
|
-
static readonly
|
|
168
|
-
static readonly
|
|
169
|
-
static readonly
|
|
170
|
-
static readonly
|
|
171
|
-
static readonly
|
|
172
|
-
static readonly
|
|
173
|
-
static readonly
|
|
174
|
-
static readonly
|
|
175
|
-
static readonly
|
|
176
|
-
static readonly
|
|
177
|
-
static readonly
|
|
178
|
-
static readonly
|
|
179
|
-
static readonly
|
|
180
|
-
static readonly
|
|
181
|
-
static readonly
|
|
182
|
-
static readonly
|
|
183
|
-
static readonly
|
|
184
|
-
static readonly
|
|
185
|
-
static readonly
|
|
186
|
-
static readonly
|
|
187
|
-
static readonly
|
|
188
|
-
static readonly
|
|
189
|
-
static readonly
|
|
190
|
-
static readonly
|
|
191
|
-
static readonly
|
|
192
|
-
static readonly
|
|
193
|
-
static readonly
|
|
194
|
-
static readonly
|
|
195
|
-
static readonly
|
|
196
|
-
static readonly
|
|
197
|
-
static readonly
|
|
198
|
-
static readonly
|
|
199
|
-
static readonly
|
|
200
|
-
static readonly
|
|
201
|
-
static readonly
|
|
202
|
-
static readonly
|
|
203
|
-
static readonly
|
|
204
|
-
static readonly
|
|
205
|
-
static readonly
|
|
206
|
-
static readonly
|
|
207
|
-
static readonly
|
|
208
|
-
static readonly
|
|
209
|
-
static readonly
|
|
210
|
-
static readonly
|
|
211
|
-
static readonly
|
|
212
|
-
static readonly
|
|
213
|
-
static readonly
|
|
214
|
-
static readonly
|
|
215
|
-
static readonly
|
|
216
|
-
static readonly
|
|
217
|
-
static readonly
|
|
218
|
-
static readonly
|
|
219
|
-
static readonly
|
|
220
|
-
static readonly
|
|
221
|
-
static readonly
|
|
222
|
-
static readonly
|
|
223
|
-
static readonly
|
|
224
|
-
static readonly
|
|
225
|
-
static readonly
|
|
226
|
-
static readonly
|
|
227
|
-
static readonly
|
|
228
|
-
static readonly
|
|
229
|
-
static readonly
|
|
230
|
-
static readonly
|
|
231
|
-
static readonly
|
|
232
|
-
static readonly
|
|
233
|
-
static readonly
|
|
234
|
-
static readonly
|
|
235
|
-
static readonly
|
|
236
|
-
static readonly
|
|
237
|
-
static readonly
|
|
238
|
-
static readonly
|
|
239
|
-
static readonly
|
|
240
|
-
static readonly
|
|
114
|
+
static readonly DISTANCE = 109;
|
|
115
|
+
static readonly GEOLOCATION = 110;
|
|
116
|
+
static readonly CALENDAR_MONTH = 111;
|
|
117
|
+
static readonly CALENDAR_QUARTER = 112;
|
|
118
|
+
static readonly CALENDAR_YEAR = 113;
|
|
119
|
+
static readonly DAY_IN_MONTH = 114;
|
|
120
|
+
static readonly DAY_IN_WEEK = 115;
|
|
121
|
+
static readonly DAY_IN_YEAR = 116;
|
|
122
|
+
static readonly DAY_ONLY = 117;
|
|
123
|
+
static readonly FISCAL_MONTH = 118;
|
|
124
|
+
static readonly FISCAL_QUARTER = 119;
|
|
125
|
+
static readonly FISCAL_YEAR = 120;
|
|
126
|
+
static readonly HOUR_IN_DAY = 121;
|
|
127
|
+
static readonly WEEK_IN_MONTH = 122;
|
|
128
|
+
static readonly WEEK_IN_YEAR = 123;
|
|
129
|
+
static readonly CONVERT_TIMEZONE = 124;
|
|
130
|
+
static readonly YESTERDAY = 125;
|
|
131
|
+
static readonly TODAY = 126;
|
|
132
|
+
static readonly TOMORROW = 127;
|
|
133
|
+
static readonly LAST_WEEK = 128;
|
|
134
|
+
static readonly THIS_WEEK = 129;
|
|
135
|
+
static readonly NEXT_WEEK = 130;
|
|
136
|
+
static readonly LAST_MONTH = 131;
|
|
137
|
+
static readonly THIS_MONTH = 132;
|
|
138
|
+
static readonly NEXT_MONTH = 133;
|
|
139
|
+
static readonly LAST_90_DAYS = 134;
|
|
140
|
+
static readonly NEXT_90_DAYS = 135;
|
|
141
|
+
static readonly LAST_N_DAYS_N = 136;
|
|
142
|
+
static readonly NEXT_N_DAYS_N = 137;
|
|
143
|
+
static readonly N_DAYS_AGO_N = 138;
|
|
144
|
+
static readonly NEXT_N_WEEKS_N = 139;
|
|
145
|
+
static readonly LAST_N_WEEKS_N = 140;
|
|
146
|
+
static readonly N_WEEKS_AGO_N = 141;
|
|
147
|
+
static readonly NEXT_N_MONTHS_N = 142;
|
|
148
|
+
static readonly LAST_N_MONTHS_N = 143;
|
|
149
|
+
static readonly N_MONTHS_AGO_N = 144;
|
|
150
|
+
static readonly THIS_QUARTER = 145;
|
|
151
|
+
static readonly LAST_QUARTER = 146;
|
|
152
|
+
static readonly NEXT_QUARTER = 147;
|
|
153
|
+
static readonly NEXT_N_QUARTERS_N = 148;
|
|
154
|
+
static readonly LAST_N_QUARTERS_N = 149;
|
|
155
|
+
static readonly N_QUARTERS_AGO_N = 150;
|
|
156
|
+
static readonly THIS_YEAR = 151;
|
|
157
|
+
static readonly LAST_YEAR = 152;
|
|
158
|
+
static readonly NEXT_YEAR = 153;
|
|
159
|
+
static readonly NEXT_N_YEARS_N = 154;
|
|
160
|
+
static readonly LAST_N_YEARS_N = 155;
|
|
161
|
+
static readonly N_YEARS_AGO_N = 156;
|
|
162
|
+
static readonly THIS_FISCAL_QUARTER = 157;
|
|
163
|
+
static readonly LAST_FISCAL_QUARTER = 158;
|
|
164
|
+
static readonly NEXT_FISCAL_QUARTER = 159;
|
|
165
|
+
static readonly NEXT_N_FISCAL_QUARTERS_N = 160;
|
|
166
|
+
static readonly LAST_N_FISCAL_QUARTERS_N = 161;
|
|
167
|
+
static readonly N_FISCAL_QUARTERS_AGO_N = 162;
|
|
168
|
+
static readonly THIS_FISCAL_YEAR = 163;
|
|
169
|
+
static readonly LAST_FISCAL_YEAR = 164;
|
|
170
|
+
static readonly NEXT_FISCAL_YEAR = 165;
|
|
171
|
+
static readonly NEXT_N_FISCAL_YEARS_N = 166;
|
|
172
|
+
static readonly LAST_N_FISCAL_YEARS_N = 167;
|
|
173
|
+
static readonly N_FISCAL_YEARS_AGO_N = 168;
|
|
174
|
+
static readonly DateLiteral = 169;
|
|
175
|
+
static readonly DateTimeLiteral = 170;
|
|
176
|
+
static readonly IntegralCurrencyLiteral = 171;
|
|
177
|
+
static readonly FIND = 172;
|
|
178
|
+
static readonly EMAIL = 173;
|
|
179
|
+
static readonly NAME = 174;
|
|
180
|
+
static readonly PHONE = 175;
|
|
181
|
+
static readonly SIDEBAR = 176;
|
|
182
|
+
static readonly FIELDS = 177;
|
|
183
|
+
static readonly METADATA = 178;
|
|
184
|
+
static readonly PRICEBOOKID = 179;
|
|
185
|
+
static readonly NETWORK = 180;
|
|
186
|
+
static readonly SNIPPET = 181;
|
|
187
|
+
static readonly TARGET_LENGTH = 182;
|
|
188
|
+
static readonly DIVISION = 183;
|
|
189
|
+
static readonly RETURNING = 184;
|
|
190
|
+
static readonly LISTVIEW = 185;
|
|
191
|
+
static readonly FindLiteral = 186;
|
|
192
|
+
static readonly FindLiteralAlt = 187;
|
|
193
|
+
static readonly IntegerLiteral = 188;
|
|
194
|
+
static readonly LongLiteral = 189;
|
|
195
|
+
static readonly NumberLiteral = 190;
|
|
196
|
+
static readonly BooleanLiteral = 191;
|
|
197
|
+
static readonly StringLiteral = 192;
|
|
198
|
+
static readonly NullLiteral = 193;
|
|
199
|
+
static readonly LPAREN = 194;
|
|
200
|
+
static readonly RPAREN = 195;
|
|
201
|
+
static readonly LBRACE = 196;
|
|
202
|
+
static readonly RBRACE = 197;
|
|
203
|
+
static readonly LBRACK = 198;
|
|
204
|
+
static readonly RBRACK = 199;
|
|
205
|
+
static readonly SEMI = 200;
|
|
206
|
+
static readonly COMMA = 201;
|
|
207
|
+
static readonly DOT = 202;
|
|
208
|
+
static readonly ASSIGN = 203;
|
|
209
|
+
static readonly GT = 204;
|
|
210
|
+
static readonly LT = 205;
|
|
211
|
+
static readonly BANG = 206;
|
|
212
|
+
static readonly TILDE = 207;
|
|
213
|
+
static readonly QUESTIONDOT = 208;
|
|
214
|
+
static readonly QUESTION = 209;
|
|
215
|
+
static readonly COLON = 210;
|
|
216
|
+
static readonly EQUAL = 211;
|
|
217
|
+
static readonly TRIPLEEQUAL = 212;
|
|
218
|
+
static readonly NOTEQUAL = 213;
|
|
219
|
+
static readonly LESSANDGREATER = 214;
|
|
220
|
+
static readonly TRIPLENOTEQUAL = 215;
|
|
221
|
+
static readonly AND = 216;
|
|
222
|
+
static readonly OR = 217;
|
|
223
|
+
static readonly INC = 218;
|
|
224
|
+
static readonly DEC = 219;
|
|
225
|
+
static readonly ADD = 220;
|
|
226
|
+
static readonly SUB = 221;
|
|
227
|
+
static readonly MUL = 222;
|
|
228
|
+
static readonly DIV = 223;
|
|
229
|
+
static readonly BITAND = 224;
|
|
230
|
+
static readonly BITOR = 225;
|
|
231
|
+
static readonly CARET = 226;
|
|
232
|
+
static readonly MAPTO = 227;
|
|
233
|
+
static readonly ADD_ASSIGN = 228;
|
|
234
|
+
static readonly SUB_ASSIGN = 229;
|
|
235
|
+
static readonly MUL_ASSIGN = 230;
|
|
236
|
+
static readonly DIV_ASSIGN = 231;
|
|
237
|
+
static readonly AND_ASSIGN = 232;
|
|
238
|
+
static readonly OR_ASSIGN = 233;
|
|
239
|
+
static readonly XOR_ASSIGN = 234;
|
|
240
|
+
static readonly LSHIFT_ASSIGN = 235;
|
|
241
|
+
static readonly RSHIFT_ASSIGN = 236;
|
|
242
|
+
static readonly URSHIFT_ASSIGN = 237;
|
|
243
|
+
static readonly ATSIGN = 238;
|
|
244
|
+
static readonly Identifier = 239;
|
|
245
|
+
static readonly WS = 240;
|
|
246
|
+
static readonly DOC_COMMENT = 241;
|
|
247
|
+
static readonly COMMENT = 242;
|
|
248
|
+
static readonly LINE_COMMENT = 243;
|
|
241
249
|
static readonly WHITESPACE_CHANNEL = 2;
|
|
242
250
|
static readonly COMMENT_CHANNEL = 3;
|
|
243
251
|
static readonly channelNames: string[];
|