private ParseTree maybeParseColonType() { ParseTree type = null; if (peek(TokenType.COLON)) { type = parseTypeAnnotation(); } return type; }
private ParseTree maybeParseColonType() { ParseTree type = null; if (peek(TokenType.COLON)) { type = parseTypeAnnotation(); } return type; }
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; }
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 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; }
private VariableDeclarationTree parseVariableDeclaration( final TokenType binding, Expression expressionIn) { SourcePosition start = getTreeStartLocation(); ParseTree lvalue; ParseTree typeAnnotation = null; if (peekPatternStart()) { lvalue = parsePattern(PatternKind.INITIALIZER); } else { lvalue = parseIdentifierExpression(); if (peek(TokenType.COLON)) { typeAnnotation = parseTypeAnnotation(); } } ParseTree initializer = null; if (peek(TokenType.EQUAL)) { initializer = parseInitializer(expressionIn); } else if (expressionIn != Expression.NO_IN) { // NOTE(blickly): this is a bit of a hack, declarations outside of for statements allow "in", // and by chance, also must have initializers for const/destructuring. Vanilla for loops // also require intializers, but are handled separately in checkVanillaForInitializers maybeReportNoInitializer(binding, lvalue); } return new VariableDeclarationTree(getTreeLocation(start), lvalue, typeAnnotation, initializer); }
private VariableDeclarationTree parseVariableDeclaration( final TokenType binding, Expression expressionIn) { SourcePosition start = getTreeStartLocation(); ParseTree lvalue; ParseTree typeAnnotation = null; if (peekPatternStart()) { lvalue = parsePattern(PatternKind.INITIALIZER); } else { lvalue = parseIdentifierExpression(); if (peek(TokenType.COLON)) { typeAnnotation = parseTypeAnnotation(); } } ParseTree initializer = null; if (peek(TokenType.EQUAL)) { initializer = parseInitializer(expressionIn); } else if (expressionIn != Expression.NO_IN) { // NOTE(blickly): this is a bit of a hack, declarations outside of for statements allow "in", // and by chance, also must have initializers for const/destructuring. Vanilla for loops // also require intializers, but are handled separately in checkVanillaForInitializers maybeReportNoInitializer(binding, lvalue); } return new VariableDeclarationTree(getTreeLocation(start), lvalue, typeAnnotation, initializer); }
typeAnnotation = parseTypeAnnotation();
typeAnnotation = parseTypeAnnotation();