private ImmutableList<String> buildIdentifierPath(IdentifierToken token) { ImmutableList.Builder<String> identifiers = ImmutableList.builder(); identifiers.add(token != null ? token.value : ""); // null if errors while parsing while (peek(TokenType.PERIOD)) { // Namespace . Identifier eat(TokenType.PERIOD); token = eatId(); if (token == null) { break; } identifiers.add(token.value); } return identifiers.build(); }
private ParseTree parseImportSpecifier() { SourcePosition start = getTreeStartLocation(); IdentifierToken importedName = eatIdOrKeywordAsId(); IdentifierToken destinationName = null; if (peekPredefinedString(PredefinedName.AS)) { eatPredefinedString(PredefinedName.AS); destinationName = eatId(); } else if (isKeyword(importedName.value)) { reportExpectedError(null, PredefinedName.AS); } return new ImportSpecifierTree( getTreeLocation(start), importedName, destinationName); }
private ImmutableList<String> buildIdentifierPath(IdentifierToken token) { ImmutableList.Builder<String> identifiers = ImmutableList.builder(); identifiers.add(token != null ? token.value : ""); // null if errors while parsing while (peek(TokenType.PERIOD)) { // Namespace . Identifier eat(TokenType.PERIOD); token = eatId(); if (token == null) { break; } identifiers.add(token.value); } return identifiers.build(); }
private Token eatPredefinedString(String string) { Token token = eatId(); if (token == null || !token.asIdentifier().value.equals(string)) { reportExpectedError(token, string); return null; } return token; }
private Token eatPredefinedString(String string) { Token token = eatId(); if (token == null || !token.asIdentifier().value.equals(string)) { reportExpectedError(token, string); return null; } return token; }
private IdentifierExpressionTree parseIdentifierExpression() { SourcePosition start = getTreeStartLocation(); IdentifierToken identifier = eatId(); return new IdentifierExpressionTree(getTreeLocation(start), identifier); }
private IdentifierExpressionTree parseIdentifierExpression() { SourcePosition start = getTreeStartLocation(); IdentifierToken identifier = eatId(); return new IdentifierExpressionTree(getTreeLocation(start), identifier); }
private ParseTree parseAmbientFunctionDeclaration() { SourcePosition start = getTreeStartLocation(); eat(Keywords.FUNCTION.type); boolean isGenerator = eatOpt(TokenType.STAR) != null; IdentifierToken name = eatId(); return parseAmbientFunctionDeclaration(start, name, isGenerator); }
private ParseTree parseFunctionDeclaration() { SourcePosition start = getTreeStartLocation(); eat(Keywords.FUNCTION.type); boolean isGenerator = eatOpt(TokenType.STAR) != null; IdentifierToken name = eatId(); return parseFunctionTail( start, name, false, isGenerator, null, FunctionDeclarationTree.Kind.DECLARATION); }
private NamespaceNameTree parseNamespaceName() { SourcePosition start = getTreeStartLocation(); IdentifierToken token = eatId(); return new NamespaceNameTree(getTreeLocation(start), buildIdentifierPath(token)); }
private NamespaceNameTree parseNamespaceName() { SourcePosition start = getTreeStartLocation(); IdentifierToken token = eatId(); return new NamespaceNameTree(getTreeLocation(start), buildIdentifierPath(token)); }
private ParseTree parseAmbientFunctionDeclaration() { SourcePosition start = getTreeStartLocation(); eat(Keywords.FUNCTION.type); boolean isGenerator = eatOpt(TokenType.STAR) != null; IdentifierToken name = eatId(); return parseAmbientFunctionDeclaration(start, name, isGenerator); }
private ParseTree parseLabelledStatement() { SourcePosition start = getTreeStartLocation(); IdentifierToken name = eatId(); eat(TokenType.COLON); return new LabelledStatementTree(getTreeLocation(start), name, parseStatement()); }
private ParseTree parseLabelledStatement() { SourcePosition start = getTreeStartLocation(); IdentifierToken name = eatId(); eat(TokenType.COLON); return new LabelledStatementTree(getTreeLocation(start), name, parseStatement()); }
private ParseTree parseEnumDeclaration() { SourcePosition start = getTreeStartLocation(); eat(TokenType.ENUM); IdentifierToken name = eatId(); eat(TokenType.OPEN_CURLY); ImmutableList<ParseTree> members = parseEnumMembers(); eat(TokenType.CLOSE_CURLY); return new EnumDeclarationTree(getTreeLocation(start), name, members); }
private ParseTree parseTypeAlias() { SourcePosition start = getTreeStartLocation(); eat(TokenType.TYPE); IdentifierToken alias = eatId(); eat(TokenType.EQUAL); ParseTree original = parseType(); eatPossibleImplicitSemiColon(); return new TypeAliasTree(getTreeLocation(start), alias, original); }
private ParseTree parseEnumDeclaration() { SourcePosition start = getTreeStartLocation(); eat(TokenType.ENUM); IdentifierToken name = eatId(); eat(TokenType.OPEN_CURLY); ImmutableList<ParseTree> members = parseEnumMembers(); eat(TokenType.CLOSE_CURLY); return new EnumDeclarationTree(getTreeLocation(start), name, members); }
private ParseTree parseTypeAlias() { SourcePosition start = getTreeStartLocation(); eat(TokenType.TYPE); IdentifierToken alias = eatId(); eat(TokenType.EQUAL); ParseTree original = parseType(); eatPossibleImplicitSemiColon(); return new TypeAliasTree(getTreeLocation(start), alias, original); }
private ParseTree parseFunctionDeclaration() { SourcePosition start = getTreeStartLocation(); eat(Keywords.FUNCTION.type); boolean isGenerator = eatOpt(TokenType.STAR) != null; FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION).setName(eatId()); parseFunctionTail(builder, isGenerator ? FunctionFlavor.GENERATOR : FunctionFlavor.NORMAL); return builder.build(getTreeLocation(start)); }
private ParseTree parseAsyncFunctionDeclaration() { SourcePosition start = getTreeStartLocation(); eatAsyncFunctionStart(); boolean generator = peek(TokenType.STAR); if (generator) { eat(TokenType.STAR); } FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION) .setName(eatId()) .setAsync(true); parseFunctionTail( builder, generator ? FunctionFlavor.ASYNCHRONOUS_GENERATOR : FunctionFlavor.ASYNCHRONOUS); return builder.build(getTreeLocation(start)); }