// ECMA-262 12.2 Primary Expressions public Node parsePrimaryExpression() { TokenType type; Token token; Node expr = null; Node node; if (match("(")) { isBindingElement = false; return inheritCoverGrammar(parseGroupExpression); } if (match("[")) { return inheritCoverGrammar(parseArrayInitializer); } if (match("{")) { return inheritCoverGrammar(parseObjectInitializer); } type = lookahead.type; node = new Node(); if (type == TokenType.Identifier) { if (state.sourceType == "module" && lookahead.value == "await") { tolerateUnexpectedToken(lookahead); } expr = node.finishIdentifier(lex().value); } else if (type == TokenType.StringLiteral || type == TokenType.NumericLiteral) { isAssignmentTarget = isBindingElement = false; if (strict && lookahead.octal) { tolerateUnexpectedToken(lookahead, Messages.StrictOctalLiteral); } expr = node.finishLiteral(lex()); } else if (type == TokenType.Keyword) { if (!strict && state.allowYield && matchKeyword("yield")) { return parseNonComputedProperty(); } isAssignmentTarget = isBindingElement = false; if (matchKeyword("function")) { return parseFunctionExpression(); } if (matchKeyword("this")) { lex(); return node.finishThisExpression(); } if (matchKeyword("class")) { return parseClassExpression(); } throwUnexpectedToken(lex()); } else if (type == TokenType.BooleanLiteral) { isAssignmentTarget = isBindingElement = false; token = lex(); token.value = (token.value == "true").ToString(); expr = node.finishLiteral(token); } else if (type == TokenType.NullLiteral) { isAssignmentTarget = isBindingElement = false; token = lex(); token.value = null; expr = node.finishLiteral(token); } else if (match("/") || match("/=")) { isAssignmentTarget = isBindingElement = false; index = startIndex; if (extra.tokens != null) { token = collectRegex(); } else { token = scanRegExp(); } lex(); expr = node.finishLiteral(token); } else if (type == TokenType.Template) { expr = parseTemplateLiteral(); } else { throwUnexpectedToken(lex()); } return expr; }
// ECMA-262 15.2 Modules public Node parseModuleSpecifier() { var node = new Node(); if (lookahead.type != TokenType.StringLiteral) { throwError(Messages.InvalidModuleSpecifier); } return node.finishLiteral(lex()); }
public Node parseObjectPropertyKey() { Token token; Node node = new Node(); Node expr; token = lex(); // Note: This function is called only from parseObjectProperty(), where // EOF and Punctuator tokens are already filtered out. switch (token.type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: if (strict && token.octal) { tolerateUnexpectedToken(token, Messages.StrictOctalLiteral); } return node.finishLiteral(token); case TokenType.Identifier: case TokenType.BooleanLiteral: case TokenType.NullLiteral: case TokenType.Keyword: return node.finishIdentifier(token.value); case TokenType.Punctuator: if (token.value == "[") { expr = isolateCoverGrammar(parseAssignmentExpression); expect("]"); return expr; } break; } throwUnexpectedToken(token); return null; }