/** * Return a new {@link FunctionDeclarationTree}. * * <p> The location is provided at this point because it cannot be correctly calculated * until the whole function has been parsed. */ public FunctionDeclarationTree build(SourceRange location) { this.location = location; return new FunctionDeclarationTree(this); } }
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 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 ParseTree parseArrowFunctionTail( SourcePosition start, GenericTypeListTree generics, FormalParameterListTree formalParameterList, Expression expressionIn) { inGeneratorContext.addLast(false); ParseTree returnType = null; if (peek(TokenType.COLON)) { returnType = parseTypeAnnotation(); } if (peekImplicitSemiColon()) { reportError("No newline allowed before '=>'"); } eat(TokenType.ARROW); ParseTree functionBody; if (peek(TokenType.OPEN_CURLY)) { functionBody = parseFunctionBody(); } else { functionBody = parseAssignment(expressionIn); } FunctionDeclarationTree declaration = new FunctionDeclarationTree( getTreeLocation(start), null, generics, false, false, false, null, FunctionDeclarationTree.Kind.ARROW, formalParameterList, returnType, functionBody); inGeneratorContext.removeLast(); return declaration; }