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 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 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 parseSetAccessor(TokenType access) { SourcePosition start = getTreeStartLocation(); boolean isStatic = eatOpt(TokenType.STATIC) != null; eatPredefinedString(PredefinedName.SET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); eat(TokenType.OPEN_PAREN); IdentifierToken parameter = eatId(); ParseTree type = maybeParseColonType(); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); if (returnType != null) { reportError(scanner.peekToken(), "setter should not have any returns"); } BlockTree body = parseFunctionBody(); return new SetAccessorTree( getTreeLocation(start), propertyName, isStatic, parameter, type, body); } else { ParseTree property = parseComputedPropertyName(); eat(TokenType.OPEN_PAREN); IdentifierToken parameter = eatId(); ParseTree type = maybeParseColonType(); eat(TokenType.CLOSE_PAREN); BlockTree body = parseFunctionBody(); return new ComputedPropertySetterTree( getTreeLocation(start), property, isStatic, access, parameter, type, body); } }
private ParseTree parseGetAccessor(TokenType access) { SourcePosition start = getTreeStartLocation(); boolean isStatic = eatOpt(TokenType.STATIC) != null; eatPredefinedString(PredefinedName.GET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); return new GetAccessorTree(getTreeLocation(start), propertyName, isStatic, returnType, body); } else { ParseTree property = parseComputedPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); return new ComputedPropertyGetterTree( getTreeLocation(start), property, isStatic, access, returnType, body); } }
private ParseTree parseGetAccessor(PartialClassElement partial) { eatPredefinedString(PredefinedName.GET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.GETTER); return new GetAccessorTree( getTreeLocation(partial.start), propertyName, partial.isStatic, returnType, body); } else { ParseTree property = parseComputedPropertyName(); eat(TokenType.OPEN_PAREN); eat(TokenType.CLOSE_PAREN); ParseTree returnType = maybeParseColonType(); BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.GETTER); return new ComputedPropertyGetterTree( getTreeLocation(partial.start), property, partial.isStatic, partial.accessModifier, returnType, body); } }
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)); }
} else { ParseTree declaredType = maybeParseColonType(); return new MemberVariableTree( getTreeLocation(start), name, false, isOptional, null, declaredType);
private ParseTree parseSetAccessor(PartialClassElement partial) { eatPredefinedString(PredefinedName.SET); if (peekPropertyName(0)) { Token propertyName = eatObjectLiteralPropertyName(); FormalParameterListTree parameter = parseSetterParameterList(); ParseTree returnType = maybeParseColonType(); if (returnType != null) { reportError(scanner.peekToken(), "setter should not have any returns"); } BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.SETTER); return new SetAccessorTree( getTreeLocation(partial.start), propertyName, partial.isStatic, parameter, body); } else { ParseTree property = parseComputedPropertyName(); FormalParameterListTree parameter = parseSetterParameterList(); BlockTree body = parseFunctionBody(); recordFeatureUsed(Feature.SETTER); return new ComputedPropertySetterTree( getTreeLocation(partial.start), property, partial.isStatic, partial.accessModifier, parameter, body); } }
} else { ParseTree declaredType = maybeParseColonType(); return new MemberVariableTree( getTreeLocation(start), name, false, isOptional, null, declaredType);
reportError("Member variable cannot be prefixed by '*' (generator function)"); ParseTree declaredType = maybeParseColonType(); if (peek(TokenType.EQUAL)) { reportError("Member variable initializers ('=') are not supported");
reportError("Member variable cannot be prefixed by '*' (generator function)"); ParseTree declaredType = maybeParseColonType(); if (peek(TokenType.EQUAL)) { reportError("Member variable initializers ('=') are not supported");
.setGenerics(maybeParseGenericTypes()) .setFormalParameterList(parseFormalParameterList(ParamContext.SIGNATURE)) .setReturnType(maybeParseColonType()) .setFunctionBody(new EmptyStatementTree(getTreeLocation(partial.start))); eatPossibleImplicitSemiColon();