parsejs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,575 @@
1
+ %% name = ParseJS::Parser
2
+
3
+ %% ast-location = ::ParseJS::AST
4
+ %% program = ast Program(elements)
5
+ %% expression_statement = ast ExpressionStatement(expression)
6
+ %% block_statement = ast BlockStatement(statements)
7
+ %% empty_statement = ast EmptyStatement()
8
+ %% identifier = ast Identifier(val)
9
+ %% literal = ast Literal(val)
10
+ %% number = ast Number(val)
11
+ %% string_literal = ast String(val, quote)
12
+ %% regexp = ast RegExp(body, flags)
13
+ %% this_expression = ast ThisExpression()
14
+ %% variable_declaration = ast VariableDeclaration(kind, declarations, semicolon)
15
+ %% variable_declarator = ast VariableDeclarator(id, init)
16
+ %% array_expression = ast ArrayExpression(elements)
17
+ %% object_expression = ast ObjectExpression(properties)
18
+ %% function_declaration = ast FunctionDeclaration(id, params, body)
19
+ %% function_expression = ast FunctionExpression(id, params, body)
20
+ %% parameter_list = ast ParameterList(list)
21
+ %% return_statement = ast ReturnStatement(label)
22
+ %% try_statement = ast TryStatement(block, handler, finalizer)
23
+ %% catch_clause = ast CatchClause(param, body)
24
+ %% throw_statement = ast ThrowStatement(argument)
25
+ %% labeled_statement = ast LabeledStatement(label, body)
26
+ %% break_statement = ast BreakStatement(label)
27
+ %% continue_statement = ast ContinueStatement(label)
28
+ %% switch_statement = ast SwitchStatement(discriminant, cases)
29
+ %% switch_case = ast SwitchCase(test, consequent)
30
+ %% with_statement = ast WithStatement(object, body)
31
+ %% conditional_expression = ast ConditionalExpression(test, consequent, alternate)
32
+ %% sequence_expression = ast SequenceExpression(expressions)
33
+ %% binary_expression = ast BinaryExpression(op, left, right)
34
+ %% assignment_expression = ast AssignmentExpression(op, left, right)
35
+ %% logical_expression = ast LogicalExpression(op, left, right)
36
+ %% unary_expression = ast UnaryExpression(op, argument)
37
+ %% update_expression = ast UpdateExpression(op, argument, prefix)
38
+ %% call_expression = ast CallExpression(callee, args)
39
+ %% new_expression = ast NewExpression(callee, args)
40
+ %% property = ast Property(key, value, kind, comments)
41
+ %% member_expression = ast MemberExpression(object, property, computed)
42
+ %% debugger_statement = ast DebuggerStatement()
43
+ %% while_statement = ast WhileStatement(test, body)
44
+ %% do_while_statement = ast DoWhileStatement(body, test)
45
+ %% for_statement = ast ForStatement(init, test, update, body)
46
+ %% for_in_statement = ast ForInStatement(left, right, body, type)
47
+ %% if_statement = ast IfStatement(test, consequent, alternate)
48
+ %% object_pattern = ast ObjectPattern(properties)
49
+ %% array_pattern = ast ArrayPattern(elements)
50
+ %% spread = ast Spread(name)
51
+ %% comment = ast Comment(body, type, newline)
52
+ %% commented_statement = ast CommentedStatement(statement, comments)
53
+
54
+ %%{
55
+ def initialize(string)
56
+ super
57
+ @benchmark = true
58
+ end
59
+ }
60
+
61
+ # Whitespace and Source Characters
62
+
63
+ S =
64
+ WhiteSpace
65
+ | LineTerminatorSequence { nil }
66
+ | Comment
67
+
68
+ - = S*:spaces { spaces.compact }
69
+
70
+ SnoComment = (WhiteSpace | LineTerminatorSequence) { nil }
71
+
72
+ SnoLB = (WhiteSpace | SingleLineComment | MultiLineCommentNoLB)+
73
+
74
+ WhiteSpace = /[\t\v\f ]+/ { nil }
75
+
76
+ LF = "\n"
77
+ CR = "\r"
78
+
79
+ LineTerminator = /[\n\r]+/
80
+ LineTerminatorSequence = < /\n|\r\n|\r/ > { text }
81
+
82
+ Comment = MultiLineComment | SingleLineComment
83
+
84
+ MultiLineCommentNoLB =
85
+ "/*" < (!("*/") SourceCharacter)* > "*/" ~comment(text, 'multiline', nil)
86
+
87
+ MultiLineComment =
88
+ "/*" < (!("*/") SourceCharacter)* > "*/" LineTerminatorSequence:lf ~comment(text, 'multiline', lf)
89
+ | MultiLineCommentNoLB
90
+
91
+ SingleLineComment = "//" < /[^\n\r]*/ > ~comment(text, 'singleline', nil)
92
+
93
+ SourceCharacter = /[\x00-\xff]/n
94
+
95
+ EOS = - ";" | SnoLB? LineTerminatorSequence | SnoLB? &("}") | - EOF
96
+ EOSnoLB = SnoLB? ";" | SnoLB? LineTerminatorSequence | SnoLB? &("}") | SnoLB? EOF
97
+
98
+ EOF = !(SourceCharacter)
99
+
100
+ # Keywords and Tokens
101
+
102
+ ReservedWord =
103
+ (Keyword | FutureReservedWord | "null" | "true" | "false") !(IdentifierPart)
104
+
105
+ Keyword =
106
+ /break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|instanceof|in|new|return|switch|this|throw|try|typeof|var|void|while|with/
107
+
108
+ FutureReservedWord =
109
+ /abstract|boolean|byte|char|class|const|double|enum|export|extends|final|float|goto|implements|import|interface|int|long|native|package|private|protected|public|short|static|super|synchronized|throws|transient|volatile/
110
+
111
+ Identifier = !(ReservedWord) IdentifierName:name ~identifier(name)
112
+
113
+ IdentifierName = < IdentifierStart IdentifierPart* > { text }
114
+
115
+ # TODO: Handle Unicode correctly
116
+ IdentifierStart = /[A-Za-z]/ | "$" | "_"
117
+
118
+ IdentifierPart = IdentifierStart | /[0-9]/
119
+
120
+ HexDigit = /[0-9a-fA-F]/
121
+
122
+ FalseTok = "false" !(IdentifierPart)
123
+ TrueTok = "true" !(IdentifierPart)
124
+ NullTok = "null" !(IdentifierPart)
125
+ BreakTok = "break" !(IdentifierPart)
126
+ ContinueTok = "continue" !(IdentifierPart)
127
+ DebuggerTok = "debugger" !(IdentifierPart)
128
+ InTok = "in" !(IdentifierPart)
129
+ InstanceOfTok = "instanceof" !(IdentifierPart)
130
+ DeleteTok = "delete" !(IdentifierPart)
131
+ FunctionTok = "function" !(IdentifierPart)
132
+ NewTok = "new" !(IdentifierPart)
133
+ ThisTok = "this" !(IdentifierPart)
134
+ TypeofTok = "typeof" !(IdentifierPart)
135
+ VoidTok = "void" !(IdentifierPart)
136
+ IfTok = "if" !(IdentifierPart)
137
+ ElseTok = "else" !(IdentifierPart)
138
+ DoTok = "do" !(IdentifierPart)
139
+ WhileTok = "while" !(IdentifierPart)
140
+ ForTok = "for" !(IdentifierPart)
141
+ VarTok = "var" !(IdentifierPart)
142
+ ReturnTok = "return" !(IdentifierPart)
143
+ CaseTok = "case" !(IdentifierPart)
144
+ DefaultTok = "default" !(IdentifierPart)
145
+ SwitchTok = "switch" !(IdentifierPart)
146
+ ThrowTok = "throw" !(IdentifierPart)
147
+ CatchTok = "catch" !(IdentifierPart)
148
+ FinallyTok = "finally" !(IdentifierPart)
149
+ TryTok = "try" !(IdentifierPart)
150
+ WithTok = "with" !(IdentifierPart)
151
+
152
+ # Program
153
+
154
+ root = Program:p { p }
155
+
156
+ Program = (CommentedStatement)*:s - ~program(s)
157
+
158
+ FunctionBody = (CommentedStatement)*:statements - { statements }
159
+
160
+ FunctionDeclaration = FunctionTok - Identifier:id - "(" - FormalParameterList?:params - ")" - "{" SnoComment* FunctionBody:body - "}" ~function_declaration(id, params || parameter_list([]), body)
161
+
162
+ FunctionExpression = FunctionTok - Identifier?:id - "(" - FormalParameterList?:params - ")" - "{" SnoComment* FunctionBody:body - "}" ~function_expression(id, params || parameter_list([]), body)
163
+
164
+ FormalParameterList = Identifier:id (- "," - Identifier)*:ids ~parameter_list([id] + ids)
165
+
166
+ UseStrictDirective = "use" S "strict" S ("," !(LineTerminator) SourceCharacter)*
167
+
168
+ # Statements
169
+
170
+ Statement =
171
+ IfStatement
172
+ | ExpressionStatement
173
+ | VariableStatement
174
+ | Block
175
+ | EmptyStatement
176
+ | IterationStatement
177
+ | ContinueStatement
178
+ | BreakStatement
179
+ | ReturnStatement
180
+ | WithStatement
181
+ | LabeledStatement
182
+ | SwitchStatement
183
+ | ThrowStatement
184
+ | TryStatement
185
+ | DebuggerStatement
186
+ | FunctionDeclaration
187
+
188
+ CommentedStatement = -:comments Statement:s ~commented_statement(s, comments)
189
+
190
+ Block = "{" (CommentedStatement)*:statements - "}" ~block_statement(statements)
191
+
192
+ VariableStatement = VarTok - VariableDeclaration:decl (- "," - VariableDeclaration)*:decls EOS ~variable_declaration("var", [decl] + decls, true)
193
+
194
+ VariableDeclaration = Identifier:id (- "=" !("=") - AssignmentExpression:expr)? ~variable_declarator(id, expr)
195
+
196
+ VariableDeclarationNoIn = Identifier:id (- "=" !("=") - AssignmentExpressionNoIn:expr)? ~variable_declarator(id, expr)
197
+
198
+ VariableDeclarationListNoIn = VariableDeclarationNoIn:var (- "," - VariableDeclarationNoIn)*:vars { [var] + vars }
199
+
200
+ EmptyStatement = ";" ~empty_statement()
201
+
202
+ ExpressionStatement = !("{" | FunctionTok) Expression:e EOS ~expression_statement(e)
203
+
204
+ IfStatement = IfTok - "(" - Expression:expr - ")" - Statement:stmt1 (- ElseTok - Statement:stmt2)? ~if_statement(expr, stmt1, stmt2)
205
+
206
+ IterationStatement = DoWhileStatement | WhileStatement | ForInStatement | ForStatement
207
+
208
+ DoWhileStatement =
209
+ DoTok - Statement:stmt - WhileTok - "(" - Expression:expr - ")" EOS ~do_while_statement(stmt, expr)
210
+
211
+ WhileStatement =
212
+ WhileTok - "(" - Expression:expr - ")" - Statement:stmt ~while_statement(expr, stmt)
213
+
214
+ ForInStatement =
215
+ ForTok - "(" (ForInLeft|ForInVarLeft):left InTok - Expression:right - ")" - Statement:stmt ~for_in_statement(left, right, stmt, nil)
216
+
217
+ ForInLeft = - LeftHandSideExpression:expr - { expr }
218
+ ForInVarLeft = - VarTok - VariableDeclarationNoIn:decl - ~variable_declaration("var", [decl], false)
219
+
220
+ ForStatement =
221
+ ForTok - "(" - (ForVarInit|ForInit)?:init - ";" - ForTest?:test - ";" - ForUpdate?:update - ")" - Statement:body ~for_statement(init, test, update, body)
222
+
223
+ ForInit = ExpressionNoIn
224
+ ForVarInit = VarTok - VariableDeclarationListNoIn:list ~variable_declaration("var", list, false)
225
+ ForTest = Expression
226
+ ForUpdate = Expression
227
+
228
+ ContinueStatement =
229
+ ContinueTok SnoLB? Identifier:id EOS ~continue_statement(id)
230
+ | ContinueTok SnoLB? EOSnoLB ~continue_statement(nil)
231
+
232
+ BreakStatement =
233
+ BreakTok SnoLB? Identifier:id ROS ~break_statement(id)
234
+ | BreakTok SnoLB? EOSnoLB ~break_statement(nil)
235
+
236
+ ReturnStatement =
237
+ ReturnTok SnoLB? (EOSnoLB | Expression:expr EOS) ~return_statement(expr)
238
+
239
+ WithStatement =
240
+ WithTok - "(" - Expression:expr - ")" - Statement:statement ~with_statement(expr, statement)
241
+
242
+ LabeledStatement =
243
+ Identifier:id - ":" - Statement:statement ~labeled_statement(id, statement)
244
+
245
+ SwitchStatement =
246
+ SwitchTok - "(" - Expression:expr - ")" - "{" - CaseClauses:clauses - "}" ~switch_statement(expr, clauses)
247
+
248
+ CaseClauses =
249
+ CaseClause*:clauses - DefaultClause:default - CaseClause*:more_clauses { clauses + [default] + more_clauses }
250
+ | CaseClause*:clauses - DefaultClause:default { clauses + [default] }
251
+ | CaseClause*:clauses { clauses }
252
+
253
+ CaseClause =
254
+ - CaseTok - Expression:expr - ":" (- Statement)*:statements ~switch_case(expr, statements)
255
+
256
+ DefaultClause =
257
+ - DefaultTok:tok - ":" (- Statement)*:statements ~switch_case(nil, statements)
258
+
259
+ ThrowStatement =
260
+ ThrowTok SnoLB? (EOSnoLB | Expression:expr EOS) ~throw_statement(expr)
261
+
262
+ TryStatement =
263
+ TryTok - Block:try - Catch:catch - Finally?:finally ~try_statement(try, catch, finally)
264
+ | TryTok - Block:try - Finally:finally ~try_statement(try, nil, finally)
265
+
266
+ Catch =
267
+ CatchTok - "(" - Identifier:id - ")" - Block:block ~catch_clause(id, block)
268
+
269
+ Finally =
270
+ FinallyTok - Block:block { block }
271
+
272
+ DebuggerStatement =
273
+ DebuggerTok - EOS ~debugger_statement()
274
+
275
+ # Expressions
276
+
277
+ Expression =
278
+ AssignmentExpression:expr (- "," - AssignmentExpression)*:exprs ~sequence_expression([expr] + exprs)
279
+
280
+ ExpressionNoIn =
281
+ AssignmentExpressionNoIn:expr (- "," - AssignmentExpressionNoIn)*:exprs ~sequence_expression([expr] + exprs)
282
+
283
+ AssignmentExpression =
284
+ LeftHandSideExpression:left - AssignmentOperator:op - AssignmentExpression:right ~assignment_expression(op, left, right)
285
+ | ConditionalExpression
286
+
287
+ AssignmentExpressionNoIn =
288
+ LeftHandSideExpression:left - AssignmentOperator:op - AssignmentExpressionNoIn:right ~assignment_expression(op, left, right)
289
+ | ConditionalExpressionNoIn
290
+
291
+ AssignmentOperator =
292
+ < "=" !("=") | "*=" | "|=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | ">>>=" | "&=" | "^=" | "|=" > { text }
293
+
294
+ ConditionalExpression =
295
+ LogicalOrExpression:left - "?" - AssignmentExpression:middle - ":" - AssignmentExpression:right ~conditional_expression(left, middle, right)
296
+ | LogicalOrExpression
297
+
298
+ ConditionalExpressionNoIn =
299
+ LogicalOrExpressionNoIn:left - "?" - AssignmentExpressionNoIn:middle - ":" - AssignmentExpressionNoIn:right ~conditional_expression(left, middle, right)
300
+ | LogicalOrExpressionNoIn
301
+
302
+ LogicalOrExpression =
303
+ LogicalOrExpression:left - "||" - LogicalAndExpression:right ~logical_expression('||', left, right)
304
+ | LogicalAndExpression
305
+
306
+ LogicalOrExpressionNoIn =
307
+ LogicalAndExpressionNoIn:left - "||" - LogicalAndExpressionNoIn:right ~logical_expression('||', left, right)
308
+ | LogicalAndExpressionNoIn
309
+
310
+ LogicalAndExpression =
311
+ LogicalAndExpression:left - '&&' - BitwiseOrExpression:right ~logical_expression('&&', left, right)
312
+ | BitwiseOrExpression
313
+
314
+ LogicalAndExpressionNoIn =
315
+ LogicalAndExpression:left - "&&" - BitwiseOrExpressionNoIn:right ~logical_expression('&&', left, right)
316
+ | BitwiseOrExpressionNoIn
317
+
318
+ BitwiseOrExpression =
319
+ BitwiseOrExpression:left - "|" !("=") - BitwiseXOrExpression:right ~binary_expression('|', left, right)
320
+ | BitwiseXOrExpression
321
+
322
+ BitwiseOrExpressionNoIn =
323
+ BitwiseOrExpressionNoIn:left - "|" !("=") - BitwiseXOrExpressionNoIn:right ~binary_expression('|', left, right)
324
+ | BitwiseXOrExpressionNoIn
325
+
326
+ BitwiseXOrExpression =
327
+ BitwiseXOrExpression:left - "^" !("=") - BitwiseAndExpression:right ~binary_expression('^', left, right)
328
+ | BitwiseAndExpression
329
+
330
+ BitwiseXOrExpressionNoIn =
331
+ BitwiseXOrExpressionNoIn:left - "^" !("=") - BitwiseAndExpressionNoIn:right ~binary_expression('^', left, right)
332
+ | BitwiseAndExpressionNoIn
333
+
334
+ BitwiseAndExpression =
335
+ BitwiseAndExpression:left - "&" !("=") - EqualityExpression:right ~binary_expression('&', left, right)
336
+ | EqualityExpression
337
+
338
+ BitwiseAndExpressionNoIn =
339
+ BitwiseAndExpressionNoIn:left - "&" !("=") - EqualityExpressionNoIn:right ~binary_expression('&', left, right)
340
+ | EqualityExpressionNoIn
341
+
342
+ EqualityExpression =
343
+ EqualityExpression:left - EqualityOp:op - RelationalExpression:right ~binary_expression(op, left, right)
344
+ | RelationalExpression
345
+
346
+ EqualityExpressionNoIn =
347
+ EqualityExpressionNoIn:left - EqualityOp:op - RelationalExpressionNoIn:right ~binary_expression(op, left, right)
348
+ | RelationalExpressionNoIn
349
+
350
+ EqualityOp = < "===" | "!==" | "==" | "!=" > { text }
351
+
352
+ RelationalExpression =
353
+ RelationalExpression:left - RelationalOp:op - ShiftExpression:right ~binary_expression(op, left, right)
354
+ | ShiftExpression:expr
355
+
356
+ RelationalExpressionNoIn =
357
+ RelationalExpressionNoIn:left - RelationalOpNoIn - ShiftExpression:right ~binary_expression(op, left, right)
358
+ | ShiftExpression
359
+
360
+ RelationalOp =
361
+ < "<=" | ">=" | "<" | ">" | InstanceOfTok | InTok > { text }
362
+
363
+ RelationalOpNoIn =
364
+ < "<=" | ">=" | "<" | ">" | InstanceOfTok > { text }
365
+
366
+ ShiftExpression =
367
+ ShiftExpression:left - ShiftOp:op - AdditiveExpression:right ~binary_expression(op, left, right)
368
+ | AdditiveExpression
369
+
370
+ ShiftOp =
371
+ < "<<" | ">>>" | ">>" > { text }
372
+
373
+ AdditiveExpression =
374
+ AdditiveExpression:left - AdditiveOp:op - MultiplicativeExpression:right ~binary_expression(op, left, right)
375
+ | MultiplicativeExpression
376
+
377
+ AdditiveOp =
378
+ < "+" > !("+"|"=") { text }
379
+ | < "-" > !("-"|"=") { text }
380
+
381
+ MultiplicativeExpression =
382
+ MultiplicativeExpression:left - MultiplicativeOp:op - UnaryExpression:right ~binary_expression(op, left, right)
383
+ | UnaryExpression
384
+
385
+ MultiplicativeOp =
386
+ < ("*" | "/" | "%") > !("=") { text }
387
+
388
+ UnaryExpression =
389
+ PostfixExpression
390
+ | SimpleUnaryExpression
391
+
392
+ SimpleUnaryExpression =
393
+ UnaryOp:op - UnaryExpression:expr ~unary_expression(op, expr)
394
+
395
+ UnaryOp = < DeleteTok | VoidTok | TypeofTok | "++" | "--" | "+" | "-" | "~" | "!" > { text }
396
+
397
+ PostfixExpression =
398
+ LeftHandSideExpression:argument SnoLB? PostfixOp:op ~update_expression(op, argument, false)
399
+ | LeftHandSideExpression
400
+
401
+ PostfixOp = < ("++" | "--") > { text }
402
+
403
+ LeftHandSideExpression =
404
+ CallExpression
405
+ | NewExpression
406
+
407
+ CallExpression =
408
+ CallExpression:call - BracketAccessor:expr ~member_expression(call, expr, true)
409
+ | CallExpression:call - DotAccessor:expr ~member_expression(call, expr, false)
410
+ | CallExpression:expr - Arguments:arguments ~call_expression(expr, arguments)
411
+ | MemberExpression:expr - Arguments:arguments ~call_expression(expr, arguments)
412
+
413
+ BracketAccessor =
414
+ "[" - Expression:expr - "]" { expr }
415
+
416
+ DotAccessor =
417
+ "." - IdentifierName:id ~identifier(id)
418
+
419
+ Arguments =
420
+ "(" - ArgumentList?:args - ")" { args || [] }
421
+
422
+ ArgumentList =
423
+ AssignmentExpression:expr (- "," - AssignmentExpression)*:exprs { [expr] + exprs }
424
+
425
+ NewExpression =
426
+ MemberExpression
427
+ | NewTok - NewExpression:expr ~new_expression(expr, nil)
428
+
429
+ MemberExpression =
430
+ MemberExpression:left - BracketAccessor:right ~member_expression(left, right, true)
431
+ | MemberExpression:left - DotAccessor:right ~member_expression(left, right, false)
432
+ | NewTok - MemberExpression:expr - Arguments:arguments ~new_expression(expr, arguments)
433
+ | PrimaryExpression
434
+ | FunctionExpression
435
+
436
+ PrimaryExpression =
437
+ ThisTok ~this_expression()
438
+ | Identifier
439
+ | Literal
440
+ | ArrayLiteral
441
+ | ObjectLiteral
442
+ | "(" - Expression:expr - ")" { expr.parens = true; expr }
443
+
444
+ ArrayLiteral =
445
+ "[" - Elision?:elision - "]" ~array_expression(elision || [])
446
+ | "[" - ElementList:list - "]" ~array_expression(list)
447
+ | "[" - ElementList:list - "," - Elision?:elision - "]" ~array_expression(list + (elision || []))
448
+
449
+ ElementList =
450
+ ElementList:list - "," - Elision?:elision - AssignmentExpression:expr { list + (elision || []) + [expr] }
451
+ | Elision?:elision - AssignmentExpression:expr { (elision || []) + [expr] }
452
+
453
+ Elision =
454
+ Elision:elision - "," { elision + [nil] }
455
+ | "," { [nil] }
456
+
457
+ ObjectLiteral =
458
+ "{" SnoComment* PropertyNameAndValueList?:list - ","? - "}" ~object_expression(list || [])
459
+
460
+ PropertyNameAndValueList =
461
+ PropertyAssignment:prop (- "," SnoComment* PropertyAssignment)*:props { [prop] + props }
462
+
463
+ PropertyAssignment =
464
+ -:comments PropertyName:key - ":" - AssignmentExpression:value ~property(key, value, 'init', comments)
465
+ | PropertyGetter
466
+ | PropertySetter
467
+
468
+ PropertyGetter =
469
+ "get" - PropertyName - "(" - ")" - "{" - FunctionBody - "}"
470
+
471
+ PropertySetter =
472
+ "set" - PropertyName - "(" - PropertySetParameterList - ")" - "{" - FunctionBody - "}"
473
+
474
+ PropertyName =
475
+ IdentifierName:name ~identifier(name)
476
+ | StringLiteral
477
+ | NumericLiteral
478
+
479
+ PropertySetParameterList =
480
+ Identifier
481
+
482
+ Literal =
483
+ NullLiteral ~literal(nil)
484
+ | BooleanLiteral
485
+ | NumericLiteral:number ~literal(number)
486
+ | StringLiteral:string ~literal(string)
487
+ | RegularExpressionLiteral:regex ~literal(regex)
488
+
489
+ NullLiteral
490
+ = NullTok
491
+
492
+ BooleanLiteral
493
+ = TrueTok ~literal(true)
494
+ | FalseTok ~literal(false)
495
+
496
+ NumericLiteral = < DecimalLiteral:literal | HexIntegerLiteral:literal > !(IdentifierStart) { literal }
497
+
498
+ DecimalLiteral = < DecimalIntegerLiteral "." DecimalDigit* ExponentPart? > ~number(text)
499
+ | < "." DecimalDigit+ ExponentPart? > ~number(text)
500
+ | < DecimalIntegerLiteral ExponentPart? > ~number(text)
501
+
502
+ DecimalIntegerLiteral = < "0" | /[1-9]/ DecimalDigit* > ~number(text)
503
+
504
+ HexIntegerLiteral = < "0x" HexDigit+ > ~number(text)
505
+ | < "0X" HexDigit+ > ~number(text)
506
+
507
+ DecimalDigit = /[0-9]/
508
+
509
+ ExponentPart = /[eE]/ SignedInteger
510
+
511
+ SignedInteger = DecimalDigit+
512
+ | "+" DecimalDigit+
513
+ | "-" DecimalDigit+
514
+
515
+
516
+ DQ = "\""
517
+ SQ = "'"
518
+
519
+ StringLiteral = DQ < DoubleStringCharacter* > DQ ~string_literal(text, '"')
520
+ | SQ < SingleStringCharacter* > SQ ~string_literal(text, "'")
521
+
522
+ RS = "\\"
523
+
524
+ DoubleStringCharacter = !( DQ | RS | LineTerminator ) < SourceCharacter > { text }
525
+ | < RS EscapeSequence > { text }
526
+ | LineContinuation
527
+
528
+ SingleStringCharacter = !( SQ | RS | LineTerminator ) < SourceCharacter > { text }
529
+ | < RS EscapeSequence > { text }
530
+ | LineContinuation
531
+
532
+ LineContinuation = RS LineTerminatorSequence
533
+
534
+ EscapeSequence = CharacterEscapeSequence
535
+ | "0" !(DecimalDigit)
536
+ | HexEscapeSequence
537
+ | UnicodeEscapeSequence
538
+
539
+ CharacterEscapeSequence = SingleEscapeCharacter
540
+ | NonEscapeCharacter
541
+
542
+ SingleEscapeCharacter = /['"\bfnrtv]/
543
+
544
+ NonEscapeCharacter = !(EscapeCharacter | LineTerminator) SourceCharacter
545
+
546
+ EscapeCharacter = SingleEscapeCharacter
547
+ | DecimalDigit
548
+ | "x"
549
+ | "u"
550
+
551
+ HexEscapeSequence = "x" HexDigit HexDigit
552
+
553
+ UnicodeEscapeSequence = "u" HexDigit HexDigit HexDigit HexDigit
554
+
555
+ RegularExpressionLiteral = "/" RegularExpressionBody:body "/" RegularExpressionFlags:flags ~regexp(body, flags)
556
+
557
+ RegularExpressionBody = < RegularExpressionFirstChar RegularExpressionChar* > { text }
558
+
559
+ RegularExpressionFirstChar = !( LineTerminator | "*" | "\\" | "/" | "[" ) SourceCharacter
560
+ | RegularExpressionBackslashSequence
561
+ | RegularExpressionClass
562
+
563
+ RegularExpressionChar = !( LineTerminator | "\\" | "/" | "[" ) SourceCharacter
564
+ | RegularExpressionBackslashSequence
565
+ | RegularExpressionClass
566
+
567
+ RegularExpressionBackslashSequence = RS !(LineTerminator) SourceCharacter
568
+
569
+ RegularExpressionClass = "[" RegularExpressionClassChar* "]"
570
+
571
+ RegularExpressionClassChar = !(LineTerminator | "\\" | "]" ) SourceCharacter
572
+ | RegularExpressionBackslashSequence
573
+
574
+ RegularExpressionFlags = < IdentifierPart* > { text }
575
+