PageRenderTime 67ms CodeModel.GetById 12ms app.highlight 46ms RepoModel.GetById 1ms app.codeStats 0ms

/src/grammar.coffee

http://github.com/jashkenas/coffee-script
CoffeeScript | 963 lines | 678 code | 118 blank | 167 comment | 22 complexity | 27a38b3ee8e956b727f2abd4f0a90d7d MD5 | raw file
  1# The CoffeeScript parser is generated by [Jison](https://github.com/zaach/jison)
  2# from this grammar file. Jison is a bottom-up parser generator, similar in
  3# style to [Bison](http://www.gnu.org/software/bison), implemented in JavaScript.
  4# It can recognize [LALR(1), LR(0), SLR(1), and LR(1)](https://en.wikipedia.org/wiki/LR_grammar)
  5# type grammars. To create the Jison parser, we list the pattern to match
  6# on the left-hand side, and the action to take (usually the creation of syntax
  7# tree nodes) on the right. As the parser runs, it
  8# shifts tokens from our token stream, from left to right, and
  9# [attempts to match](https://en.wikipedia.org/wiki/Bottom-up_parsing)
 10# the token sequence against the rules below. When a match can be made, it
 11# reduces into the [nonterminal](https://en.wikipedia.org/wiki/Terminal_and_nonterminal_symbols)
 12# (the enclosing name at the top), and we proceed from there.
 13#
 14# If you run the `cake build:parser` command, Jison constructs a parse table
 15# from our rules and saves it into `lib/parser.js`.
 16
 17# The only dependency is on the **Jison.Parser**.
 18{Parser} = require 'jison'
 19
 20# Jison DSL
 21# ---------
 22
 23# Since we're going to be wrapped in a function by Jison in any case, if our
 24# action immediately returns a value, we can optimize by removing the function
 25# wrapper and just returning the value directly.
 26unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/
 27
 28# Our handy DSL for Jison grammar generation, thanks to
 29# [Tim Caswell](https://github.com/creationix). For every rule in the grammar,
 30# we pass the pattern-defining string, the action to run, and extra options,
 31# optionally. If no action is specified, we simply pass the value of the
 32# previous nonterminal.
 33o = (patternString, action, options) ->
 34  patternString = patternString.replace /\s{2,}/g, ' '
 35  patternCount = patternString.split(' ').length
 36  if action
 37    action = if match = unwrap.exec action then match[1] else "(#{action}())"
 38
 39    # All runtime functions we need are defined on `yy`
 40    action = action.replace /\bnew /g, '$&yy.'
 41    action = action.replace /\b(?:Block\.wrap|extend)\b/g, 'yy.$&'
 42
 43    # Returns strings of functions to add to `parser.js` which add extra data
 44    # that nodes may have, such as comments or location data. Location data
 45    # is added to the first parameter passed in, and the parameter is returned.
 46    # If the parameter is not a node, it will just be passed through unaffected.
 47    getAddDataToNodeFunctionString = (first, last, forceUpdateLocation = yes) ->
 48      "yy.addDataToNode(yy, @#{first}, #{if first[0] is '$' then '$$' else '$'}#{first}, #{if last then "@#{last}, #{if last[0] is '$' then '$$' else '$'}#{last}" else 'null, null'}, #{if forceUpdateLocation then 'true' else 'false'})"
 49
 50    returnsLoc = /^LOC/.test action
 51    action = action.replace /LOC\(([0-9]*)\)/g, getAddDataToNodeFunctionString('$1')
 52    action = action.replace /LOC\(([0-9]*),\s*([0-9]*)\)/g, getAddDataToNodeFunctionString('$1', '$2')
 53    performActionFunctionString = "$$ = #{getAddDataToNodeFunctionString(1, patternCount, not returnsLoc)}(#{action});"
 54  else
 55    performActionFunctionString = '$$ = $1;'
 56
 57  [patternString, performActionFunctionString, options]
 58
 59# Grammatical Rules
 60# -----------------
 61
 62# In all of the rules that follow, you'll see the name of the nonterminal as
 63# the key to a list of alternative matches. With each match's action, the
 64# dollar-sign variables are provided by Jison as references to the value of
 65# their numeric position, so in this rule:
 66#
 67#     'Expression UNLESS Expression'
 68#
 69# `$1` would be the value of the first `Expression`, `$2` would be the token
 70# for the `UNLESS` terminal, and `$3` would be the value of the second
 71# `Expression`.
 72grammar =
 73
 74  # The **Root** is the top-level node in the syntax tree. Since we parse bottom-up,
 75  # all parsing must end here.
 76  Root: [
 77    o '',                                       -> new Root new Block
 78    o 'Body',                                   -> new Root $1
 79  ]
 80
 81  # Any list of statements and expressions, separated by line breaks or semicolons.
 82  Body: [
 83    o 'Line',                                   -> Block.wrap [$1]
 84    o 'Body TERMINATOR Line',                   -> $1.push $3
 85    o 'Body TERMINATOR'
 86  ]
 87
 88  # Block and statements, which make up a line in a body. YieldReturn is a
 89  # statement, but not included in Statement because that results in an ambiguous
 90  # grammar.
 91  Line: [
 92    o 'Expression'
 93    o 'ExpressionLine'
 94    o 'Statement'
 95    o 'FuncDirective'
 96  ]
 97
 98  FuncDirective: [
 99    o 'YieldReturn'
100    o 'AwaitReturn'
101  ]
102
103  # Pure statements which cannot be expressions.
104  Statement: [
105    o 'Return'
106    o 'STATEMENT',                              -> new StatementLiteral $1
107    o 'Import'
108    o 'Export'
109  ]
110
111  # All the different types of expressions in our language. The basic unit of
112  # CoffeeScript is the **Expression** -- everything that can be an expression
113  # is one. Blocks serve as the building blocks of many other rules, making
114  # them somewhat circular.
115  Expression: [
116    o 'Value'
117    o 'Code'
118    o 'Operation'
119    o 'Assign'
120    o 'If'
121    o 'Try'
122    o 'While'
123    o 'For'
124    o 'Switch'
125    o 'Class'
126    o 'Throw'
127    o 'Yield'
128  ]
129
130  # Expressions which are written in single line and would otherwise require being
131  # wrapped in braces: E.g `a = b if do -> f a is 1`, `if f (a) -> a*2 then ...`,
132  # `for x in do (obj) -> f obj when x > 8 then f x`
133  ExpressionLine: [
134    o 'CodeLine'
135    o 'IfLine'
136    o 'OperationLine'
137  ]
138
139  Yield: [
140    o 'YIELD',                                  -> new Op $1, new Value new Literal ''
141    o 'YIELD Expression',                       -> new Op $1, $2
142    o 'YIELD INDENT Object OUTDENT',            -> new Op $1, $3
143    o 'YIELD FROM Expression',                  -> new Op $1.concat($2), $3
144  ]
145
146  # An indented block of expressions. Note that the [Rewriter](rewriter.html)
147  # will convert some postfix forms into blocks for us, by adjusting the
148  # token stream.
149  Block: [
150    o 'INDENT OUTDENT',                         -> new Block
151    o 'INDENT Body OUTDENT',                    -> $2
152  ]
153
154  Identifier: [
155    o 'IDENTIFIER',                             -> new IdentifierLiteral $1
156    o 'JSX_TAG',                                -> new JSXTag $1.toString(),
157                                                     tagNameLocationData:                  $1.tagNameToken[2]
158                                                     closingTagOpeningBracketLocationData: $1.closingTagOpeningBracketToken?[2]
159                                                     closingTagSlashLocationData:          $1.closingTagSlashToken?[2]
160                                                     closingTagNameLocationData:           $1.closingTagNameToken?[2]
161                                                     closingTagClosingBracketLocationData: $1.closingTagClosingBracketToken?[2]
162  ]
163
164  Property: [
165    o 'PROPERTY',                               -> new PropertyName $1.toString()
166  ]
167
168  # Alphanumerics are separated from the other **Literal** matchers because
169  # they can also serve as keys in object literals.
170  AlphaNumeric: [
171    o 'NUMBER',                                 -> new NumberLiteral $1.toString(), parsedValue: $1.parsedValue
172    o 'String'
173  ]
174
175  String: [
176    o 'STRING', ->
177      new StringLiteral(
178        $1.slice 1, -1 # strip artificial quotes and unwrap to primitive string
179        quote:        $1.quote
180        initialChunk: $1.initialChunk
181        finalChunk:   $1.finalChunk
182        indent:       $1.indent
183        double:       $1.double
184        heregex:      $1.heregex
185      )
186    o 'STRING_START Interpolations STRING_END', -> new StringWithInterpolations Block.wrap($2), quote: $1.quote, startQuote: LOC(1)(new Literal $1.toString())
187  ]
188
189  Interpolations: [
190    o 'InterpolationChunk',                     -> [$1]
191    o 'Interpolations InterpolationChunk',      -> $1.concat $2
192  ]
193
194  InterpolationChunk: [
195    o 'INTERPOLATION_START Body INTERPOLATION_END',                -> new Interpolation $2
196    o 'INTERPOLATION_START INDENT Body OUTDENT INTERPOLATION_END', -> new Interpolation $3
197    o 'INTERPOLATION_START INTERPOLATION_END',                     -> new Interpolation
198    o 'String',                                                    -> $1
199  ]
200
201  # The .toString() calls here and elsewhere are to convert `String` objects
202  # back to primitive strings now that we've retrieved stowaway extra properties
203  Regex: [
204    o 'REGEX',                                  -> new RegexLiteral $1.toString(), delimiter: $1.delimiter, heregexCommentTokens: $1.heregexCommentTokens
205    o 'REGEX_START Invocation REGEX_END',       -> new RegexWithInterpolations $2, heregexCommentTokens: $3.heregexCommentTokens
206  ]
207
208  # All of our immediate values. Generally these can be passed straight
209  # through and printed to JavaScript.
210  Literal: [
211    o 'AlphaNumeric'
212    o 'JS',                                     -> new PassthroughLiteral $1.toString(), here: $1.here, generated: $1.generated
213    o 'Regex'
214    o 'UNDEFINED',                              -> new UndefinedLiteral $1
215    o 'NULL',                                   -> new NullLiteral $1
216    o 'BOOL',                                   -> new BooleanLiteral $1.toString(), originalValue: $1.original
217    o 'INFINITY',                               -> new InfinityLiteral $1.toString(), originalValue: $1.original
218    o 'NAN',                                    -> new NaNLiteral $1
219  ]
220
221  # Assignment of a variable, property, or index to a value.
222  Assign: [
223    o 'Assignable = Expression',                -> new Assign $1, $3
224    o 'Assignable = TERMINATOR Expression',     -> new Assign $1, $4
225    o 'Assignable = INDENT Expression OUTDENT', -> new Assign $1, $4
226  ]
227
228  # Assignment when it happens within an object literal. The difference from
229  # the ordinary **Assign** is that these allow numbers and strings as keys.
230  AssignObj: [
231    o 'ObjAssignable',                          -> new Value $1
232    o 'ObjRestValue'
233    o 'ObjAssignable : Expression',             -> new Assign LOC(1)(new Value $1), $3, 'object',
234                                                              operatorToken: LOC(2)(new Literal $2)
235    o 'ObjAssignable :
236       INDENT Expression OUTDENT',              -> new Assign LOC(1)(new Value $1), $4, 'object',
237                                                              operatorToken: LOC(2)(new Literal $2)
238    o 'SimpleObjAssignable = Expression',       -> new Assign LOC(1)(new Value $1), $3, null,
239                                                              operatorToken: LOC(2)(new Literal $2)
240    o 'SimpleObjAssignable =
241       INDENT Expression OUTDENT',              -> new Assign LOC(1)(new Value $1), $4, null,
242                                                              operatorToken: LOC(2)(new Literal $2)
243  ]
244
245  SimpleObjAssignable: [
246    o 'Identifier'
247    o 'Property'
248    o 'ThisProperty'
249  ]
250
251  ObjAssignable: [
252    o 'SimpleObjAssignable'
253    o '[ Expression ]',          -> new Value new ComputedPropertyName $2
254    o '@ [ Expression ]',        -> new Value LOC(1)(new ThisLiteral $1), [LOC(3)(new ComputedPropertyName($3))], 'this'
255    o 'AlphaNumeric'
256  ]
257
258  # Object literal spread properties.
259  ObjRestValue: [
260    o 'SimpleObjAssignable ...', -> new Splat new Value $1
261    o '... SimpleObjAssignable', -> new Splat new Value($2), postfix: no
262    o 'ObjSpreadExpr ...',       -> new Splat $1
263    o '... ObjSpreadExpr',       -> new Splat $2, postfix: no
264  ]
265
266  ObjSpreadExpr: [
267    o 'ObjSpreadIdentifier'
268    o 'Object'
269    o 'Parenthetical'
270    o 'Super'
271    o 'This'
272    o 'SUPER OptFuncExist Arguments',               -> new SuperCall LOC(1)(new Super), $3, $2.soak, $1
273    o 'DYNAMIC_IMPORT Arguments',                   -> new DynamicImportCall LOC(1)(new DynamicImport), $2
274    o 'SimpleObjAssignable OptFuncExist Arguments', -> new Call (new Value $1), $3, $2.soak
275    o 'ObjSpreadExpr OptFuncExist Arguments',       -> new Call $1, $3, $2.soak
276  ]
277
278  ObjSpreadIdentifier: [
279    o 'SimpleObjAssignable Accessor', -> (new Value $1).add $2
280    o 'ObjSpreadExpr Accessor',       -> (new Value $1).add $2
281  ]
282
283  # A return statement from a function body.
284  Return: [
285    o 'RETURN Expression',                      -> new Return $2
286    o 'RETURN INDENT Object OUTDENT',           -> new Return new Value $3
287    o 'RETURN',                                 -> new Return
288  ]
289
290  YieldReturn: [
291    o 'YIELD RETURN Expression',                -> new YieldReturn $3,   returnKeyword: LOC(2)(new Literal $2)
292    o 'YIELD RETURN',                           -> new YieldReturn null, returnKeyword: LOC(2)(new Literal $2)
293  ]
294
295  AwaitReturn: [
296    o 'AWAIT RETURN Expression',                -> new AwaitReturn $3,   returnKeyword: LOC(2)(new Literal $2)
297    o 'AWAIT RETURN',                           -> new AwaitReturn null, returnKeyword: LOC(2)(new Literal $2)
298  ]
299
300  # The **Code** node is the function literal. It's defined by an indented block
301  # of **Block** preceded by a function arrow, with an optional parameter list.
302  Code: [
303    o 'PARAM_START ParamList PARAM_END FuncGlyph Block', -> new Code $2, $5, $4, LOC(1)(new Literal $1)
304    o 'FuncGlyph Block',                                 -> new Code [], $2, $1
305  ]
306
307  # The Codeline is the **Code** node with **Line** instead of indented **Block**.
308  CodeLine: [
309    o 'PARAM_START ParamList PARAM_END FuncGlyph Line', -> new Code $2, LOC(5)(Block.wrap [$5]), $4,
310                                                              LOC(1)(new Literal $1)
311    o 'FuncGlyph Line',                                 -> new Code [], LOC(2)(Block.wrap [$2]), $1
312  ]
313
314  # CoffeeScript has two different symbols for functions. `->` is for ordinary
315  # functions, and `=>` is for functions bound to the current value of *this*.
316  FuncGlyph: [
317    o '->',                                     -> new FuncGlyph $1
318    o '=>',                                     -> new FuncGlyph $1
319  ]
320
321  # An optional, trailing comma.
322  OptComma: [
323    o ''
324    o ','
325  ]
326
327  # The list of parameters that a function accepts can be of any length.
328  ParamList: [
329    o '',                                       -> []
330    o 'Param',                                  -> [$1]
331    o 'ParamList , Param',                      -> $1.concat $3
332    o 'ParamList OptComma TERMINATOR Param',    -> $1.concat $4
333    o 'ParamList OptComma INDENT ParamList OptComma OUTDENT', -> $1.concat $4
334  ]
335
336  # A single parameter in a function definition can be ordinary, or a splat
337  # that hoovers up the remaining arguments.
338  Param: [
339    o 'ParamVar',                               -> new Param $1
340    o 'ParamVar ...',                           -> new Param $1, null, on
341    o '... ParamVar',                           -> new Param $2, null, postfix: no
342    o 'ParamVar = Expression',                  -> new Param $1, $3
343    o '...',                                    -> new Expansion
344  ]
345
346  # Function Parameters
347  ParamVar: [
348    o 'Identifier'
349    o 'ThisProperty'
350    o 'Array'
351    o 'Object'
352  ]
353
354  # A splat that occurs outside of a parameter list.
355  Splat: [
356    o 'Expression ...',                         -> new Splat $1
357    o '... Expression',                         -> new Splat $2, {postfix: no}
358  ]
359
360  # Variables and properties that can be assigned to.
361  SimpleAssignable: [
362    o 'Identifier',                             -> new Value $1
363    o 'Value Accessor',                         -> $1.add $2
364    o 'Code Accessor',                          -> new Value($1).add $2
365    o 'ThisProperty'
366  ]
367
368  # Everything that can be assigned to.
369  Assignable: [
370    o 'SimpleAssignable'
371    o 'Array',                                  -> new Value $1
372    o 'Object',                                 -> new Value $1
373  ]
374
375  # The types of things that can be treated as values -- assigned to, invoked
376  # as functions, indexed into, named as a class, etc.
377  Value: [
378    o 'Assignable'
379    o 'Literal',                                -> new Value $1
380    o 'Parenthetical',                          -> new Value $1
381    o 'Range',                                  -> new Value $1
382    o 'Invocation',                             -> new Value $1
383    o 'DoIife',                                 -> new Value $1
384    o 'This'
385    o 'Super',                                  -> new Value $1
386    o 'MetaProperty',                           -> new Value $1
387  ]
388
389  # A `super`-based expression that can be used as a value.
390  Super: [
391    o 'SUPER . Property',                                      -> new Super LOC(3)(new Access $3), LOC(1)(new Literal $1)
392    o 'SUPER INDEX_START Expression INDEX_END',                -> new Super LOC(3)(new Index $3),  LOC(1)(new Literal $1)
393    o 'SUPER INDEX_START INDENT Expression OUTDENT INDEX_END', -> new Super LOC(4)(new Index $4),  LOC(1)(new Literal $1)
394  ]
395
396  # A "meta-property" access e.g. `new.target`
397  MetaProperty: [
398    o 'NEW_TARGET . Property',                  -> new MetaProperty LOC(1)(new IdentifierLiteral $1), LOC(3)(new Access $3)
399  ]
400
401  # The general group of accessors into an object, by property, by prototype
402  # or by array index or slice.
403  Accessor: [
404    o '.  Property',                            -> new Access $2
405    o '?. Property',                            -> new Access $2, soak: yes
406    o ':: Property',                            -> [LOC(1)(new Access new PropertyName('prototype'), shorthand: yes), LOC(2)(new Access $2)]
407    o '?:: Property',                           -> [LOC(1)(new Access new PropertyName('prototype'), shorthand: yes, soak: yes), LOC(2)(new Access $2)]
408    o '::',                                     -> new Access new PropertyName('prototype'), shorthand: yes
409    o '?::',                                    -> new Access new PropertyName('prototype'), shorthand: yes, soak: yes
410    o 'Index'
411  ]
412
413  # Indexing into an object or array using bracket notation.
414  Index: [
415    o 'INDEX_START IndexValue INDEX_END',                -> $2
416    o 'INDEX_START INDENT IndexValue OUTDENT INDEX_END', -> $3
417    o 'INDEX_SOAK  Index',                               -> extend $2, soak: yes
418  ]
419
420  IndexValue: [
421    o 'Expression',                             -> new Index $1
422    o 'Slice',                                  -> new Slice $1
423  ]
424
425  # In CoffeeScript, an object literal is simply a list of assignments.
426  Object: [
427    o '{ AssignList OptComma }',                -> new Obj $2, $1.generated
428  ]
429
430  # Assignment of properties within an object literal can be separated by
431  # comma, as in JavaScript, or simply by newline.
432  AssignList: [
433    o '',                                                       -> []
434    o 'AssignObj',                                              -> [$1]
435    o 'AssignList , AssignObj',                                 -> $1.concat $3
436    o 'AssignList OptComma TERMINATOR AssignObj',               -> $1.concat $4
437    o 'AssignList OptComma INDENT AssignList OptComma OUTDENT', -> $1.concat $4
438  ]
439
440  # Class definitions have optional bodies of prototype property assignments,
441  # and optional references to the superclass.
442  Class: [
443    o 'CLASS',                                           -> new Class
444    o 'CLASS Block',                                     -> new Class null, null, $2
445    o 'CLASS EXTENDS Expression',                        -> new Class null, $3
446    o 'CLASS EXTENDS Expression Block',                  -> new Class null, $3, $4
447    o 'CLASS SimpleAssignable',                          -> new Class $2
448    o 'CLASS SimpleAssignable Block',                    -> new Class $2, null, $3
449    o 'CLASS SimpleAssignable EXTENDS Expression',       -> new Class $2, $4
450    o 'CLASS SimpleAssignable EXTENDS Expression Block', -> new Class $2, $4, $5
451  ]
452
453  Import: [
454    o 'IMPORT String',                                                                -> new ImportDeclaration null, $2
455    o 'IMPORT ImportDefaultSpecifier FROM String',                                    -> new ImportDeclaration new ImportClause($2, null), $4
456    o 'IMPORT ImportNamespaceSpecifier FROM String',                                  -> new ImportDeclaration new ImportClause(null, $2), $4
457    o 'IMPORT { } FROM String',                                                       -> new ImportDeclaration new ImportClause(null, new ImportSpecifierList []), $5
458    o 'IMPORT { ImportSpecifierList OptComma } FROM String',                          -> new ImportDeclaration new ImportClause(null, new ImportSpecifierList $3), $7
459    o 'IMPORT ImportDefaultSpecifier , ImportNamespaceSpecifier FROM String',         -> new ImportDeclaration new ImportClause($2, $4), $6
460    o 'IMPORT ImportDefaultSpecifier , { ImportSpecifierList OptComma } FROM String', -> new ImportDeclaration new ImportClause($2, new ImportSpecifierList $5), $9
461  ]
462
463  ImportSpecifierList: [
464    o 'ImportSpecifier',                                                          -> [$1]
465    o 'ImportSpecifierList , ImportSpecifier',                                    -> $1.concat $3
466    o 'ImportSpecifierList OptComma TERMINATOR ImportSpecifier',                  -> $1.concat $4
467    o 'INDENT ImportSpecifierList OptComma OUTDENT',                              -> $2
468    o 'ImportSpecifierList OptComma INDENT ImportSpecifierList OptComma OUTDENT', -> $1.concat $4
469  ]
470
471  ImportSpecifier: [
472    o 'Identifier',                             -> new ImportSpecifier $1
473    o 'Identifier AS Identifier',               -> new ImportSpecifier $1, $3
474    o 'DEFAULT',                                -> new ImportSpecifier LOC(1)(new DefaultLiteral $1)
475    o 'DEFAULT AS Identifier',                  -> new ImportSpecifier LOC(1)(new DefaultLiteral($1)), $3
476  ]
477
478  ImportDefaultSpecifier: [
479    o 'Identifier',                             -> new ImportDefaultSpecifier $1
480  ]
481
482  ImportNamespaceSpecifier: [
483    o 'IMPORT_ALL AS Identifier',               -> new ImportNamespaceSpecifier new Literal($1), $3
484  ]
485
486  Export: [
487    o 'EXPORT { }',                                          -> new ExportNamedDeclaration new ExportSpecifierList []
488    o 'EXPORT { ExportSpecifierList OptComma }',             -> new ExportNamedDeclaration new ExportSpecifierList $3
489    o 'EXPORT Class',                                        -> new ExportNamedDeclaration $2
490    o 'EXPORT Identifier = Expression',                      -> new ExportNamedDeclaration LOC(2,4)(new Assign $2, $4, null,
491                                                                                                      moduleDeclaration: 'export')
492    o 'EXPORT Identifier = TERMINATOR Expression',           -> new ExportNamedDeclaration LOC(2,5)(new Assign $2, $5, null,
493                                                                                                      moduleDeclaration: 'export')
494    o 'EXPORT Identifier = INDENT Expression OUTDENT',       -> new ExportNamedDeclaration LOC(2,6)(new Assign $2, $5, null,
495                                                                                                      moduleDeclaration: 'export')
496    o 'EXPORT DEFAULT Expression',                           -> new ExportDefaultDeclaration $3
497    o 'EXPORT DEFAULT INDENT Object OUTDENT',                -> new ExportDefaultDeclaration new Value $4
498    o 'EXPORT EXPORT_ALL FROM String',                       -> new ExportAllDeclaration new Literal($2), $4
499    o 'EXPORT { } FROM String',                              -> new ExportNamedDeclaration new ExportSpecifierList([]), $5
500    o 'EXPORT { ExportSpecifierList OptComma } FROM String', -> new ExportNamedDeclaration new ExportSpecifierList($3), $7
501  ]
502
503  ExportSpecifierList: [
504    o 'ExportSpecifier',                                                          -> [$1]
505    o 'ExportSpecifierList , ExportSpecifier',                                    -> $1.concat $3
506    o 'ExportSpecifierList OptComma TERMINATOR ExportSpecifier',                  -> $1.concat $4
507    o 'INDENT ExportSpecifierList OptComma OUTDENT',                              -> $2
508    o 'ExportSpecifierList OptComma INDENT ExportSpecifierList OptComma OUTDENT', -> $1.concat $4
509  ]
510
511  ExportSpecifier: [
512    o 'Identifier',                             -> new ExportSpecifier $1
513    o 'Identifier AS Identifier',               -> new ExportSpecifier $1, $3
514    o 'Identifier AS DEFAULT',                  -> new ExportSpecifier $1, LOC(3)(new DefaultLiteral $3)
515    o 'DEFAULT',                                -> new ExportSpecifier LOC(1)(new DefaultLiteral $1)
516    o 'DEFAULT AS Identifier',                  -> new ExportSpecifier LOC(1)(new DefaultLiteral($1)), $3
517  ]
518
519  # Ordinary function invocation, or a chained series of calls.
520  Invocation: [
521    o 'Value OptFuncExist String',              -> new TaggedTemplateCall $1, $3, $2.soak
522    o 'Value OptFuncExist Arguments',           -> new Call $1, $3, $2.soak
523    o 'SUPER OptFuncExist Arguments',           -> new SuperCall LOC(1)(new Super), $3, $2.soak, $1
524    o 'DYNAMIC_IMPORT Arguments',               -> new DynamicImportCall LOC(1)(new DynamicImport), $2
525  ]
526
527  # An optional existence check on a function.
528  OptFuncExist: [
529    o '',                                       -> soak: no
530    o 'FUNC_EXIST',                             -> soak: yes
531  ]
532
533  # The list of arguments to a function call.
534  Arguments: [
535    o 'CALL_START CALL_END',                    -> []
536    o 'CALL_START ArgList OptComma CALL_END',   -> $2.implicit = $1.generated; $2
537  ]
538
539  # A reference to the *this* current object.
540  This: [
541    o 'THIS',                                   -> new Value new ThisLiteral $1
542    o '@',                                      -> new Value new ThisLiteral $1
543  ]
544
545  # A reference to a property on *this*.
546  ThisProperty: [
547    o '@ Property',                             -> new Value LOC(1)(new ThisLiteral $1), [LOC(2)(new Access($2))], 'this'
548  ]
549
550  # The array literal.
551  Array: [
552    o '[ ]',                                    -> new Arr []
553    o '[ Elisions ]',                           -> new Arr $2
554    o '[ ArgElisionList OptElisions ]',         -> new Arr [].concat $2, $3
555  ]
556
557  # Inclusive and exclusive range dots.
558  RangeDots: [
559    o '..',                                     -> exclusive: no
560    o '...',                                    -> exclusive: yes
561  ]
562
563  # The CoffeeScript range literal.
564  Range: [
565    o '[ Expression RangeDots Expression ]',      -> new Range $2, $4, if $3.exclusive then 'exclusive' else 'inclusive'
566    o '[ ExpressionLine RangeDots Expression ]',  -> new Range $2, $4, if $3.exclusive then 'exclusive' else 'inclusive'
567  ]
568
569  # Array slice literals.
570  Slice: [
571    o 'Expression RangeDots Expression',        -> new Range $1, $3, if $2.exclusive then 'exclusive' else 'inclusive'
572    o 'Expression RangeDots',                   -> new Range $1, null, if $2.exclusive then 'exclusive' else 'inclusive'
573    o 'ExpressionLine RangeDots Expression',    -> new Range $1, $3, if $2.exclusive then 'exclusive' else 'inclusive'
574    o 'ExpressionLine RangeDots',               -> new Range $1, null, if $2.exclusive then 'exclusive' else 'inclusive'
575    o 'RangeDots Expression',                   -> new Range null, $2, if $1.exclusive then 'exclusive' else 'inclusive'
576    o 'RangeDots',                              -> new Range null, null, if $1.exclusive then 'exclusive' else 'inclusive'
577  ]
578
579  # The **ArgList** is the list of objects passed into a function call
580  # (i.e. comma-separated expressions). Newlines work as well.
581  ArgList: [
582    o 'Arg',                                              -> [$1]
583    o 'ArgList , Arg',                                    -> $1.concat $3
584    o 'ArgList OptComma TERMINATOR Arg',                  -> $1.concat $4
585    o 'INDENT ArgList OptComma OUTDENT',                  -> $2
586    o 'ArgList OptComma INDENT ArgList OptComma OUTDENT', -> $1.concat $4
587  ]
588
589  # Valid arguments are Blocks or Splats.
590  Arg: [
591    o 'Expression'
592    o 'ExpressionLine'
593    o 'Splat'
594    o '...',                                     -> new Expansion
595  ]
596
597  # The **ArgElisionList** is the list of objects, contents of an array literal
598  # (i.e. comma-separated expressions and elisions). Newlines work as well.
599  ArgElisionList: [
600    o 'ArgElision'
601    o 'ArgElisionList , ArgElision',                                          -> $1.concat $3
602    o 'ArgElisionList OptComma TERMINATOR ArgElision',                        -> $1.concat $4
603    o 'INDENT ArgElisionList OptElisions OUTDENT',                            -> $2.concat $3
604    o 'ArgElisionList OptElisions INDENT ArgElisionList OptElisions OUTDENT', -> $1.concat $2, $4, $5
605  ]
606
607  ArgElision: [
608    o 'Arg',                  -> [$1]
609    o 'Elisions Arg',         -> $1.concat $2
610  ]
611
612  OptElisions: [
613    o 'OptComma',             -> []
614    o ', Elisions',           -> [].concat $2
615  ]
616
617  Elisions: [
618    o 'Elision',              -> [$1]
619    o 'Elisions Elision',     -> $1.concat $2
620  ]
621
622  Elision: [
623    o ',',                    -> new Elision
624    o 'Elision TERMINATOR',   -> $1
625  ]
626
627  # Just simple, comma-separated, required arguments (no fancy syntax). We need
628  # this to be separate from the **ArgList** for use in **Switch** blocks, where
629  # having the newlines wouldn't make sense.
630  SimpleArgs: [
631    o 'Expression'
632    o 'ExpressionLine'
633    o 'SimpleArgs , Expression',                -> [].concat $1, $3
634    o 'SimpleArgs , ExpressionLine',            -> [].concat $1, $3
635  ]
636
637  # The variants of *try/catch/finally* exception handling blocks.
638  Try: [
639    o 'TRY Block',                              -> new Try $2
640    o 'TRY Block Catch',                        -> new Try $2, $3
641    o 'TRY Block FINALLY Block',                -> new Try $2, null, $4, LOC(3)(new Literal $3)
642    o 'TRY Block Catch FINALLY Block',          -> new Try $2, $3, $5, LOC(4)(new Literal $4)
643  ]
644
645  # A catch clause names its error and runs a block of code.
646  Catch: [
647    o 'CATCH Identifier Block',                 -> new Catch $3, $2
648    o 'CATCH Object Block',                     -> new Catch $3, LOC(2)(new Value($2))
649    o 'CATCH Block',                            -> new Catch $2
650  ]
651
652  # Throw an exception object.
653  Throw: [
654    o 'THROW Expression',                       -> new Throw $2
655    o 'THROW INDENT Object OUTDENT',            -> new Throw new Value $3
656  ]
657
658  # Parenthetical expressions. Note that the **Parenthetical** is a **Value**,
659  # not an **Expression**, so if you need to use an expression in a place
660  # where only values are accepted, wrapping it in parentheses will always do
661  # the trick.
662  Parenthetical: [
663    o '( Body )',                               -> new Parens $2
664    o '( INDENT Body OUTDENT )',                -> new Parens $3
665  ]
666
667  # The condition portion of a while loop.
668  WhileLineSource: [
669    o 'WHILE ExpressionLine',                       -> new While $2
670    o 'WHILE ExpressionLine WHEN ExpressionLine',   -> new While $2, guard: $4
671    o 'UNTIL ExpressionLine',                       -> new While $2, invert: true
672    o 'UNTIL ExpressionLine WHEN ExpressionLine',   -> new While $2, invert: true, guard: $4
673  ]
674
675  WhileSource: [
676    o 'WHILE Expression',                       -> new While $2
677    o 'WHILE Expression WHEN Expression',       -> new While $2, guard: $4
678    o 'WHILE ExpressionLine WHEN Expression',   -> new While $2, guard: $4
679    o 'UNTIL Expression',                       -> new While $2, invert: true
680    o 'UNTIL Expression WHEN Expression',       -> new While $2, invert: true, guard: $4
681    o 'UNTIL ExpressionLine WHEN Expression',   -> new While $2, invert: true, guard: $4
682  ]
683
684  # The while loop can either be normal, with a block of expressions to execute,
685  # or postfix, with a single expression. There is no do..while.
686  While: [
687    o 'WhileSource Block',                      -> $1.addBody $2
688    o 'WhileLineSource Block',                  -> $1.addBody $2
689    o 'Statement  WhileSource',                 -> (Object.assign $2, postfix: yes).addBody LOC(1) Block.wrap([$1])
690    o 'Expression WhileSource',                 -> (Object.assign $2, postfix: yes).addBody LOC(1) Block.wrap([$1])
691    o 'Loop',                                   -> $1
692  ]
693
694  Loop: [
695    o 'LOOP Block',                             -> new While(LOC(1)(new BooleanLiteral 'true'), isLoop: yes).addBody $2
696    o 'LOOP Expression',                        -> new While(LOC(1)(new BooleanLiteral 'true'), isLoop: yes).addBody LOC(2) Block.wrap [$2]
697  ]
698
699  # Array, object, and range comprehensions, at the most generic level.
700  # Comprehensions can either be normal, with a block of expressions to execute,
701  # or postfix, with a single expression.
702  For: [
703    o 'Statement    ForBody',  -> $2.postfix = yes; $2.addBody $1
704    o 'Expression   ForBody',  -> $2.postfix = yes; $2.addBody $1
705    o 'ForBody      Block',    -> $1.addBody $2
706    o 'ForLineBody  Block',    -> $1.addBody $2
707  ]
708
709  ForBody: [
710    o 'FOR Range',                -> new For [], source: (LOC(2) new Value($2))
711    o 'FOR Range BY Expression',  -> new For [], source: (LOC(2) new Value($2)), step: $4
712    o 'ForStart ForSource',       -> $1.addSource $2
713  ]
714
715  ForLineBody: [
716    o 'FOR Range BY ExpressionLine',  -> new For [], source: (LOC(2) new Value($2)), step: $4
717    o 'ForStart ForLineSource',       -> $1.addSource $2
718  ]
719
720  ForStart: [
721    o 'FOR ForVariables',        -> new For [], name: $2[0], index: $2[1]
722    o 'FOR AWAIT ForVariables',  ->
723        [name, index] = $3
724        new For [], {name, index, await: yes, awaitTag: (LOC(2) new Literal($2))}
725    o 'FOR OWN ForVariables',    ->
726        [name, index] = $3
727        new For [], {name, index, own: yes, ownTag: (LOC(2) new Literal($2))}
728  ]
729
730  # An array of all accepted values for a variable inside the loop.
731  # This enables support for pattern matching.
732  ForValue: [
733    o 'Identifier'
734    o 'ThisProperty'
735    o 'Array',                                  -> new Value $1
736    o 'Object',                                 -> new Value $1
737  ]
738
739  # An array or range comprehension has variables for the current element
740  # and (optional) reference to the current index. Or, *key, value*, in the case
741  # of object comprehensions.
742  ForVariables: [
743    o 'ForValue',                               -> [$1]
744    o 'ForValue , ForValue',                    -> [$1, $3]
745  ]
746
747  # The source of a comprehension is an array or object with an optional guard
748  # clause. If it's an array comprehension, you can also choose to step through
749  # in fixed-size increments.
750  ForSource: [
751    o 'FORIN Expression',                                           -> source: $2
752    o 'FOROF Expression',                                           -> source: $2, object: yes
753    o 'FORIN Expression WHEN Expression',                           -> source: $2, guard: $4
754    o 'FORIN ExpressionLine WHEN Expression',                       -> source: $2, guard: $4
755    o 'FOROF Expression WHEN Expression',                           -> source: $2, guard: $4, object: yes
756    o 'FOROF ExpressionLine WHEN Expression',                       -> source: $2, guard: $4, object: yes
757    o 'FORIN Expression BY Expression',                             -> source: $2, step:  $4
758    o 'FORIN ExpressionLine BY Expression',                         -> source: $2, step:  $4
759    o 'FORIN Expression WHEN Expression BY Expression',             -> source: $2, guard: $4, step: $6
760    o 'FORIN ExpressionLine WHEN Expression BY Expression',         -> source: $2, guard: $4, step: $6
761    o 'FORIN Expression WHEN ExpressionLine BY Expression',         -> source: $2, guard: $4, step: $6
762    o 'FORIN ExpressionLine WHEN ExpressionLine BY Expression',     -> source: $2, guard: $4, step: $6
763    o 'FORIN Expression BY Expression WHEN Expression',             -> source: $2, step:  $4, guard: $6
764    o 'FORIN ExpressionLine BY Expression WHEN Expression',         -> source: $2, step:  $4, guard: $6
765    o 'FORIN Expression BY ExpressionLine WHEN Expression',         -> source: $2, step:  $4, guard: $6
766    o 'FORIN ExpressionLine BY ExpressionLine WHEN Expression',     -> source: $2, step:  $4, guard: $6
767    o 'FORFROM Expression',                                         -> source: $2, from: yes
768    o 'FORFROM Expression WHEN Expression',                         -> source: $2, guard: $4, from: yes
769    o 'FORFROM ExpressionLine WHEN Expression',                     -> source: $2, guard: $4, from: yes
770  ]
771
772  ForLineSource: [
773    o 'FORIN ExpressionLine',                                       -> source: $2
774    o 'FOROF ExpressionLine',                                       -> source: $2, object: yes
775    o 'FORIN Expression WHEN ExpressionLine',                       -> source: $2, guard: $4
776    o 'FORIN ExpressionLine WHEN ExpressionLine',                   -> source: $2, guard: $4
777    o 'FOROF Expression WHEN ExpressionLine',                       -> source: $2, guard: $4, object: yes
778    o 'FOROF ExpressionLine WHEN ExpressionLine',                   -> source: $2, guard: $4, object: yes
779    o 'FORIN Expression BY ExpressionLine',                         -> source: $2, step:  $4
780    o 'FORIN ExpressionLine BY ExpressionLine',                     -> source: $2, step:  $4
781    o 'FORIN Expression WHEN Expression BY ExpressionLine',         -> source: $2, guard: $4, step: $6
782    o 'FORIN ExpressionLine WHEN Expression BY ExpressionLine',     -> source: $2, guard: $4, step: $6
783    o 'FORIN Expression WHEN ExpressionLine BY ExpressionLine',     -> source: $2, guard: $4, step: $6
784    o 'FORIN ExpressionLine WHEN ExpressionLine BY ExpressionLine', -> source: $2, guard: $4, step: $6
785    o 'FORIN Expression BY Expression WHEN ExpressionLine',         -> source: $2, step:  $4, guard: $6
786    o 'FORIN ExpressionLine BY Expression WHEN ExpressionLine',     -> source: $2, step:  $4, guard: $6
787    o 'FORIN Expression BY ExpressionLine WHEN ExpressionLine',     -> source: $2, step:  $4, guard: $6
788    o 'FORIN ExpressionLine BY ExpressionLine WHEN ExpressionLine', -> source: $2, step:  $4, guard: $6
789    o 'FORFROM ExpressionLine',                                     -> source: $2, from: yes
790    o 'FORFROM Expression WHEN ExpressionLine',                     -> source: $2, guard: $4, from: yes
791    o 'FORFROM ExpressionLine WHEN ExpressionLine',                 -> source: $2, guard: $4, from: yes
792  ]
793
794  Switch: [
795    o 'SWITCH Expression INDENT Whens OUTDENT',                -> new Switch $2, $4
796    o 'SWITCH ExpressionLine INDENT Whens OUTDENT',            -> new Switch $2, $4
797    o 'SWITCH Expression INDENT Whens ELSE Block OUTDENT',     -> new Switch $2, $4, LOC(5,6) $6
798    o 'SWITCH ExpressionLine INDENT Whens ELSE Block OUTDENT', -> new Switch $2, $4, LOC(5,6) $6
799    o 'SWITCH INDENT Whens OUTDENT',                           -> new Switch null, $3
800    o 'SWITCH INDENT Whens ELSE Block OUTDENT',                -> new Switch null, $3, LOC(4,5) $5
801  ]
802
803  Whens: [
804    o 'When',                                   -> [$1]
805    o 'Whens When',                             -> $1.concat $2
806  ]
807
808  # An individual **When** clause, with action.
809  When: [
810    o 'LEADING_WHEN SimpleArgs Block',            -> new SwitchWhen $2, $3
811    o 'LEADING_WHEN SimpleArgs Block TERMINATOR', -> LOC(1, 3) new SwitchWhen $2, $3
812  ]
813
814  # The most basic form of *if* is a condition and an action. The following
815  # if-related rules are broken up along these lines in order to avoid
816  # ambiguity.
817  IfBlock: [
818    o 'IF Expression Block',                    -> new If $2, $3, type: $1
819    o 'IfBlock ELSE IF Expression Block',       -> $1.addElse LOC(3,5) new If $4, $5, type: $3
820  ]
821
822  # The full complement of *if* expressions, including postfix one-liner
823  # *if* and *unless*.
824  If: [
825    o 'IfBlock'
826    o 'IfBlock ELSE Block',                     -> $1.addElse $3
827    o 'Statement  POST_IF Expression',          -> new If $3, LOC(1)(Block.wrap [$1]), type: $2, postfix: true
828    o 'Expression POST_IF Expression',          -> new If $3, LOC(1)(Block.wrap [$1]), type: $2, postfix: true
829  ]
830
831  IfBlockLine: [
832    o 'IF ExpressionLine Block',                  -> new If $2, $3, type: $1
833    o 'IfBlockLine ELSE IF ExpressionLine Block', -> $1.addElse LOC(3,5) new If $4, $5, type: $3
834  ]
835
836  IfLine: [
837    o 'IfBlockLine'
838    o 'IfBlockLine ELSE Block',               -> $1.addElse $3
839    o 'Statement  POST_IF ExpressionLine',    -> new If $3, LOC(1)(Block.wrap [$1]), type: $2, postfix: true
840    o 'Expression POST_IF ExpressionLine',    -> new If $3, LOC(1)(Block.wrap [$1]), type: $2, postfix: true
841  ]
842
843  # Arithmetic and logical operators, working on one or more operands.
844  # Here they are grouped by order of precedence. The actual precedence rules
845  # are defined at the bottom of the page. It would be shorter if we could
846  # combine most of these rules into a single generic *Operand OpSymbol Operand*
847  # -type rule, but in order to make the precedence binding possible, separate
848  # rules are necessary.
849  OperationLine: [
850    o 'UNARY ExpressionLine',                   -> new Op $1, $2
851    o 'DO ExpressionLine',                      -> new Op $1, $2
852    o 'DO_IIFE CodeLine',                       -> new Op $1, $2
853  ]
854
855  Operation: [
856    o 'UNARY Expression',                       -> new Op $1.toString(), $2, undefined, undefined, originalOperator: $1.original
857    o 'DO Expression',                          -> new Op $1, $2
858    o 'UNARY_MATH Expression',                  -> new Op $1, $2
859    o '-     Expression',                      (-> new Op '-', $2), prec: 'UNARY_MATH'
860    o '+     Expression',                      (-> new Op '+', $2), prec: 'UNARY_MATH'
861
862    o 'AWAIT Expression',                       -> new Op $1, $2
863    o 'AWAIT INDENT Object OUTDENT',            -> new Op $1, $3
864
865    o '-- SimpleAssignable',                    -> new Op '--', $2
866    o '++ SimpleAssignable',                    -> new Op '++', $2
867    o 'SimpleAssignable --',                    -> new Op '--', $1, null, true
868    o 'SimpleAssignable ++',                    -> new Op '++', $1, null, true
869
870    # [The existential operator](https://coffeescript.org/#existential-operator).
871    o 'Expression ?',                           -> new Existence $1
872
873    o 'Expression +  Expression',               -> new Op '+' , $1, $3
874    o 'Expression -  Expression',               -> new Op '-' , $1, $3
875
876    o 'Expression MATH     Expression',         -> new Op $2, $1, $3
877    o 'Expression **       Expression',         -> new Op $2, $1, $3
878    o 'Expression SHIFT    Expression',         -> new Op $2, $1, $3
879    o 'Expression COMPARE  Expression',         -> new Op $2.toString(), $1, $3, undefined, originalOperator: $2.original
880    o 'Expression &        Expression',         -> new Op $2, $1, $3
881    o 'Expression ^        Expression',         -> new Op $2, $1, $3
882    o 'Expression |        Expression',         -> new Op $2, $1, $3
883    o 'Expression &&       Expression',         -> new Op $2.toString(), $1, $3, undefined, originalOperator: $2.original
884    o 'Expression ||       Expression',         -> new Op $2.toString(), $1, $3, undefined, originalOperator: $2.original
885    o 'Expression BIN?     Expression',         -> new Op $2, $1, $3
886    o 'Expression RELATION Expression',         -> new Op $2.toString(), $1, $3, undefined, invertOperator: $2.invert?.original ? $2.invert
887
888    o 'SimpleAssignable COMPOUND_ASSIGN
889       Expression',                             -> new Assign $1, $3, $2.toString(), originalContext: $2.original
890    o 'SimpleAssignable COMPOUND_ASSIGN
891       INDENT Expression OUTDENT',              -> new Assign $1, $4, $2.toString(), originalContext: $2.original
892    o 'SimpleAssignable COMPOUND_ASSIGN TERMINATOR
893       Expression',                             -> new Assign $1, $4, $2.toString(), originalContext: $2.original
894  ]
895
896  DoIife: [
897    o 'DO_IIFE Code',                           -> new Op $1 , $2
898  ]
899
900# Precedence
901# ----------
902
903# Operators at the top of this list have higher precedence than the ones lower
904# down. Following these rules is what makes `2 + 3 * 4` parse as:
905#
906#     2 + (3 * 4)
907#
908# And not:
909#
910#     (2 + 3) * 4
911operators = [
912  ['right',     'DO_IIFE']
913  ['left',      '.', '?.', '::', '?::']
914  ['left',      'CALL_START', 'CALL_END']
915  ['nonassoc',  '++', '--']
916  ['left',      '?']
917  ['right',     'UNARY', 'DO']
918  ['right',     'AWAIT']
919  ['right',     '**']
920  ['right',     'UNARY_MATH']
921  ['left',      'MATH']
922  ['left',      '+', '-']
923  ['left',      'SHIFT']
924  ['left',      'RELATION']
925  ['left',      'COMPARE']
926  ['left',      '&']
927  ['left',      '^']
928  ['left',      '|']
929  ['left',      '&&']
930  ['left',      '||']
931  ['left',      'BIN?']
932  ['nonassoc',  'INDENT', 'OUTDENT']
933  ['right',     'YIELD']
934  ['right',     '=', ':', 'COMPOUND_ASSIGN', 'RETURN', 'THROW', 'EXTENDS']
935  ['right',     'FORIN', 'FOROF', 'FORFROM', 'BY', 'WHEN']
936  ['right',     'IF', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'IMPORT', 'EXPORT', 'DYNAMIC_IMPORT']
937  ['left',      'POST_IF']
938]
939
940# Wrapping Up
941# -----------
942
943# Finally, now that we have our **grammar** and our **operators**, we can create
944# our **Jison.Parser**. We do this by processing all of our rules, recording all
945# terminals (every symbol which does not appear as the name of a rule above)
946# as "tokens".
947tokens = []
948for name, alternatives of grammar
949  grammar[name] = for alt in alternatives
950    for token in alt[0].split ' '
951      tokens.push token unless grammar[token]
952    alt[1] = "return #{alt[1]}" if name is 'Root'
953    alt
954
955# Initialize the **Parser** with our list of terminal **tokens**, our **grammar**
956# rules, and the name of the root. Reverse the operators because Jison orders
957# precedence from low to high, and we have it high to low
958# (as in [Yacc](http://dinosaur.compilertools.net/yacc/index.html)).
959exports.parser = new Parser
960  tokens      : tokens.join ' '
961  bnf         : grammar
962  operators   : operators.reverse()
963  startSymbol : 'Root'