-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript_lexer.go
400 lines (342 loc) · 12.4 KB
/
javascript_lexer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
// Code generated from JavaScriptLexer.g4 by ANTLR 4.9.2. DO NOT EDIT.
package parser
import (
"fmt"
"unicode"
"github.com/antlr/antlr4/runtime/Go/antlr"
)
// Suppress unused import error
var _ = fmt.Printf
var _ = unicode.IsLetter
type JavaScriptLexer struct {
JavaScriptLexerBase
channelNames []string
modeNames []string
// TODO: EOF string
}
// NewJavaScriptLexer produces a new lexer instance for the optional input antlr.CharStream.
//
// The *JavaScriptLexer instance produced may be reused by calling the SetInputStream method.
// The initial lexer configuration is expensive to construct, and the object is not thread-safe;
// however, if used within a Golang sync.Pool, the construction cost amortizes well and the
// objects can be used in a thread-safe manner.
func NewJavaScriptLexer(input antlr.CharStream) *JavaScriptLexer {
l := new(JavaScriptLexer)
lexerDeserializer := antlr.NewATNDeserializer(nil)
lexerAtn := lexerDeserializer.DeserializeFromUInt16(serializedLexerAtn)
lexerDecisionToDFA := make([]*antlr.DFA, len(lexerAtn.DecisionToState))
for index, ds := range lexerAtn.DecisionToState {
lexerDecisionToDFA[index] = antlr.NewDFA(ds, index)
}
l.BaseLexer = antlr.NewBaseLexer(input)
l.Interpreter = antlr.NewLexerATNSimulator(l, lexerAtn, lexerDecisionToDFA, antlr.NewPredictionContextCache())
l.channelNames = lexerChannelNames
l.modeNames = lexerModeNames
l.RuleNames = lexerRuleNames
l.LiteralNames = lexerLiteralNames
l.SymbolicNames = lexerSymbolicNames
l.GrammarFileName = "JavaScriptLexer.g4"
// TODO: l.EOF = antlr.TokenEOF
return l
}
// JavaScriptLexer tokens.
const (
JavaScriptLexerHashBangLine = 1
JavaScriptLexerMultiLineComment = 2
JavaScriptLexerSingleLineComment = 3
JavaScriptLexerRegularExpressionLiteral = 4
JavaScriptLexerOpenBracket = 5
JavaScriptLexerCloseBracket = 6
JavaScriptLexerOpenParen = 7
JavaScriptLexerCloseParen = 8
JavaScriptLexerOpenBrace = 9
JavaScriptLexerCloseBrace = 10
JavaScriptLexerSemiColon = 11
JavaScriptLexerComma = 12
JavaScriptLexerAssign = 13
JavaScriptLexerQuestionMark = 14
JavaScriptLexerColon = 15
JavaScriptLexerEllipsis = 16
JavaScriptLexerDot = 17
JavaScriptLexerPlusPlus = 18
JavaScriptLexerMinusMinus = 19
JavaScriptLexerPlus = 20
JavaScriptLexerMinus = 21
JavaScriptLexerBitNot = 22
JavaScriptLexerNot = 23
JavaScriptLexerMultiply = 24
JavaScriptLexerDivide = 25
JavaScriptLexerModulus = 26
JavaScriptLexerPower = 27
JavaScriptLexerNullCoalesce = 28
JavaScriptLexerHashtag = 29
JavaScriptLexerRightShiftArithmetic = 30
JavaScriptLexerLeftShiftArithmetic = 31
JavaScriptLexerRightShiftLogical = 32
JavaScriptLexerLessThan = 33
JavaScriptLexerMoreThan = 34
JavaScriptLexerLessThanEquals = 35
JavaScriptLexerGreaterThanEquals = 36
JavaScriptLexerEquals_ = 37
JavaScriptLexerNotEquals = 38
JavaScriptLexerIdentityEquals = 39
JavaScriptLexerIdentityNotEquals = 40
JavaScriptLexerBitAnd = 41
JavaScriptLexerBitXOr = 42
JavaScriptLexerBitOr = 43
JavaScriptLexerAnd = 44
JavaScriptLexerOr = 45
JavaScriptLexerMultiplyAssign = 46
JavaScriptLexerDivideAssign = 47
JavaScriptLexerModulusAssign = 48
JavaScriptLexerPlusAssign = 49
JavaScriptLexerMinusAssign = 50
JavaScriptLexerLeftShiftArithmeticAssign = 51
JavaScriptLexerRightShiftArithmeticAssign = 52
JavaScriptLexerRightShiftLogicalAssign = 53
JavaScriptLexerBitAndAssign = 54
JavaScriptLexerBitXorAssign = 55
JavaScriptLexerBitOrAssign = 56
JavaScriptLexerPowerAssign = 57
JavaScriptLexerARROW = 58
JavaScriptLexerNullLiteral = 59
JavaScriptLexerBooleanLiteral = 60
JavaScriptLexerDecimalLiteral = 61
JavaScriptLexerHexIntegerLiteral = 62
JavaScriptLexerOctalIntegerLiteral = 63
JavaScriptLexerOctalIntegerLiteral2 = 64
JavaScriptLexerBinaryIntegerLiteral = 65
JavaScriptLexerBigHexIntegerLiteral = 66
JavaScriptLexerBigOctalIntegerLiteral = 67
JavaScriptLexerBigBinaryIntegerLiteral = 68
JavaScriptLexerBigDecimalIntegerLiteral = 69
JavaScriptLexerBreak = 70
JavaScriptLexerDo = 71
JavaScriptLexerInstanceof = 72
JavaScriptLexerTypeof = 73
JavaScriptLexerCase = 74
JavaScriptLexerElse = 75
JavaScriptLexerNew = 76
JavaScriptLexerVar = 77
JavaScriptLexerCatch = 78
JavaScriptLexerFinally = 79
JavaScriptLexerReturn = 80
JavaScriptLexerVoid = 81
JavaScriptLexerContinue = 82
JavaScriptLexerFor = 83
JavaScriptLexerSwitch = 84
JavaScriptLexerWhile = 85
JavaScriptLexerDebugger = 86
JavaScriptLexerFunction = 87
JavaScriptLexerThis = 88
JavaScriptLexerWith = 89
JavaScriptLexerDefault = 90
JavaScriptLexerIf = 91
JavaScriptLexerThrow = 92
JavaScriptLexerDelete = 93
JavaScriptLexerIn = 94
JavaScriptLexerTry = 95
JavaScriptLexerAs = 96
JavaScriptLexerFrom = 97
JavaScriptLexerClass = 98
JavaScriptLexerEnum = 99
JavaScriptLexerExtends = 100
JavaScriptLexerSuper = 101
JavaScriptLexerConst = 102
JavaScriptLexerExport = 103
JavaScriptLexerImport = 104
JavaScriptLexerAsync = 105
JavaScriptLexerAwait = 106
JavaScriptLexerImplements = 107
JavaScriptLexerStrictLet = 108
JavaScriptLexerNonStrictLet = 109
JavaScriptLexerPrivate = 110
JavaScriptLexerPublic = 111
JavaScriptLexerInterface = 112
JavaScriptLexerPackage = 113
JavaScriptLexerProtected = 114
JavaScriptLexerStatic = 115
JavaScriptLexerYield = 116
JavaScriptLexerIdentifier = 117
JavaScriptLexerStringLiteral = 118
JavaScriptLexerTemplateStringLiteral = 119
JavaScriptLexerWhiteSpaces = 120
JavaScriptLexerLineTerminator = 121
JavaScriptLexerHtmlComment = 122
JavaScriptLexerCDataComment = 123
JavaScriptLexerUnexpectedCharacter = 124
)
// JavaScriptLexerERROR is the JavaScriptLexer channel.
const JavaScriptLexerERROR = 2
func (l *JavaScriptLexer) Action(localctx antlr.RuleContext, ruleIndex, actionIndex int) {
switch ruleIndex {
case 8:
l.OpenBrace_Action(localctx, actionIndex)
case 9:
l.CloseBrace_Action(localctx, actionIndex)
case 117:
l.StringLiteral_Action(localctx, actionIndex)
default:
panic("No registered action for: " + fmt.Sprint(ruleIndex))
}
}
func (l *JavaScriptLexer) OpenBrace_Action(localctx antlr.RuleContext, actionIndex int) {
switch actionIndex {
case 0:
l.ProcessOpenBrace()
default:
panic("No registered action for: " + fmt.Sprint(actionIndex))
}
}
func (l *JavaScriptLexer) CloseBrace_Action(localctx antlr.RuleContext, actionIndex int) {
switch actionIndex {
case 1:
l.ProcessCloseBrace()
default:
panic("No registered action for: " + fmt.Sprint(actionIndex))
}
}
func (l *JavaScriptLexer) StringLiteral_Action(localctx antlr.RuleContext, actionIndex int) {
switch actionIndex {
case 2:
l.ProcessStringLiteral()
default:
panic("No registered action for: " + fmt.Sprint(actionIndex))
}
}
func (l *JavaScriptLexer) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool {
switch ruleIndex {
case 0:
return l.HashBangLine_Sempred(localctx, predIndex)
case 3:
return l.RegularExpressionLiteral_Sempred(localctx, predIndex)
case 62:
return l.OctalIntegerLiteral_Sempred(localctx, predIndex)
case 106:
return l.Implements_Sempred(localctx, predIndex)
case 107:
return l.StrictLet_Sempred(localctx, predIndex)
case 108:
return l.NonStrictLet_Sempred(localctx, predIndex)
case 109:
return l.Private_Sempred(localctx, predIndex)
case 110:
return l.Public_Sempred(localctx, predIndex)
case 111:
return l.Interface_Sempred(localctx, predIndex)
case 112:
return l.Package_Sempred(localctx, predIndex)
case 113:
return l.Protected_Sempred(localctx, predIndex)
case 114:
return l.Static_Sempred(localctx, predIndex)
case 115:
return l.Yield_Sempred(localctx, predIndex)
default:
panic("No registered predicate for: " + fmt.Sprint(ruleIndex))
}
}
func (p *JavaScriptLexer) HashBangLine_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 0:
return p.IsStartOfFile()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) RegularExpressionLiteral_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 1:
return p.IsRegexPossible()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) OctalIntegerLiteral_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 2:
return !p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) Implements_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 3:
return p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) StrictLet_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 4:
return p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) NonStrictLet_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 5:
return !p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) Private_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 6:
return p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) Public_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 7:
return p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) Interface_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 8:
return p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) Package_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 9:
return p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) Protected_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 10:
return p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) Static_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 11:
return p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}
func (p *JavaScriptLexer) Yield_Sempred(localctx antlr.RuleContext, predIndex int) bool {
switch predIndex {
case 12:
return p.IsStrictMode()
default:
panic("No predicate with index: " + fmt.Sprint(predIndex))
}
}