private boolean peekId() { return peekId(0); }
/** * Consumes an identifier token that is not a reserved word. * @see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" */ private IdentifierToken eatId() { if (peekId()) { return eatIdOrKeywordAsId(); } else { reportExpectedError(peekToken(), TokenType.IDENTIFIER); if (peekIdOrKeyword()) { return eatIdOrKeywordAsId(); } else { return null; } } }
private boolean peekId() { return peekId(0); }
/** * Shorthand for eatOpt(TokenType.IDENTIFIER) */ private IdentifierToken eatIdOpt() { return (peekId()) ? eatIdOrKeywordAsId() : null; }
private boolean peekLabelledStatement() { return peekId() && peek(1, TokenType.COLON); }
/** * Shorthand for eatOpt(TokenType.IDENTIFIER) */ private IdentifierToken eatIdOpt() { return (peekId()) ? eatIdOrKeywordAsId() : null; }
private boolean peekLabelledStatement() { return peekId() && peek(1, TokenType.COLON); }
private boolean peekParameter(ParamContext context) { if (peekId() || peek(TokenType.SPREAD)) { return true; } if (context != ParamContext.TYPE_EXPRESSION) { return peek(TokenType.OPEN_SQUARE) || peek(TokenType.OPEN_CURLY); } return false; }
private boolean peekParameter(ParamContext context) { if (peekId() || peek(TokenType.SPREAD)) { return true; } if (context != ParamContext.TYPE_EXPRESSION) { return peek(TokenType.OPEN_SQUARE) || peek(TokenType.OPEN_CURLY); } return false; }
/** * Consumes an identifier token that is not a reserved word. * @see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" */ private IdentifierToken eatId() { if (peekId()) { return eatIdOrKeywordAsId(); } else { reportExpectedError(peekToken(), TokenType.IDENTIFIER); return null; } }
private ImmutableList<ParseTree> parseEnumMembers() { SourceRange range = getTreeLocation(getTreeStartLocation()); IdentifierToken propertyName; ParseTree member = null; ImmutableList.Builder<ParseTree> result = ImmutableList.builder(); while (peekId()) { propertyName = parseIdentifierExpression().identifierToken; member = new PropertyNameAssignmentTree(range, propertyName, null); result.add(member); if (!peek(TokenType.CLOSE_CURLY)) { eat(TokenType.COMMA); } } return result.build(); }
private ImmutableList<ParseTree> parseEnumMembers() { SourceRange range = getTreeLocation(getTreeStartLocation()); IdentifierToken propertyName; ParseTree member = null; ImmutableList.Builder<ParseTree> result = ImmutableList.builder(); while (peekId()) { propertyName = parseIdentifierExpression().identifierToken; member = new PropertyNameAssignmentTree(range, propertyName, null); result.add(member); if (!peek(TokenType.CLOSE_CURLY)) { eat(TokenType.COMMA); } } return result.build(); }
private ParseTree parseType() { SourcePosition start = getTreeStartLocation(); if (!peekId() && !EnumSet.of(TokenType.VOID, TokenType.OPEN_PAREN, TokenType.OPEN_CURLY, TokenType.TYPEOF).contains(peekType())) { reportError("Unexpected token '%s' in type expression", peekType()); return new TypeNameTree(getTreeLocation(start), ImmutableList.of("error")); } ParseTree typeExpression = parseFunctionTypeExpression(); if (!peek(TokenType.BAR)) { return typeExpression; } ImmutableList.Builder<ParseTree> unionType = ImmutableList.builder(); unionType.add(typeExpression); do { eat(TokenType.BAR); unionType.add(parseArrayTypeExpression()); } while (peek(TokenType.BAR)); return new UnionTypeTree(getTreeLocation(start), unionType.build()); }
private ParseTree parseType() { SourcePosition start = getTreeStartLocation(); if (!peekId() && !EnumSet.of(TokenType.VOID, TokenType.OPEN_PAREN, TokenType.OPEN_CURLY, TokenType.TYPEOF).contains(peekType())) { reportError("Unexpected token '%s' in type expression", peekType()); return new TypeNameTree(getTreeLocation(start), ImmutableList.of("error")); } ParseTree typeExpression = parseFunctionTypeExpression(); if (!peek(TokenType.BAR)) { return typeExpression; } ImmutableList.Builder<ParseTree> unionType = ImmutableList.builder(); unionType.add(typeExpression); do { eat(TokenType.BAR); unionType.add(parseArrayTypeExpression()); } while (peek(TokenType.BAR)); return new UnionTypeTree(getTreeLocation(start), unionType.build()); }
private boolean isStartOfAsyncArrowFunction(ParseTree partialExpression) { if (partialExpression.type == ParseTreeType.IDENTIFIER_EXPRESSION) { final IdentifierToken identifierToken = partialExpression.asIdentifierExpression().identifierToken; // partialExpression is `async` // followed by `[no newline] bindingIdentifier [no newline] =>` return identifierToken.value.equals(ASYNC) && !peekImplicitSemiColon(0) && peekId() && !peekImplicitSemiColon(1) && peek(1, TokenType.ARROW); } else if (partialExpression.type == ParseTreeType.CALL_EXPRESSION) { final CallExpressionTree callExpression = partialExpression.asCallExpression(); ParseTree callee = callExpression.operand; ParseTree arguments = callExpression.arguments; // partialExpression is `async [no newline] (parameters)` // followed by `[no newline] =>` return callee.type == ParseTreeType.IDENTIFIER_EXPRESSION && callee.asIdentifierExpression().identifierToken.value.equals(ASYNC) && callee.location.end.line == arguments.location.start.line && !peekImplicitSemiColon() && peek(TokenType.ARROW); } else { return false; } }
private GenericTypeListTree maybeParseGenericTypes() { if (!peek(TokenType.OPEN_ANGLE)) { return null; } SourcePosition start = getTreeStartLocation(); eat(TokenType.OPEN_ANGLE); scanner.incTypeParameterLevel(); LinkedHashMap<IdentifierToken, ParseTree> types = new LinkedHashMap<>(); do { IdentifierToken name = eatId(); ParseTree bound = null; if (peek(TokenType.EXTENDS)) { eat(TokenType.EXTENDS); bound = parseType(); } types.put(name, bound); if (peek(TokenType.COMMA)) { eat(TokenType.COMMA); } } while (peekId()); eat(TokenType.CLOSE_ANGLE); scanner.decTypeParameterLevel(); return new GenericTypeListTree(getTreeLocation(start), types); }
eat(TokenType.CLASS); IdentifierToken name = null; if (!isExpression || peekId()) { name = eatId();
private GenericTypeListTree maybeParseGenericTypes() { if (!peek(TokenType.OPEN_ANGLE)) { return null; } SourcePosition start = getTreeStartLocation(); eat(TokenType.OPEN_ANGLE); scanner.incTypeParameterLevel(); LinkedHashMap<IdentifierToken, ParseTree> types = new LinkedHashMap<IdentifierToken, ParseTree>(); do { IdentifierToken name = eatId(); ParseTree bound = null; if (peek(TokenType.EXTENDS)) { eat(TokenType.EXTENDS); bound = parseType(); } types.put(name, bound); if (peek(TokenType.COMMA)) { eat(TokenType.COMMA); } } while (peekId()); eat(TokenType.CLOSE_ANGLE); scanner.decTypeParameterLevel(); return new GenericTypeListTree(getTreeLocation(start), types); }
private ParseTree parseComprehensionFor() { SourcePosition start = getTreeStartLocation(); eat(TokenType.FOR); eat(TokenType.OPEN_PAREN); ParseTree initializer; if (peekId()) { initializer = parseIdentifierExpression(); } else { initializer = parsePattern(PatternKind.ANY); } eatPredefinedString(PredefinedName.OF); ParseTree collection = parseAssignmentExpression(); eat(TokenType.CLOSE_PAREN); return new ComprehensionForTree( getTreeLocation(start), initializer, collection); }
private ParseTree parseComprehensionFor() { SourcePosition start = getTreeStartLocation(); eat(TokenType.FOR); eat(TokenType.OPEN_PAREN); ParseTree initializer; if (peekId()) { initializer = parseIdentifierExpression(); } else { initializer = parsePattern(PatternKind.ANY); } eatPredefinedString(PredefinedName.OF); ParseTree collection = parseAssignmentExpression(); eat(TokenType.CLOSE_PAREN); return new ComprehensionForTree( getTreeLocation(start), initializer, collection); }