{
var ast = module.require('./ast'); function filledArray(count, value) { var result = new Array(count), i; for (i = 0; i < count; i++) { result[i] = value; } return result; } function extractOptional(optional, index) { return optional ? optional[index] : null; } function extractList(list, index) { var result = new Array(list.length), i; for (i = 0; i < list.length; i++) { result[i] = list[i][index]; } return result; } function buildList(first, rest, index) { return [first].concat(extractList(rest, index)); } function buildTree(first, rest, builder) { var result = first, i; for (i = 0; i < rest.length; i++) { result = builder(result, rest[i]); } return result; } function buildBinaryExpression(first, rest) { return buildTree(first, rest, function(result, element) { return insertLocationData(new ast.BinaryExpression(result, element[1], element[3]), text(), line(), column()); }); } function buildLogicalExpression(first, rest) { return buildTree(first, rest, function(result, element) { return insertLocationData(new ast.LogicalExpression(result, element[1], element[3]), text(), line(), column()); }); } function buildNullCoalescingExpression(first, rest) { return buildTree(first, rest, function(result, element) { return insertLocationData(new ast.NullCoalescingExpression(result, element[3]), text(), line(), column()); }); } function optionalList(value) { return value !== null ? value : []; } function insertLocationData(node, text, line, column) { var lines = text.split("\n"); node.loc = { "start": { "line": line, "column": column - 1 }, "end": { "line": line + lines.length - 1, "column": (lines.length === 1 ? (column - 1) : 0) + lines[lines.length - 1].length } }; return node; }
}
Start
= __ program:Program __ { return program; }
/* —– A.1 Lexical Grammar —– */
SourceCharacter
= .
WhiteSpace “whitespace”
= "\t" / "\v" / "\f" / " " / "\u00A0" / "\uFEFF" / Zs
LineTerminator
= [\n\r\u2028\u2029]
LineTerminatorSequence “end of line”
= "\n" / "\r\n" / "\r" / "\u2028" / "\u2029"
Comment “comment”
= MultiLineComment / SingleLineComment
MultiLineComment
= "/*" (!"*/" SourceCharacter)* "*/"
MultiLineCommentNoLineTerminator
= "/*" (!("*/" / LineTerminator) SourceCharacter)* "*/"
SingleLineComment
= "//" (!LineTerminator SourceCharacter)*
Identifier
= !ReservedWord name:IdentifierName { return name; }
IdentifierName “identifier”
= first:IdentifierStart rest:IdentifierPart* { return insertLocationData(new ast.Identifier(first + rest.join("")), text(), line(), column()); }
IdentifierStart
= UnicodeLetter / "$" / "_" / "\\" sequence:UnicodeEscapeSequence { return sequence; }
IdentifierPart
= IdentifierStart / UnicodeCombiningMark / UnicodeDigit / UnicodeConnectorPunctuation / "\u200C" / "\u200D"
UnicodeLetter
= Lu / Ll / Lt / Lm / Lo / Nl
UnicodeCombiningMark
= Mn / Mc
UnicodeDigit
= Nd
UnicodeConnectorPunctuation
= Pc
ReservedWord
= Keyword / NullLiteral / BooleanLiteral
Keyword
= AndToken / OrToken / ReturnToken / VarToken / IfToken / ElseToken / ForToken / FnToken / NewToken / UseToken / ThisToken / SuperToken / ThrowToken / BreakToken / ContinueToken / DebuggerToken / WhileToken / UntilToken / TypeofToken / InToken / OfToken / TryToken / CatchToken / FinallyToken / InstanceofToken / SwitchToken / CaseToken / DefaultToken / FallthroughToken / NotToken / ImportToken / FromToken / AsToken / ExportToken / DeleteToken / AsyncToken / AwaitToken / GoToken / NullToken / UndefinedToken
Literal
= NullLiteral / UndefinedLiteral / BooleanLiteral / NumericLiteral / StringLiteral / RegularExpressionLiteral
NullLiteral
= NullToken { return insertLocationData(new ast.NullLiteral(), text(), line(), column()); }
UndefinedLiteral
= UndefinedToken { return insertLocationData(new ast.UndefinedLiteral(), text(), line(), column()); }
BooleanLiteral
= TrueToken { return insertLocationData(new ast.BooleanLiteral("true"), text(), line(), column()); } / FalseToken { return insertLocationData(new ast.BooleanLiteral("false"), text(), line(), column()); }
NumericLiteral “number”
= literal:HexIntegerLiteral !(IdentifierStart / DecimalDigit) { return literal; } / literal:DecimalLiteral !(IdentifierStart / DecimalDigit) { return literal; }
DecimalLiteral
= DecimalIntegerLiteral "." !"." DecimalDigit* ExponentPart? { return insertLocationData(new ast.NumberLiteral(text()), text(), line(), column()); } / "." !"." DecimalDigit+ ExponentPart? { return insertLocationData(new ast.NumberLiteral(text()), text(), line(), column()); } / DecimalIntegerLiteral ExponentPart? { return insertLocationData(new ast.NumberLiteral(text()), text(), line(), column()); }
DecimalIntegerLiteral
= "0" / NonZeroDigit DecimalDigit*
DecimalDigit
= [0-9]
NonZeroDigit
= [1-9]
ExponentPart
= ExponentIndicator SignedInteger
ExponentIndicator
= "e"i
SignedInteger
= [+-]? DecimalDigit+
HexIntegerLiteral
= "0x"i digits:$HexDigit+ { return insertLocationData(new ast.NumberLiteral(text(), 16), text(), line(), column()); }
HexDigit
= [0-9a-f]i
StringLiteral “string”
= '"' chars:DoubleStringCharacter* '"' { return insertLocationData(new ast.StringLiteral(chars, column()), text(), line(), column()); } / "'" chars:SingleStringCharacter* "'" { return insertLocationData(new ast.StringLiteral(chars, column()), text(), line(), column()); }
DoubleStringCharacter
= !('"' / "\\" / LineTerminator) SourceCharacter { return text(); } / "\\" sequence:EscapeSequence { return sequence; } / LineContinuation / LineTerminator __ { return new ast.StringLiteral.NewLine(text()); }
SingleStringCharacter
= !("'" / "\\" / LineTerminator) SourceCharacter { return text(); } / "\\" sequence:EscapeSequence { return sequence; } / LineContinuation / LineTerminator __ { return new ast.StringLiteral.NewLine(text()); }
LineContinuation
= "\\" LineTerminatorSequence { return ""; }
EscapeSequence
= ExpressionSequence / CharacterEscapeSequence / "0" !DecimalDigit { return "\0"; } / HexEscapeSequence / UnicodeEscapeSequence
CharacterEscapeSequence
= SingleEscapeCharacter / NonEscapeCharacter
SingleEscapeCharacter
= "'" / '"' / "\\" / "b" { return "\b"; } / "f" { return "\f"; } / "n" { return "\n"; } / "r" { return "\r"; } / "t" { return "\t"; } / "v" { return "\x0B"; }
NonEscapeCharacter
= !(EscapeCharacter / LineTerminator) SourceCharacter { return text(); }
EscapeCharacter
= SingleEscapeCharacter / DecimalDigit / "x" / "u"
HexEscapeSequence
= "x" digits:$(HexDigit HexDigit) { return String.fromCharCode(parseInt(digits, 16)); }
UnicodeEscapeSequence
= "u" digits:$(HexDigit HexDigit HexDigit HexDigit) { return String.fromCharCode(parseInt(digits, 16)); }
ExpressionSequence
= "(" expression:Expression ")" { return expression; }
RegularExpressionLiteral “regular expression”
= "/" pattern:$RegularExpressionBody "/" flags:$RegularExpressionFlags { return insertLocationData(new ast.RegularExpressionLiteral(pattern, flags), text(), line(), column()); }
RegularExpressionBody
= RegularExpressionFirstChar RegularExpressionChar*
RegularExpressionFirstChar
= ![*\\/[] RegularExpressionNonTerminator / RegularExpressionBackslashSequence / RegularExpressionClass
RegularExpressionChar
= ![\\/[] RegularExpressionNonTerminator / RegularExpressionBackslashSequence / RegularExpressionClass
RegularExpressionBackslashSequence
= "\\" RegularExpressionNonTerminator
RegularExpressionNonTerminator
= !LineTerminator SourceCharacter
RegularExpressionClass
= "[" RegularExpressionClassChar* "]"
RegularExpressionClassChar
= ![\]\\] RegularExpressionNonTerminator / RegularExpressionBackslashSequence
RegularExpressionFlags
= IdentifierPart*
/*
* Unicode Character Categories * * Extracted from the following Unicode Character Database file: * * http://www.unicode.org/Public/6.3.0/ucd/extracted/DerivedGeneralCategory.txt * * Unix magic used: * * grep "; $CATEGORY" DerivedGeneralCategory.txt | # Filter characters * cut -f1 -d " " | # Extract code points * grep -v '[0-9a-fA-F]\{5\}' | # Exclude non-BMP characters * sed -e 's/\.\./-/' | # Adjust formatting * sed -e 's/\([0-9a-fA-F]\{4\}\)/\\u\1/g' | # Adjust formatting * tr -d '\n' # Join lines * * ECMA-262 allows using Unicode 3.0 or later, version 6.3.0 was the latest one * at the time of writing. * * Non-BMP characters are completely ignored to avoid surrogate pair handling * (detecting surrogate pairs isn't possible with a simple character class and * other methods would degrade performance). I don't consider it a big deal as * even parsers in JavaScript engines of common browsers seem to ignore them. */
// Letter, Lowercase Ll = [u0061-u007Au00B5u00DF-u00F6u00F8-u00FFu0101u0103u0105u0107u0109u010Bu010Du010Fu0111u0113u0115u0117u0119u011Bu011Du011Fu0121u0123u0125u0127u0129u012Bu012Du012Fu0131u0133u0135u0137-u0138u013Au013Cu013Eu0140u0142u0144u0146u0148-u0149u014Bu014Du014Fu0151u0153u0155u0157u0159u015Bu015Du015Fu0161u0163u0165u0167u0169u016Bu016Du016Fu0171u0173u0175u0177u017Au017Cu017E-u0180u0183u0185u0188u018C-u018Du0192u0195u0199-u019Bu019Eu01A1u01A3u01A5u01A8u01AA-u01ABu01ADu01B0u01B4u01B6u01B9-u01BAu01BD-u01BFu01C6u01C9u01CCu01CEu01D0u01D2u01D4u01D6u01D8u01DAu01DC-u01DDu01DFu01E1u01E3u01E5u01E7u01E9u01EBu01EDu01EF-u01F0u01F3u01F5u01F9u01FBu01FDu01FFu0201u0203u0205u0207u0209u020Bu020Du020Fu0211u0213u0215u0217u0219u021Bu021Du021Fu0221u0223u0225u0227u0229u022Bu022Du022Fu0231u0233-u0239u023Cu023F-u0240u0242u0247u0249u024Bu024Du024F-u0293u0295-u02AFu0371u0373u0377u037B-u037Du0390u03AC-u03CEu03D0-u03D1u03D5-u03D7u03D9u03DBu03DDu03DFu03E1u03E3u03E5u03E7u03E9u03EBu03EDu03EF-u03F3u03F5u03F8u03FB-u03FCu0430-u045Fu0461u0463u0465u0467u0469u046Bu046Du046Fu0471u0473u0475u0477u0479u047Bu047Du047Fu0481u048Bu048Du048Fu0491u0493u0495u0497u0499u049Bu049Du049Fu04A1u04A3u04A5u04A7u04A9u04ABu04ADu04AFu04B1u04B3u04B5u04B7u04B9u04BBu04BDu04BFu04C2u04C4u04C6u04C8u04CAu04CCu04CE-u04CFu04D1u04D3u04D5u04D7u04D9u04DBu04DDu04DFu04E1u04E3u04E5u04E7u04E9u04EBu04EDu04EFu04F1u04F3u04F5u04F7u04F9u04FBu04FDu04FFu0501u0503u0505u0507u0509u050Bu050Du050Fu0511u0513u0515u0517u0519u051Bu051Du051Fu0521u0523u0525u0527u0561-u0587u1D00-u1D2Bu1D6B-u1D77u1D79-u1D9Au1E01u1E03u1E05u1E07u1E09u1E0Bu1E0Du1E0Fu1E11u1E13u1E15u1E17u1E19u1E1Bu1E1Du1E1Fu1E21u1E23u1E25u1E27u1E29u1E2Bu1E2Du1E2Fu1E31u1E33u1E35u1E37u1E39u1E3Bu1E3Du1E3Fu1E41u1E43u1E45u1E47u1E49u1E4Bu1E4Du1E4Fu1E51u1E53u1E55u1E57u1E59u1E5Bu1E5Du1E5Fu1E61u1E63u1E65u1E67u1E69u1E6Bu1E6Du1E6Fu1E71u1E73u1E75u1E77u1E79u1E7Bu1E7Du1E7Fu1E81u1E83u1E85u1E87u1E89u1E8Bu1E8Du1E8Fu1E91u1E93u1E95-u1E9Du1E9Fu1EA1u1EA3u1EA5u1EA7u1EA9u1EABu1EADu1EAFu1EB1u1EB3u1EB5u1EB7u1EB9u1EBBu1EBDu1EBFu1EC1u1EC3u1EC5u1EC7u1EC9u1ECBu1ECDu1ECFu1ED1u1ED3u1ED5u1ED7u1ED9u1EDBu1EDDu1EDFu1EE1u1EE3u1EE5u1EE7u1EE9u1EEBu1EEDu1EEFu1EF1u1EF3u1EF5u1EF7u1EF9u1EFBu1EFDu1EFF-u1F07u1F10-u1F15u1F20-u1F27u1F30-u1F37u1F40-u1F45u1F50-u1F57u1F60-u1F67u1F70-u1F7Du1F80-u1F87u1F90-u1F97u1FA0-u1FA7u1FB0-u1FB4u1FB6-u1FB7u1FBEu1FC2-u1FC4u1FC6-u1FC7u1FD0-u1FD3u1FD6-u1FD7u1FE0-u1FE7u1FF2-u1FF4u1FF6-u1FF7u210Au210E-u210Fu2113u212Fu2134u2139u213C-u213Du2146-u2149u214Eu2184u2C30-u2C5Eu2C61u2C65-u2C66u2C68u2C6Au2C6Cu2C71u2C73-u2C74u2C76-u2C7Bu2C81u2C83u2C85u2C87u2C89u2C8Bu2C8Du2C8Fu2C91u2C93u2C95u2C97u2C99u2C9Bu2C9Du2C9Fu2CA1u2CA3u2CA5u2CA7u2CA9u2CABu2CADu2CAFu2CB1u2CB3u2CB5u2CB7u2CB9u2CBBu2CBDu2CBFu2CC1u2CC3u2CC5u2CC7u2CC9u2CCBu2CCDu2CCFu2CD1u2CD3u2CD5u2CD7u2CD9u2CDBu2CDDu2CDFu2CE1u2CE3-u2CE4u2CECu2CEEu2CF3u2D00-u2D25u2D27u2D2DuA641uA643uA645uA647uA649uA64BuA64DuA64FuA651uA653uA655uA657uA659uA65BuA65DuA65FuA661uA663uA665uA667uA669uA66BuA66DuA681uA683uA685uA687uA689uA68BuA68DuA68FuA691uA693uA695uA697uA723uA725uA727uA729uA72BuA72DuA72F-uA731uA733uA735uA737uA739uA73BuA73DuA73FuA741uA743uA745uA747uA749uA74BuA74DuA74FuA751uA753uA755uA757uA759uA75BuA75DuA75FuA761uA763uA765uA767uA769uA76BuA76DuA76FuA771-uA778uA77AuA77CuA77FuA781uA783uA785uA787uA78CuA78EuA791uA793uA7A1uA7A3uA7A5uA7A7uA7A9uA7FAuFB00-uFB06uFB13-uFB17uFF41-uFF5A]
// Letter, Modifier Lm = [u02B0-u02C1u02C6-u02D1u02E0-u02E4u02ECu02EEu0374u037Au0559u0640u06E5-u06E6u07F4-u07F5u07FAu081Au0824u0828u0971u0E46u0EC6u10FCu17D7u1843u1AA7u1C78-u1C7Du1D2C-u1D6Au1D78u1D9B-u1DBFu2071u207Fu2090-u209Cu2C7C-u2C7Du2D6Fu2E2Fu3005u3031-u3035u303Bu309D-u309Eu30FC-u30FEuA015uA4F8-uA4FDuA60CuA67FuA717-uA71FuA770uA788uA7F8-uA7F9uA9CFuAA70uAADDuAAF3-uAAF4uFF70uFF9E-uFF9F]
// Letter, Other Lo = [u00AAu00BAu01BBu01C0-u01C3u0294u05D0-u05EAu05F0-u05F2u0620-u063Fu0641-u064Au066E-u066Fu0671-u06D3u06D5u06EE-u06EFu06FA-u06FCu06FFu0710u0712-u072Fu074D-u07A5u07B1u07CA-u07EAu0800-u0815u0840-u0858u08A0u08A2-u08ACu0904-u0939u093Du0950u0958-u0961u0972-u0977u0979-u097Fu0985-u098Cu098F-u0990u0993-u09A8u09AA-u09B0u09B2u09B6-u09B9u09BDu09CEu09DC-u09DDu09DF-u09E1u09F0-u09F1u0A05-u0A0Au0A0F-u0A10u0A13-u0A28u0A2A-u0A30u0A32-u0A33u0A35-u0A36u0A38-u0A39u0A59-u0A5Cu0A5Eu0A72-u0A74u0A85-u0A8Du0A8F-u0A91u0A93-u0AA8u0AAA-u0AB0u0AB2-u0AB3u0AB5-u0AB9u0ABDu0AD0u0AE0-u0AE1u0B05-u0B0Cu0B0F-u0B10u0B13-u0B28u0B2A-u0B30u0B32-u0B33u0B35-u0B39u0B3Du0B5C-u0B5Du0B5F-u0B61u0B71u0B83u0B85-u0B8Au0B8E-u0B90u0B92-u0B95u0B99-u0B9Au0B9Cu0B9E-u0B9Fu0BA3-u0BA4u0BA8-u0BAAu0BAE-u0BB9u0BD0u0C05-u0C0Cu0C0E-u0C10u0C12-u0C28u0C2A-u0C33u0C35-u0C39u0C3Du0C58-u0C59u0C60-u0C61u0C85-u0C8Cu0C8E-u0C90u0C92-u0CA8u0CAA-u0CB3u0CB5-u0CB9u0CBDu0CDEu0CE0-u0CE1u0CF1-u0CF2u0D05-u0D0Cu0D0E-u0D10u0D12-u0D3Au0D3Du0D4Eu0D60-u0D61u0D7A-u0D7Fu0D85-u0D96u0D9A-u0DB1u0DB3-u0DBBu0DBDu0DC0-u0DC6u0E01-u0E30u0E32-u0E33u0E40-u0E45u0E81-u0E82u0E84u0E87-u0E88u0E8Au0E8Du0E94-u0E97u0E99-u0E9Fu0EA1-u0EA3u0EA5u0EA7u0EAA-u0EABu0EAD-u0EB0u0EB2-u0EB3u0EBDu0EC0-u0EC4u0EDC-u0EDFu0F00u0F40-u0F47u0F49-u0F6Cu0F88-u0F8Cu1000-u102Au103Fu1050-u1055u105A-u105Du1061u1065-u1066u106E-u1070u1075-u1081u108Eu10D0-u10FAu10FD-u1248u124A-u124Du1250-u1256u1258u125A-u125Du1260-u1288u128A-u128Du1290-u12B0u12B2-u12B5u12B8-u12BEu12C0u12C2-u12C5u12C8-u12D6u12D8-u1310u1312-u1315u1318-u135Au1380-u138Fu13A0-u13F4u1401-u166Cu166F-u167Fu1681-u169Au16A0-u16EAu1700-u170Cu170E-u1711u1720-u1731u1740-u1751u1760-u176Cu176E-u1770u1780-u17B3u17DCu1820-u1842u1844-u1877u1880-u18A8u18AAu18B0-u18F5u1900-u191Cu1950-u196Du1970-u1974u1980-u19ABu19C1-u19C7u1A00-u1A16u1A20-u1A54u1B05-u1B33u1B45-u1B4Bu1B83-u1BA0u1BAE-u1BAFu1BBA-u1BE5u1C00-u1C23u1C4D-u1C4Fu1C5A-u1C77u1CE9-u1CECu1CEE-u1CF1u1CF5-u1CF6u2135-u2138u2D30-u2D67u2D80-u2D96u2DA0-u2DA6u2DA8-u2DAEu2DB0-u2DB6u2DB8-u2DBEu2DC0-u2DC6u2DC8-u2DCEu2DD0-u2DD6u2DD8-u2DDEu3006u303Cu3041-u3096u309Fu30A1-u30FAu30FFu3105-u312Du3131-u318Eu31A0-u31BAu31F0-u31FFu3400-u4DB5u4E00-u9FCCuA000-uA014uA016-uA48CuA4D0-uA4F7uA500-uA60BuA610-uA61FuA62A-uA62BuA66EuA6A0-uA6E5uA7FB-uA801uA803-uA805uA807-uA80AuA80C-uA822uA840-uA873uA882-uA8B3uA8F2-uA8F7uA8FBuA90A-uA925uA930-uA946uA960-uA97CuA984-uA9B2uAA00-uAA28uAA40-uAA42uAA44-uAA4BuAA60-uAA6FuAA71-uAA76uAA7AuAA80-uAAAFuAAB1uAAB5-uAAB6uAAB9-uAABDuAAC0uAAC2uAADB-uAADCuAAE0-uAAEAuAAF2uAB01-uAB06uAB09-uAB0EuAB11-uAB16uAB20-uAB26uAB28-uAB2EuABC0-uABE2uAC00-uD7A3uD7B0-uD7C6uD7CB-uD7FBuF900-uFA6DuFA70-uFAD9uFB1DuFB1F-uFB28uFB2A-uFB36uFB38-uFB3CuFB3EuFB40-uFB41uFB43-uFB44uFB46-uFBB1uFBD3-uFD3DuFD50-uFD8FuFD92-uFDC7uFDF0-uFDFBuFE70-uFE74uFE76-uFEFCuFF66-uFF6FuFF71-uFF9DuFFA0-uFFBEuFFC2-uFFC7uFFCA-uFFCFuFFD2-uFFD7uFFDA-uFFDC]
// Letter, Titlecase Lt = [u01C5u01C8u01CBu01F2u1F88-u1F8Fu1F98-u1F9Fu1FA8-u1FAFu1FBCu1FCCu1FFC]
// Letter, Uppercase Lu = [u0041-u005Au00C0-u00D6u00D8-u00DEu0100u0102u0104u0106u0108u010Au010Cu010Eu0110u0112u0114u0116u0118u011Au011Cu011Eu0120u0122u0124u0126u0128u012Au012Cu012Eu0130u0132u0134u0136u0139u013Bu013Du013Fu0141u0143u0145u0147u014Au014Cu014Eu0150u0152u0154u0156u0158u015Au015Cu015Eu0160u0162u0164u0166u0168u016Au016Cu016Eu0170u0172u0174u0176u0178-u0179u017Bu017Du0181-u0182u0184u0186-u0187u0189-u018Bu018E-u0191u0193-u0194u0196-u0198u019C-u019Du019F-u01A0u01A2u01A4u01A6-u01A7u01A9u01ACu01AE-u01AFu01B1-u01B3u01B5u01B7-u01B8u01BCu01C4u01C7u01CAu01CDu01CFu01D1u01D3u01D5u01D7u01D9u01DBu01DEu01E0u01E2u01E4u01E6u01E8u01EAu01ECu01EEu01F1u01F4u01F6-u01F8u01FAu01FCu01FEu0200u0202u0204u0206u0208u020Au020Cu020Eu0210u0212u0214u0216u0218u021Au021Cu021Eu0220u0222u0224u0226u0228u022Au022Cu022Eu0230u0232u023A-u023Bu023D-u023Eu0241u0243-u0246u0248u024Au024Cu024Eu0370u0372u0376u0386u0388-u038Au038Cu038E-u038Fu0391-u03A1u03A3-u03ABu03CFu03D2-u03D4u03D8u03DAu03DCu03DEu03E0u03E2u03E4u03E6u03E8u03EAu03ECu03EEu03F4u03F7u03F9-u03FAu03FD-u042Fu0460u0462u0464u0466u0468u046Au046Cu046Eu0470u0472u0474u0476u0478u047Au047Cu047Eu0480u048Au048Cu048Eu0490u0492u0494u0496u0498u049Au049Cu049Eu04A0u04A2u04A4u04A6u04A8u04AAu04ACu04AEu04B0u04B2u04B4u04B6u04B8u04BAu04BCu04BEu04C0-u04C1u04C3u04C5u04C7u04C9u04CBu04CDu04D0u04D2u04D4u04D6u04D8u04DAu04DCu04DEu04E0u04E2u04E4u04E6u04E8u04EAu04ECu04EEu04F0u04F2u04F4u04F6u04F8u04FAu04FCu04FEu0500u0502u0504u0506u0508u050Au050Cu050Eu0510u0512u0514u0516u0518u051Au051Cu051Eu0520u0522u0524u0526u0531-u0556u10A0-u10C5u10C7u10CDu1E00u1E02u1E04u1E06u1E08u1E0Au1E0Cu1E0Eu1E10u1E12u1E14u1E16u1E18u1E1Au1E1Cu1E1Eu1E20u1E22u1E24u1E26u1E28u1E2Au1E2Cu1E2Eu1E30u1E32u1E34u1E36u1E38u1E3Au1E3Cu1E3Eu1E40u1E42u1E44u1E46u1E48u1E4Au1E4Cu1E4Eu1E50u1E52u1E54u1E56u1E58u1E5Au1E5Cu1E5Eu1E60u1E62u1E64u1E66u1E68u1E6Au1E6Cu1E6Eu1E70u1E72u1E74u1E76u1E78u1E7Au1E7Cu1E7Eu1E80u1E82u1E84u1E86u1E88u1E8Au1E8Cu1E8Eu1E90u1E92u1E94u1E9Eu1EA0u1EA2u1EA4u1EA6u1EA8u1EAAu1EACu1EAEu1EB0u1EB2u1EB4u1EB6u1EB8u1EBAu1EBCu1EBEu1EC0u1EC2u1EC4u1EC6u1EC8u1ECAu1ECCu1ECEu1ED0u1ED2u1ED4u1ED6u1ED8u1EDAu1EDCu1EDEu1EE0u1EE2u1EE4u1EE6u1EE8u1EEAu1EECu1EEEu1EF0u1EF2u1EF4u1EF6u1EF8u1EFAu1EFCu1EFEu1F08-u1F0Fu1F18-u1F1Du1F28-u1F2Fu1F38-u1F3Fu1F48-u1F4Du1F59u1F5Bu1F5Du1F5Fu1F68-u1F6Fu1FB8-u1FBBu1FC8-u1FCBu1FD8-u1FDBu1FE8-u1FECu1FF8-u1FFBu2102u2107u210B-u210Du2110-u2112u2115u2119-u211Du2124u2126u2128u212A-u212Du2130-u2133u213E-u213Fu2145u2183u2C00-u2C2Eu2C60u2C62-u2C64u2C67u2C69u2C6Bu2C6D-u2C70u2C72u2C75u2C7E-u2C80u2C82u2C84u2C86u2C88u2C8Au2C8Cu2C8Eu2C90u2C92u2C94u2C96u2C98u2C9Au2C9Cu2C9Eu2CA0u2CA2u2CA4u2CA6u2CA8u2CAAu2CACu2CAEu2CB0u2CB2u2CB4u2CB6u2CB8u2CBAu2CBCu2CBEu2CC0u2CC2u2CC4u2CC6u2CC8u2CCAu2CCCu2CCEu2CD0u2CD2u2CD4u2CD6u2CD8u2CDAu2CDCu2CDEu2CE0u2CE2u2CEBu2CEDu2CF2uA640uA642uA644uA646uA648uA64AuA64CuA64EuA650uA652uA654uA656uA658uA65AuA65CuA65EuA660uA662uA664uA666uA668uA66AuA66CuA680uA682uA684uA686uA688uA68AuA68CuA68EuA690uA692uA694uA696uA722uA724uA726uA728uA72AuA72CuA72EuA732uA734uA736uA738uA73AuA73CuA73EuA740uA742uA744uA746uA748uA74AuA74CuA74EuA750uA752uA754uA756uA758uA75AuA75CuA75EuA760uA762uA764uA766uA768uA76AuA76CuA76EuA779uA77BuA77D-uA77EuA780uA782uA784uA786uA78BuA78DuA790uA792uA7A0uA7A2uA7A4uA7A6uA7A8uA7AAuFF21-uFF3A]
// Mark, Spacing Combining Mc = [u0903u093Bu093E-u0940u0949-u094Cu094E-u094Fu0982-u0983u09BE-u09C0u09C7-u09C8u09CB-u09CCu09D7u0A03u0A3E-u0A40u0A83u0ABE-u0AC0u0AC9u0ACB-u0ACCu0B02-u0B03u0B3Eu0B40u0B47-u0B48u0B4B-u0B4Cu0B57u0BBE-u0BBFu0BC1-u0BC2u0BC6-u0BC8u0BCA-u0BCCu0BD7u0C01-u0C03u0C41-u0C44u0C82-u0C83u0CBEu0CC0-u0CC4u0CC7-u0CC8u0CCA-u0CCBu0CD5-u0CD6u0D02-u0D03u0D3E-u0D40u0D46-u0D48u0D4A-u0D4Cu0D57u0D82-u0D83u0DCF-u0DD1u0DD8-u0DDFu0DF2-u0DF3u0F3E-u0F3Fu0F7Fu102B-u102Cu1031u1038u103B-u103Cu1056-u1057u1062-u1064u1067-u106Du1083-u1084u1087-u108Cu108Fu109A-u109Cu17B6u17BE-u17C5u17C7-u17C8u1923-u1926u1929-u192Bu1930-u1931u1933-u1938u19B0-u19C0u19C8-u19C9u1A19-u1A1Au1A55u1A57u1A61u1A63-u1A64u1A6D-u1A72u1B04u1B35u1B3Bu1B3D-u1B41u1B43-u1B44u1B82u1BA1u1BA6-u1BA7u1BAAu1BAC-u1BADu1BE7u1BEA-u1BECu1BEEu1BF2-u1BF3u1C24-u1C2Bu1C34-u1C35u1CE1u1CF2-u1CF3u302E-u302FuA823-uA824uA827uA880-uA881uA8B4-uA8C3uA952-uA953uA983uA9B4-uA9B5uA9BA-uA9BBuA9BD-uA9C0uAA2F-uAA30uAA33-uAA34uAA4DuAA7BuAAEBuAAEE-uAAEFuAAF5uABE3-uABE4uABE6-uABE7uABE9-uABEAuABEC]
// Mark, Nonspacing Mn = [u0300-u036Fu0483-u0487u0591-u05BDu05BFu05C1-u05C2u05C4-u05C5u05C7u0610-u061Au064B-u065Fu0670u06D6-u06DCu06DF-u06E4u06E7-u06E8u06EA-u06EDu0711u0730-u074Au07A6-u07B0u07EB-u07F3u0816-u0819u081B-u0823u0825-u0827u0829-u082Du0859-u085Bu08E4-u08FEu0900-u0902u093Au093Cu0941-u0948u094Du0951-u0957u0962-u0963u0981u09BCu09C1-u09C4u09CDu09E2-u09E3u0A01-u0A02u0A3Cu0A41-u0A42u0A47-u0A48u0A4B-u0A4Du0A51u0A70-u0A71u0A75u0A81-u0A82u0ABCu0AC1-u0AC5u0AC7-u0AC8u0ACDu0AE2-u0AE3u0B01u0B3Cu0B3Fu0B41-u0B44u0B4Du0B56u0B62-u0B63u0B82u0BC0u0BCDu0C3E-u0C40u0C46-u0C48u0C4A-u0C4Du0C55-u0C56u0C62-u0C63u0CBCu0CBFu0CC6u0CCC-u0CCDu0CE2-u0CE3u0D41-u0D44u0D4Du0D62-u0D63u0DCAu0DD2-u0DD4u0DD6u0E31u0E34-u0E3Au0E47-u0E4Eu0EB1u0EB4-u0EB9u0EBB-u0EBCu0EC8-u0ECDu0F18-u0F19u0F35u0F37u0F39u0F71-u0F7Eu0F80-u0F84u0F86-u0F87u0F8D-u0F97u0F99-u0FBCu0FC6u102D-u1030u1032-u1037u1039-u103Au103D-u103Eu1058-u1059u105E-u1060u1071-u1074u1082u1085-u1086u108Du109Du135D-u135Fu1712-u1714u1732-u1734u1752-u1753u1772-u1773u17B4-u17B5u17B7-u17BDu17C6u17C9-u17D3u17DDu180B-u180Du18A9u1920-u1922u1927-u1928u1932u1939-u193Bu1A17-u1A18u1A1Bu1A56u1A58-u1A5Eu1A60u1A62u1A65-u1A6Cu1A73-u1A7Cu1A7Fu1B00-u1B03u1B34u1B36-u1B3Au1B3Cu1B42u1B6B-u1B73u1B80-u1B81u1BA2-u1BA5u1BA8-u1BA9u1BABu1BE6u1BE8-u1BE9u1BEDu1BEF-u1BF1u1C2C-u1C33u1C36-u1C37u1CD0-u1CD2u1CD4-u1CE0u1CE2-u1CE8u1CEDu1CF4u1DC0-u1DE6u1DFC-u1DFFu20D0-u20DCu20E1u20E5-u20F0u2CEF-u2CF1u2D7Fu2DE0-u2DFFu302A-u302Du3099-u309AuA66FuA674-uA67DuA69FuA6F0-uA6F1uA802uA806uA80BuA825-uA826uA8C4uA8E0-uA8F1uA926-uA92DuA947-uA951uA980-uA982uA9B3uA9B6-uA9B9uA9BCuAA29-uAA2EuAA31-uAA32uAA35-uAA36uAA43uAA4CuAAB0uAAB2-uAAB4uAAB7-uAAB8uAABE-uAABFuAAC1uAAEC-uAAEDuAAF6uABE5uABE8uABEDuFB1EuFE00-uFE0FuFE20-uFE26]
// Number, Decimal Digit Nd = [u0030-u0039u0660-u0669u06F0-u06F9u07C0-u07C9u0966-u096Fu09E6-u09EFu0A66-u0A6Fu0AE6-u0AEFu0B66-u0B6Fu0BE6-u0BEFu0C66-u0C6Fu0CE6-u0CEFu0D66-u0D6Fu0E50-u0E59u0ED0-u0ED9u0F20-u0F29u1040-u1049u1090-u1099u17E0-u17E9u1810-u1819u1946-u194Fu19D0-u19D9u1A80-u1A89u1A90-u1A99u1B50-u1B59u1BB0-u1BB9u1C40-u1C49u1C50-u1C59uA620-uA629uA8D0-uA8D9uA900-uA909uA9D0-uA9D9uAA50-uAA59uABF0-uABF9uFF10-uFF19]
// Number, Letter Nl = [u16EE-u16F0u2160-u2182u2185-u2188u3007u3021-u3029u3038-u303AuA6E6-uA6EF]
// Punctuation, Connector Pc = [u005Fu203F-u2040u2054uFE33-uFE34uFE4D-uFE4FuFF3F]
// Separator, Space Zs = [u0020u00A0u1680u2000-u200Au202Fu205Fu3000]
/* Tokens */
AndToken = “and” !IdentifierPart OrToken = “or” !IdentifierPart ReturnToken = “return” !IdentifierPart FnToken = “fn” !IdentifierPart VarToken = “var” !IdentifierPart IfToken = “if” !IdentifierPart ElseToken = “else” !IdentifierPart ForToken = “for” !IdentifierPart TrueToken = “true” !IdentifierPart FalseToken = “false” !IdentifierPart NullToken = “null” !IdentifierPart NewToken = “new” !IdentifierPart UseToken = “use” !IdentifierPart ThisToken = “this” !IdentifierPart SuperToken = “super” !IdentifierPart ThrowToken = “throw” !IdentifierPart BreakToken = “break” !IdentifierPart ContinueToken = “continue” !IdentifierPart DebuggerToken = “debugger” !IdentifierPart WhileToken = “while” !IdentifierPart UntilToken = “until” !IdentifierPart TypeofToken = “typeof” !IdentifierPart InToken = “in” !IdentifierPart OfToken = “of” !IdentifierPart TryToken = “try” !IdentifierPart FinallyToken = “finally” !IdentifierPart CatchToken = “catch” !IdentifierPart InstanceofToken = “instanceof” !IdentifierPart SwitchToken = “switch” !IdentifierPart CaseToken = “case” !IdentifierPart DefaultToken = “default” !IdentifierPart FallthroughToken = “fallthrough” !IdentifierPart NotToken = “not” !IdentifierPart ImportToken = “import” !IdentifierPart FromToken = “from” !IdentifierPart AsToken = “as” !IdentifierPart ExportToken = “export” !IdentifierPart DeleteToken = “delete” !IdentifierPart DoToken = “do” !IdentifierPart AsyncToken = “async” !IdentifierPart AwaitToken = “await” !IdentifierPart GoToken = “go” !IdentifierPart UndefinedToken = “undefined” !IdentifierPart
__
= (WhiteSpace / LineTerminatorSequence / Comment)*
_
= (WhiteSpace / MultiLineCommentNoLineTerminator)*
EOS
= __ ";"
EOF
= !.
Program
= body:StatementList? { return insertLocationData(new ast.Program(optionalList(body)), text(), line(), column()); }
StatementList
= first:Statement rest:(__ Statement)* { return buildList(first, rest, 1); }
Statement
= Block / VariableStatement / FunctionDeclaration / IfStatement / PushStatement / ExpressionStatement / ReturnStatement / ForStatement / UseStatement / ThrowStatement / TryStatement / BreakStatement / ContinueStatement / DebuggerStatement / WhileStatement / UntilStatement / SwitchStatement / FallthroughStatement / ImportDeclarationStatement / ExportDeclarationStatement / DoWhileStatement / GoStatement
Block
= "{" __ body:(StatementList __)? "}" { return insertLocationData(new ast.BlockStatement(optionalList(extractOptional(body, 0))), text(), line(), column()); }
VariableStatement
= VarToken __ declarations:VariableDeclarationList EOS { return insertLocationData(new ast.VariableDeclarationStatement(declarations), text(), line(), column()); }
VariableDeclarationList
= first:VariableDeclaration rest:(__ "," __ VariableDeclaration)* { return buildList(first, rest, 3); }
VariableDeclaration
= id:Identifier init:(__ Initialiser)? { return insertLocationData(new ast.VariableDeclarator(id, extractOptional(init, 1)), text(), line(), column()); } / id:Pattern init:(__ Initialiser)? { return insertLocationData(new ast.VariableDeclarator(id, extractOptional(init, 1)), text(), line(), column()); }
Initialiser
= "=" !"=" __ expression:AssignmentExpression { return expression; }
FunctionDeclaration
= AsyncToken __ FnToken __ id:Identifier __ "(" __ params:(FormalParameterList __)? ")" __ inheritsFrom:InheritsFrom? __ body:Block __ { return insertLocationData( new ast.VariableDeclarationStatement( [new ast.VariableDeclarator(id, new ast.UnaryExpression("async", new ast.FunctionExpression( null, optionalList(extractOptional(params, 0)), body, inheritsFrom ) ) )] ), text(), line(), column()); } / FnToken __ id:Identifier __ "(" __ params:(FormalParameterList __)? ")" __ inheritsFrom:InheritsFrom? __ body:Block __ { return insertLocationData( new ast.FunctionDeclarationStatement(id, optionalList(extractOptional(params, 0)), body, inheritsFrom), text(), line(), column()); }
InheritsFrom
= "extends" __ call:CallExpression __ { return call; }
FormalParameterList
= first:FormalParameter rest:(__ "," __ FormalParameter)* { return buildList(first, rest, 3); }
FormalParameter
= id:Identifier __ "=" __ defaultValue:Expression { return insertLocationData(new ast.Parameter(id, defaultValue, false), text(), line(), column()); } / id:Identifier __ "..." { return insertLocationData(new ast.Parameter(id, null, true), text(), line(), column()); } / id:Identifier { return insertLocationData(new ast.Parameter(id, null, false), text(), line(), column()); }
IfStatement
= IfToken __ test:Expression __ consequent:Statement __ ElseToken __ alternate:Statement { return insertLocationData(new ast.IfStatement(test, consequent, alternate), text(), line(), column()); } / IfToken __ test:Expression __ consequent:Statement { return insertLocationData(new ast.IfStatement(test, consequent, null), text(), line(), column()); }
ReturnStatement
= ReturnToken EOS { return insertLocationData(new ast.ReturnStatement(null), text(), line(), column()); } / ReturnToken _ argument:Expression EOS { return insertLocationData(new ast.ReturnStatement(argument), text(), line(), column()); }
ThrowStatement
= ThrowToken _ argument:Expression EOS { return insertLocationData(new ast.ThrowStatement(argument), text(), line(), column()); }
TryStatement
= TryToken __ block:Block __ handler:Catch __ finalizer:Finally { return insertLocationData(new ast.TryStatement(block, handler, finalizer), text(), line(), column()); } / TryToken __ block:Block __ handler:Catch { return insertLocationData(new ast.TryStatement(block, handler, null), text(), line(), column()); } / TryToken __ block:Block __ finalizer:Finally { return insertLocationData(new ast.TryStatement(block, null, finalizer), text(), line(), column()); }
Catch
= CatchToken __ param:Identifier __ body:Block { return insertLocationData(new ast.CatchClause(param, body), text(), line(), column()); }
Finally
= FinallyToken __ block:Block { return block; }
BreakStatement
= BreakToken EOS { return insertLocationData(new ast.BreakStatement(), text(), line(), column()); }
ContinueStatement
= ContinueToken EOS { return insertLocationData(new ast.ContinueStatement(), text(), line(), column()); }
FallthroughStatement
= FallthroughToken EOS { return insertLocationData(new ast.FallthroughStatement(), text(), line(), column()); }
ImportDeclarationStatement
= ImportToken __ specifiers:ImportSpecifierList __ FromToken __ source:StringLiteral EOS { return insertLocationData(new ast.ImportDeclarationStatement(specifiers, source, "named"), text(), line(), column()); } / ImportToken __ "*" __ AsToken __ id:Identifier __ FromToken __ source:StringLiteral EOS { return insertLocationData(new ast.ImportDeclarationStatement([ new ast.ImportNamespaceSpecifier(id) ], source, "named"), text(), line(), column()); } / ImportToken __ source:StringLiteral __ AsToken __ id:Identifier EOS { return insertLocationData(new ast.ImportDeclarationStatement([ new ast.ImportDefaultSpecifier(id) ], source, "default"), text(), line(), column()); }
ImportSpecifierList
= first:ImportSpecifier rest:("," __ ImportSpecifier)* { return buildList(first, rest, 2); }
ImportSpecifier
= id:Identifier __ AsToken __ alias:Identifier { return insertLocationData(new ast.ImportSpecifier(id, alias), text(), line(), column()); } / id:Identifier { return insertLocationData(new ast.ImportSpecifier(id, null), text(), line(), column()); }
ExportDeclarationStatement
= ExportToken __ specifiers:ExportSpecifierList source:(__ FromToken __ StringLiteral)? EOS { return insertLocationData(new ast.ExportDeclarationStatement(specifiers, extractOptional(source, 3), null, false), text(), line(), column()); } / ExportToken __ "*" __ FromToken __ source:StringLiteral EOS { return insertLocationData(new ast.ExportDeclarationStatement([ new ast.ExportBatchSpecifier() ], source, null, false), text(), line(), column()); } / ExportToken __ statement:VariableStatement { return insertLocationData(new ast.ExportDeclarationStatement(null, null, statement, false), text(), line(), column()); } / ExportToken __ statement:FunctionDeclaration { return insertLocationData(new ast.ExportDeclarationStatement(null, null, statement, false), text(), line(), column()); } / ExportToken __ DefaultToken __ expression:Expression EOS { return insertLocationData(new ast.ExportDeclarationStatement(null, null, expression, true), text(), line(), column()); }
ExportSpecifierList
= first:ExportSpecifier rest:("," __ ExportSpecifier)* { return buildList(first, rest, 2); }
ExportSpecifier
= id:Identifier __ AsToken __ alias:Identifier { return insertLocationData(new ast.ExportSpecifier(id, alias), text(), line(), column()); } / id:Identifier { return insertLocationData(new ast.ExportSpecifier(id, null), text(), line(), column()); }
DoWhileStatement
= DoToken __ body:Statement __ WhileToken __ test:Expression EOS { return insertLocationData(new ast.DoWhileStatement(test, body), text(), line(), column()); }
PushStatement
= left:LeftHandSideExpression __ "<-" __ right:AssignmentExpression EOS { return insertLocationData(new ast.PushStatement(left, right), text(), line(), column()); }
GoStatement
= GoToken __ body:Block EOS { return insertLocationData(new ast.GoStatement(body), text(), line(), column()); }
DebuggerStatement
= DebuggerToken EOS { return insertLocationData(new ast.DebuggerStatement(), text(), line(), column()); }
WhileStatement
= WhileToken __ test:Expression __ body:Statement { return insertLocationData(new ast.WhileStatement(test, body), text(), line(), column()); }
UntilStatement
= UntilToken __ test:Expression __ body:Statement { return insertLocationData(new ast.UntilStatement(test, body), text(), line(), column()); }
SwitchStatement
= SwitchToken __ discriminant:Expression __ "{" __ cases:CaseClauseList __ "}" { return insertLocationData(new ast.SwitchStatement(discriminant, cases), text(), line(), column()); }
CaseClauseList
= first:CaseClause rest:(__ ","? __ CaseClause)* { return buildList(first, rest, 3); }
CaseClause
= CaseToken __ tests:CaseClauseTestList __ ":" __ body:Statement { return insertLocationData(new ast.CaseClause(tests, body), text(), line(), column()); } / DefaultToken __ ":" __ body:Statement { return insertLocationData(new ast.CaseClause(null, body), text(), line(), column()); }
CaseClauseTestList
= first:CaseClauseTest rest:("," __ CaseClauseTest)* { return buildList(first, rest, 2); }
CaseClauseTest
= OptionalRange / Expression
ForStatement
= ForToken __ item:Identifier __ index:("," __ Identifier)? __ InToken __ array:Expression __ body:Statement { return insertLocationData(new ast.ForInStatement( item, extractOptional(index, 2), array, body ), text(), line(), column()); } / ForToken __ key:Identifier __ value:("," __ Identifier)? __ OfToken __ object:Expression __ body:Statement { return insertLocationData(new ast.ForOfStatement( key, extractOptional(value, 2), object, body ), text(), line(), column()); } / ForToken __ VarToken __ declarations:VariableDeclarationList __ ";" __ test:(Expression __)? ";" __ update:(!("{" __ "}") Expression __)? __ body:Statement { return insertLocationData(new ast.ForStatement( new ast.VariableDeclarationStatement(declarations), extractOptional(test, 0), extractOptional(update, 1), body ), text(), line(), column()); } / ForToken __ init:(Expression __)? ";" __ test:(Expression __)? ";" __ update:(!("{" __ "}") Expression __)? __ body:Statement { return insertLocationData(new ast.ForStatement( extractOptional(init, 0), extractOptional(test, 0), extractOptional(update, 1), body ), text(), line(), column()); }
UseStatement
= UseToken __ identifiers:UseIdentifierList EOS { return new ast.UseStatement(identifiers) }
UseIdentifierList
= first:UseIdentifier rest:(__ "," __ UseIdentifier)* { return buildList(first, rest, 3); }
UseIdentifier
= Identifier / ":" id:Identifier { return id.asPredefinedCollection(); }
ExpressionStatement
= !("{" / FnToken) expression:Expression EOS { return insertLocationData(new ast.ExpressionStatement(expression), text(), line(), column()); }
AssignmentExpression
= left:Pattern __ "=" !"=" __ right:AssignmentExpression { return insertLocationData(new ast.AssignmentExpression( left, "=", right), text(), line(), column()); } / left:ConditionalExpression assignment:(__ operator:AssignmentOperator __ right:AssignmentExpression)? { if (!assignment) { return left; } return insertLocationData(new ast.AssignmentExpression( left, extractOptional(assignment, 1), extractOptional(assignment, 3)), text(), line(), column()); }
AssignmentOperator
= "=" !"=" { return "=" } / "*=" / "/=" / "%=" / "+=" / "-=" / "<<=" / ">>=" / ">>>=" / "&=" / "^=" / "|="
ConditionalExpression
= consequent:LogicalORExpression __ condition:(IfToken __ LogicalORExpression __ ElseToken __ LogicalORExpression)? { if (condition) { var test = extractOptional(condition, 2); var alternate = extractOptional(condition, 6); return insertLocationData(new ast.ConditionalExpression(test, consequent, alternate), text(), line(), column()); } else { return consequent; } }
LogicalORExpression
= first:LogicalANDExpression rest:(__ LogicalOROperator __ LogicalANDExpression)* { return buildLogicalExpression(first, rest); }
LogicalOROperator
= "||" / OrToken { return "||"; }
LogicalANDExpression
= first:BitwiseORExpression rest:(__ LogicalANDOperator __ BitwiseORExpression)* { return buildLogicalExpression(first, rest); }
LogicalANDOperator
= "&&" / AndToken { return "&&"; }
BitwiseORExpression
= first:BitwiseXORExpression rest:(__ BitwiseOROperator __ BitwiseXORExpression)* { return buildBinaryExpression(first, rest); }
BitwiseOROperator
= $("|" ![|=])
BitwiseXORExpression
= first:BitwiseANDExpression rest:(__ BitwiseXOROperator __ BitwiseANDExpression)* { return buildBinaryExpression(first, rest); }
BitwiseXOROperator
= $("^" !"=")
BitwiseANDExpression
= first:EqualityExpression rest:(__ BitwiseANDOperator __ EqualityExpression)* { return buildBinaryExpression(first, rest); }
BitwiseANDOperator
= $("&" ![&=])
EqualityExpression
= first:RelationalExpression rest:(__ EqualityOperator __ RelationalExpression)* { return buildBinaryExpression(first, rest); }
EqualityOperator
= "==" / "!="
RelationalExpression
= first:InExpression rest:(__ RelationalOperator __ InExpression)* { return buildBinaryExpression(first, rest); }
RelationalOperator
= "<=" / ">=" / $("<" !"<") / $(">" !">") / $InstanceofToken
InExpression
= left:NullCoalescingExpression right:(__ InToken __ NullCoalescingExpression)? { if (!right) { return left; } return insertLocationData(new ast.InExpression(left, extractOptional(right, 3)), text(), line(), column()); }
NullCoalescingExpression
= first:ShiftExpression rest:(__ "??" __ ShiftExpression)* { return buildNullCoalescingExpression(first, rest); }
ShiftExpression
= first:AdditiveExpression rest:(__ ShiftOperator __ AdditiveExpression)* { return buildBinaryExpression(first, rest); }
ShiftOperator
= $("<<" !"=") / $(">>>" !"=") / $(">>" !"=")
AdditiveExpression
= first:MultiplicativeExpression rest:(__ AdditiveOperator __ MultiplicativeExpression)* { return buildBinaryExpression(first, rest); }
AdditiveOperator
= $("+" ![+=]) / $("-" ![-=])
MultiplicativeExpression
= first:ExponentiativeExpression rest:(__ MultiplicativeOperator __ UnaryExpression)* { return buildBinaryExpression(first, rest); }
MultiplicativeOperator
= $("*" ![*=]) / $("/" !"=") / $("#" !"=") / $("%" ![%=]) / $("%%" !"=")
ExponentiativeExpression
= first:UnaryExpression rest:(__ ExponentiativeOperator __ UnaryExpression)* { return buildBinaryExpression(first, rest); }
ExponentiativeOperator
= $("**" !"=")
UnaryExpression
= operator:UnaryOperator __ argument:PostfixExpression { if (operator === "++" || operator === "--") { return insertLocationData(new ast.UpdateExpression(argument, operator, true), text(), line(), column()); } else { return insertLocationData(new ast.UnaryExpression(operator, argument), text(), line(), column()); } } / PostfixExpression
UnaryOperator
= $DeleteToken / $TypeofToken / $AsyncToken / $AwaitToken / $NotToken { return "!" } / "<-" / "++" / "--" / $("+" !"=") / $("-" !"=") / "!"
PostfixExpression
= argument:ExistentialExpression _ operator:PostfixOperator? { if (operator) { return insertLocationData(new ast.UpdateExpression(argument, operator, false), text(), line(), column()); } else { return argument; } }
PostfixOperator
= "++" / "--"
ExistentialExpression
= argument:LeftHandSideExpression operator:"?"? !"?" { if (operator) { return insertLocationData(new ast.ExistentialExpression(argument), text(), line(), column()); } else { return argument; } }
LeftHandSideExpression
= CallExpression
CallExpression
= first:( callee:MemberExpression call:(__ CallExpressionOperator? __ args:Arguments)? { if (!call) { return callee; } var op = extractOptional(call, 1); if (op === "?") { return insertLocationData(new ast.NullCheckCallExpression(callee, extractOptional(call, 3)), text(), line(), column()); } else if (op === "^") { return insertLocationData(new ast.CurryCallExpression(callee, extractOptional(call, 3)), text(), line(), column()); } else { return insertLocationData(new ast.CallExpression(callee, extractOptional(call, 3)), text(), line(), column()); } } ) rest:( __ operator:CallExpressionOperator? __ args:Arguments { var type = "CallExpression"; if (operator === "?") { type = "NullCheckCallExpression"; } else if (operator === "^") { type = "CurryCallExpression"; } return { type: type, arguments: args }; } / __ "[" __ property:Expression __ "]" { return { type: "MemberExpression", property: property, computed: true }; } / __ "[" __ range:OptionalRange __ "]" { return { type: "RangeMemberExpression", range: range } } / __ nullPropagatingOperator:"?"? __ "." !"." __ property:IdentifierName { return { type: nullPropagatingOperator === "?" ? "NullPropagatingExpression" : "MemberExpression", property: property, computed: false }; } )* { return buildTree(first, rest, function(result, element) { if (element.type === "MemberExpression") { return insertLocationData(new ast.MemberExpression(result, element.property, element.computed), text(), line(), column()); } if (element.type === "NullPropagatingExpression") { return insertLocationData(new ast.NullPropagatingExpression(result, element.property, element.computed), text(), line(), column()); } else if (element.type === "CallExpression") { return insertLocationData(new ast.CallExpression(result, element.arguments), text(), line(), column()); } else if (element.type === "CurryCallExpression") { return insertLocationData(new ast.CurryCallExpression(result, element.arguments), text(), line(), column()); } else if (element.type === "NullCheckCallExpression") { return insertLocationData(new ast.NullCheckCallExpression(result, element.arguments), text(), line(), column()); } else if (element.type === "RangeMemberExpression") { return insertLocationData(new ast.RangeMemberExpression(result, element.range), text(), line(), column()); } }); }
CallExpressionOperator
= "?" / "^"
MemberExpression
= first:( FunctionExpression / NewToken __ callee:MemberExpression __ args:Arguments { return insertLocationData(new ast.NewExpression(callee, args), text(), line(), column()); } ) rest:( __ "[" __ property:Expression __ "]" { return { type: "MemberExpression", property: property, computed: true }; } / __ nullPropagatingOperator:"?"? __ "." !"." __ property:IdentifierName { return { type: nullPropagatingOperator === "?" ? "NullPropagatingExpression" : "MemberExpression", property: property, computed: false }; } / __ "[" __ range:OptionalRange __ "]" { return { type: "RangeMemberExpression", range: range } } )* { return buildTree(first, rest, function (result, element) { if (element.type === "NullPropagatingExpression") { return insertLocationData(new ast.NullPropagatingExpression(result, element.property, element.computed), text(), line(), column()); } else if (element.type === "MemberExpression") { return insertLocationData(new ast.MemberExpression(result, element.property, element.computed), text(), line(), column()); } else if (element.type === "RangeMemberExpression") { return insertLocationData(new ast.RangeMemberExpression(result, element.range), text(), line(), column()); } }); }
Arguments
= "(" __ args:(ArgumentList __)? ")" { return optionalList(extractOptional(args, 0)); }
ArgumentList
= first:Argument rest:(__ "," __ Argument)* { return buildList(first, rest, 3); }
Argument
= expression:AssignmentExpression __ "..." { return insertLocationData(new ast.SplatExpression(expression), text(), line(), column()); } / AssignmentExpression
FunctionExpression
= FnToken __ id:(Identifier __)? "(" __ params:(FormalParameterList __)? ")" __ inheritsFrom:InheritsFrom? __ body:Block __ { return insertLocationData(new ast.FunctionExpression( extractOptional(id, 0), optionalList(extractOptional(params, 0)), body, inheritsFrom ), text(), line(), column()); } / "(" __ params:(FormalParameterList __)? ")" __ operator:FunctionExpressionOperator __ body:Block __ { return insertLocationData(new ast.FunctionExpression( null, optionalList(extractOptional(params, 0)), body, null, operator ), text(), line(), column()); } / "(" __ params:(FormalParameterList __)? ")" __ operator:FunctionExpressionOperator __ body:Expression __ { return insertLocationData(new ast.FunctionExpression( null, optionalList(extractOptional(params, 0)), body, null, operator ), text(), line(), column()); } / ForInExpression
FunctionExpressionOperator
= "->" / "=>"
ForInExpression
= "[" __ expression:Expression __ ForToken __ item:Identifier __ index:("," __ Identifier __)? InToken __ array:Expression __ condition:(IfToken __ Expression __)? "]" { return insertLocationData(new ast.ForInExpression( expression, item, index ? extractOptional(index, 2) : null, array, condition ? extractOptional(condition, 2) : null ), text(), line(), column()); } / GlobalIdentifierExpression
GlobalIdentifierExpression
= "::" __ id:Identifier { return id.asGlobal(); } / PrimaryExpression
PrimaryExpression
= ThisExpression / SuperExpression / RangeExpression / Identifier / Literal / ArrayLiteral / ObjectLiteral / "(" __ expression:Expression __ ")" { return expression; }
ThisExpression
= ThisToken { return insertLocationData(new ast.ThisExpression(), text(), line(), column()); }
SuperExpression
= SuperToken { return insertLocationData(new ast.SuperExpression(), text(), line(), column()); }
RangeExpression
= "[" __ range:Range __ "]" { return range; }
Range
= from:Expression __ operator:RangeOperator __ to:Expression { return insertLocationData(new ast.Range(from, operator, to), text(), line(), column()); }
OptionalRange
= from:Expression? __ operator:RangeOperator __ to:Expression? { return insertLocationData(new ast.Range(from, operator, to), text(), line(), column()); }
RangeOperator
= ".." !"." { return ".."; } / "..."
Expression
= expression:AssignmentExpression { return expression; }
ArrayLiteral
= "[" __ elision:(Elision __)? "]" { return insertLocationData(new ast.ArrayExpression(optionalList(extractOptional(elision, 0))), text(), line(), column()); } / "[" __ elements:ElementList __ "]" { return insertLocationData(new ast.ArrayExpression(elements), text(), line(), column()); } / "[" __ elements:ElementList __ "," __ elision:(Elision __)? "]" { return insertLocationData(new ast.ArrayExpression(elements.concat(optionalList(extractOptional(elision, 0)))), text(), line(), column()); }
ElementList
= first:( elision:(Elision __)? element:AssignmentExpression { return optionalList(extractOptional(elision, 0)).concat(element); } ) rest:( __ "," __ elision:(Elision __)? element:AssignmentExpression { return optionalList(extractOptional(elision, 0)).concat(element); } )* { return Array.prototype.concat.apply(first, rest); }
ArrayPattern
= "[" __ elision:(Elision __)? "]" { return insertLocationData(new ast.ArrayPattern(optionalList(extractOptional(elision, 0))), text(), line(), column()); } / "[" __ elements:PatternElementList __ "]" { return insertLocationData(new ast.ArrayPattern(elements), text(), line(), column()); } / "[" __ elements:PatternElementList __ "," __ elision:(Elision __)? "]" { return insertLocationData(new ast.ArrayPattern(elements.concat(optionalList(extractOptional(elision, 0)))), text(), line(), column()); }
PatternElementList
= first:( elision:(Elision __)? element:PatternElement { return optionalList(extractOptional(elision, 0)).concat(element); } ) rest:( __ "," __ elision:(Elision __)? element:PatternElement { return optionalList(extractOptional(elision, 0)).concat(element); } )* { return Array.prototype.concat.apply(first, rest); }
PatternElement
= Identifier / ArrayPattern
Elision
= "," commas:(__ ",")* { return filledArray(commas.length + 1, null); }
ObjectLiteral
= "{" __ "}" { return new ast.ObjectExpression([]); } / "{" __ properties:PropertyNameAndValueList __ "}" { return insertLocationData(new ast.ObjectExpression(properties), text(), line(), column()); } / "{" __ properties:PropertyNameAndValueList __ "," __ "}" { return insertLocationData(new ast.ObjectExpression(properties), text(), line(), column()); }
PropertyNameAndValueList
= first:PropertyAssignment rest:(__ "," __ PropertyAssignment)* { return buildList(first, rest, 3); }
PropertyAssignment
= key:PropertyName __ ":" __ value:AssignmentExpression { return insertLocationData(new ast.Property(key, value, false, false), text(), line(), column()); } / key:PropertyName __ "(" __ params:(FormalParameterList __)? ")" __ body:Block __ { return insertLocationData(new ast.Property(key, new ast.FunctionExpression( null, optionalList(extractOptional(params, 0)), body, null ), false, true), text(), line(), column()); } / key:IdentifierName { return insertLocationData(new ast.Property(key, key, true, false), text(), line(), column()); }
PropertyName
= IdentifierName / StringLiteral / NumericLiteral
ObjectPattern
= "{" __ "}" { return new ast.ObjectPattern([]); } / "{" __ properties:PatternPropertyNameAndValueList __ "}" { return insertLocationData(new ast.ObjectPattern(properties), text(), line(), column()); } / "{" __ properties:PatternPropertyNameAndValueList __ "," __ "}" { return insertLocationData(new ast.ObjectPattern(properties), text(), line(), column()); }
PatternPropertyNameAndValueList
= first:PatternPropertyAssignment rest:(__ "," __ PatternPropertyAssignment)* { return buildList(first, rest, 3); }
PatternPropertyAssignment
= key:IdentifierName __ ":" __ value:IdentifierName { return insertLocationData(new ast.Property(key, value, false, false), text(), line(), column()); } / key:IdentifierName __ ":" __ value:ObjectPattern { return insertLocationData(new ast.Property(key, value, false, false), text(), line(), column()); } / key:IdentifierName { return insertLocationData(new ast.Property(key, key, true, false), text(), line(), column()); }
Pattern
= ObjectPattern / ArrayPattern