private FunctionDeclarationTree parseFunctionTail( SourcePosition start, IdentifierToken name, boolean isStatic, boolean isGenerator, TokenType access, FunctionDeclarationTree.Kind kind) { inGeneratorContext.addLast(isGenerator); GenericTypeListTree generics = maybeParseGenericTypes(); FormalParameterListTree formalParameterList = parseFormalParameterList(ParamContext.IMPLEMENTATION); ParseTree returnType = maybeParseColonType(); BlockTree functionBody = parseFunctionBody(); FunctionDeclarationTree declaration = new FunctionDeclarationTree( getTreeLocation(start), name, generics, isStatic, isGenerator, false, access, kind, formalParameterList, returnType, functionBody); inGeneratorContext.removeLast(); return declaration; }
private CallSignatureTree parseCallSignature(boolean isNew) { SourcePosition start = getTreeStartLocation(); if (isNew) { eat(TokenType.NEW); } GenericTypeListTree generics = maybeParseGenericTypes(); FormalParameterListTree params = parseFormalParameterList(ParamContext.SIGNATURE); ParseTree returnType = maybeParseColonType(); return new CallSignatureTree(getTreeLocation(start), isNew, generics, params, returnType); }
private CallSignatureTree parseCallSignature(boolean isNew) { SourcePosition start = getTreeStartLocation(); if (isNew) { eat(TokenType.NEW); } GenericTypeListTree generics = maybeParseGenericTypes(); FormalParameterListTree params = parseFormalParameterList(ParamContext.SIGNATURE); ParseTree returnType = maybeParseColonType(); return new CallSignatureTree(getTreeLocation(start), isNew, generics, params, returnType); }
private FunctionDeclarationTree parseAmbientFunctionDeclaration(SourcePosition start, IdentifierToken name, boolean isGenerator) { GenericTypeListTree generics = maybeParseGenericTypes(); FormalParameterListTree formalParameterList = parseFormalParameterList(ParamContext.SIGNATURE); ParseTree returnType = maybeParseColonType(); ParseTree functionBody = new EmptyStatementTree(getTreeLocation(start)); FunctionDeclarationTree declaration = new FunctionDeclarationTree( getTreeLocation(start), name, generics, false, isGenerator, false, null, FunctionDeclarationTree.Kind.DECLARATION, formalParameterList, returnType, functionBody); return declaration; }
private FunctionDeclarationTree parseMethodSignature(SourcePosition start, IdentifierToken name, boolean isStatic, boolean isGenerator, boolean isOptional, TokenType access) { GenericTypeListTree generics = maybeParseGenericTypes(); FormalParameterListTree formalParameterList = parseFormalParameterList(ParamContext.SIGNATURE); ParseTree returnType = maybeParseColonType(); ParseTree functionBody = new EmptyStatementTree(getTreeLocation(start)); FunctionDeclarationTree declaration = new FunctionDeclarationTree( getTreeLocation(start), name, generics, isStatic, isGenerator, isOptional, access, FunctionDeclarationTree.Kind.MEMBER, formalParameterList, returnType, functionBody); return declaration; }
private void parseFunctionTail( FunctionDeclarationTree.Builder builder, FunctionFlavor functionFlavor) { functionContextStack.addLast(functionFlavor); builder .setGenerator(functionFlavor.isGenerator) .setGenerics(maybeParseGenericTypes()) .setFormalParameterList(parseFormalParameterList(ParamContext.IMPLEMENTATION)) .setReturnType(maybeParseColonType()) .setFunctionBody(parseFunctionBody()); functionContextStack.removeLast(); }
private ParseTree parseInterfaceDeclaration() { SourcePosition start = getTreeStartLocation(); eat(TokenType.INTERFACE); IdentifierToken name = eatId(); GenericTypeListTree generics = maybeParseGenericTypes(); ImmutableList.Builder<ParseTree> superTypes = ImmutableList.builder(); if (peek(TokenType.EXTENDS)) { eat(TokenType.EXTENDS); ParseTree type = parseType(); superTypes.add(type); while (peek(TokenType.COMMA)) { eat(TokenType.COMMA); type = parseType(); if (type != null) { superTypes.add(type); } } } eat(TokenType.OPEN_CURLY); ImmutableList<ParseTree> elements = parseInterfaceElements(); eat(TokenType.CLOSE_CURLY); return new InterfaceDeclarationTree(getTreeLocation(start), name, generics, superTypes.build(), elements); }
private ParseTree parseInterfaceDeclaration() { SourcePosition start = getTreeStartLocation(); eat(TokenType.INTERFACE); IdentifierToken name = eatId(); GenericTypeListTree generics = maybeParseGenericTypes(); ImmutableList.Builder<ParseTree> superTypes = ImmutableList.builder(); if (peek(TokenType.EXTENDS)) { eat(TokenType.EXTENDS); ParseTree type = parseType(); superTypes.add(type); while (peek(TokenType.COMMA)) { eat(TokenType.COMMA); type = parseType(); if (type != null) { superTypes.add(type); } } } eat(TokenType.OPEN_CURLY); ImmutableList<ParseTree> elements = parseInterfaceElements(); eat(TokenType.CLOSE_CURLY); return new InterfaceDeclarationTree(getTreeLocation(start), name, generics, superTypes.build(), elements); }
private boolean peekFunctionTypeExpression() { if ((config.parseTypeSyntax && peek(TokenType.OPEN_PAREN)) || peek(TokenType.OPEN_ANGLE)) { // TODO(blickly): determine if we can parse this without the // overhead of forking the parser. Parser p = createLookaheadParser(); try { p.maybeParseGenericTypes(); p.parseFormalParameterList(ParamContext.TYPE_EXPRESSION); if (p.peek(TokenType.COLON)) { p.parseTypeAnnotation(); } return p.peek(TokenType.ARROW); } catch (ParseException e) { return false; } } return false; }
private boolean peekFunctionTypeExpression() { if (peek(TokenType.OPEN_PAREN) || peek(TokenType.OPEN_ANGLE)) { // TODO(blickly): determine if we can parse this without the // overhead of forking the parser. Parser p = createLookaheadParser(); try { p.maybeParseGenericTypes(); p.parseFormalParameterList(ParamContext.TYPE_EXPRESSION); if (p.peek(TokenType.COLON)) { p.parseTypeAnnotation(); } return p.peek(TokenType.ARROW); } catch (ParseException e) { return false; } } return false; }
GenericTypeListTree generics = maybeParseGenericTypes(); ParseTree superClass = null; if (peek(TokenType.EXTENDS)) {
GenericTypeListTree generics = maybeParseGenericTypes(); ParseTree superClass = null; if (peek(TokenType.EXTENDS)) {
private FunctionDeclarationTree parseAmbientFunctionDeclaration( SourcePosition start, IdentifierToken name, boolean isGenerator) { FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.DECLARATION) .setName(name) .setGenerator(isGenerator) .setGenerics(maybeParseGenericTypes()) .setFormalParameterList(parseFormalParameterList(ParamContext.SIGNATURE)) .setReturnType(maybeParseColonType()) .setFunctionBody(new EmptyStatementTree(getTreeLocation(start))); return builder.build(getTreeLocation(start)); }
private FunctionDeclarationTree parseMethodSignature( SourcePosition start, IdentifierToken name, boolean isStatic, boolean isGenerator, boolean isOptional, TokenType access) { FunctionDeclarationTree.Builder builder = FunctionDeclarationTree.builder(FunctionDeclarationTree.Kind.MEMBER) .setName(name) .setStatic(isStatic) .setGenerator(isGenerator) .setOptional(isOptional) .setAccess(access) .setGenerics(maybeParseGenericTypes()) .setFormalParameterList(parseFormalParameterList(ParamContext.SIGNATURE)) .setReturnType(maybeParseColonType()) .setFunctionBody(new EmptyStatementTree(getTreeLocation(start))); return builder.build(getTreeLocation(start)); }
if (partial.isAmbient) { builder .setGenerics(maybeParseGenericTypes()) .setFormalParameterList(parseFormalParameterList(ParamContext.SIGNATURE)) .setReturnType(maybeParseColonType())