private void reportTemplateErrorIfPresent(TemplateLiteralToken templateToken) { if (templateToken.errorMessage != null) { reportError(templateToken.errorPosition, "%s", templateToken.errorMessage); } }
/** * Report a 'X' expected error message. * @param token The location to report the message at. * @param expected The thing that was expected. */ private void reportExpectedError(Token token, Object expected) { reportError(token, "'%s' expected", expected); }
/** * Report a 'X' expected error message. * @param token The location to report the message at. * @param expected The thing that was expected. */ private void reportExpectedError(Token token, Object expected) { reportError(token, "'%s' expected", expected); }
/** Reports if declaration requires an initializer, assuming initializer is absent. */ private void maybeReportNoInitializer(TokenType token, ParseTree lvalue) { if (token == TokenType.CONST) { reportError("const variables must have an initializer"); } else if (lvalue.isPattern()) { reportError("destructuring must have an initializer"); } }
/** Reports if declaration requires an initializer, assuming initializer is absent. */ private void maybeReportNoInitializer(TokenType token, ParseTree lvalue) { if (token == TokenType.CONST) { features = features.require(Feature.CONST_DECLARATIONS); reportError("const variables must have an initializer"); } else if (lvalue.isPattern()) { features = features.require(Feature.DESTRUCTURING); reportError("destructuring must have an initializer"); } }
private ParseTree parseRestAssignmentTarget(PatternKind patternKind) { ParseTree patternAssignmentTarget = parsePatternAssignmentTargetNoDefault(patternKind); if (peek(TokenType.EQUAL)) { reportError("A default value cannot be specified after '...'"); } return patternAssignmentTarget; }
private VariableDeclarationListTree parseAmbientVariableDeclarationList() { VariableDeclarationListTree declare = parseVariableDeclarationList(Expression.NO_IN); // AmbientVariebleDeclaration may not have initializer for (VariableDeclarationTree tree : declare.asVariableDeclarationList().declarations) { if (tree.initializer != null) { reportError("Ambient variable declaration may not have initializer"); } } return declare; }
private ParseTree parseRestAssignmentTarget(PatternKind patternKind) { ParseTree patternAssignmentTarget = parsePatternAssignmentTargetNoDefault(patternKind); if (peek(TokenType.EQUAL)) { reportError("A default value cannot be specified after '...'"); } return patternAssignmentTarget; }
private VariableDeclarationListTree parseAmbientVariableDeclarationList() { VariableDeclarationListTree declare = parseVariableDeclarationList(Expression.NO_IN); // AmbientVariebleDeclaration may not have initializer for (VariableDeclarationTree tree : declare.asVariableDeclarationList().declarations) { if (tree.initializer != null) { reportError("Ambient variable declaration may not have initializer"); } } return declare; }
/** * Reports an error message at a given token. * @param token The location to report the message at. * @param message The message to report in String.format style. * @param arguments The arguments to fill in the message format. */ private void reportError(Token token, String message, Object... arguments) { if (token == null) { reportError(message, arguments); } else { errorReporter.reportError(token.getStart(), message, arguments); } }
private TokenType maybeParseAccessibilityModifier() { if (peekAccessibilityModifier()) { features = features.require(FeatureSet.TYPESCRIPT); if (!config.is6Typed) { reportError("Accessibility modifier is only supported in ES6 typed mode"); } return nextToken().type; } else { return null; } }
/** * Reports an error message at a given parse tree's location. * * @param parseTree The location to report the message at. * @param message The message to report in String.format style. * @param arguments The arguments to fill in the message format. */ @FormatMethod private void reportError(ParseTree parseTree, @FormatString String message, Object... arguments) { if (parseTree == null) { reportError(message, arguments); } else { errorReporter.reportError(parseTree.location.start, message, arguments); } }
private ParseTree parseMissingPrimaryExpression() { SourcePosition start = getTreeStartLocation(); nextToken(); reportError("primary expression expected"); return new MissingPrimaryExpressionTree(getTreeLocation(start)); }
private ParseTree parseMissingPrimaryExpression() { SourcePosition start = getTreeStartLocation(); nextToken(); reportError("primary expression expected"); return new MissingPrimaryExpressionTree(getTreeLocation(start)); }
/** * Reports an error message at a given token. * @param token The location to report the message at. * @param message The message to report in String.format style. * @param arguments The arguments to fill in the message format. */ @FormatMethod private void reportError(Token token, @FormatString String message, Object... arguments) { if (token == null) { reportError(message, arguments); } else { errorReporter.reportError(token.getStart(), message, arguments); } }
private ParseTree parseAwaitExpression() { SourcePosition start = getTreeStartLocation(); if (functionContextStack.isEmpty() || !functionContextStack.peekLast().isAsynchronous) { reportError("'await' used in a non-async function context"); } eatPredefinedString(AWAIT); ParseTree expression = parseUnaryExpression(); return new AwaitExpressionTree(getTreeLocation(start), expression); }
public ProgramTree parseProgram() { try { SourcePosition start = getTreeStartLocation(); ImmutableList<ParseTree> sourceElements = parseGlobalSourceElements(); eat(TokenType.END_OF_FILE); return new ProgramTree( getTreeLocation(start), sourceElements, commentRecorder.getComments()); } catch (StackOverflowError e) { reportError("Too deep recursion while parsing"); return null; } }
/** * Consume a (possibly implicit) semi-colon. Reports an error if a semi-colon is not present. */ private void eatPossibleImplicitSemiColon() { if (peek(TokenType.SEMI_COLON) && peekToken().location.start.line == getLastLine()) { eat(TokenType.SEMI_COLON); return; } if (peekImplicitSemiColon()) { return; } reportError("Semi-colon expected"); }
private ParseTree parseThrowStatement() { SourcePosition start = getTreeStartLocation(); eat(TokenType.THROW); ParseTree value = null; if (peekImplicitSemiColon()) { reportError("semicolon/newline not allowed after 'throw'"); } else { value = parseExpression(); } eatPossibleImplicitSemiColon(); return new ThrowStatementTree(getTreeLocation(start), value); }
private ParseTree parseThrowStatement() { SourcePosition start = getTreeStartLocation(); eat(TokenType.THROW); ParseTree value = null; if (peekImplicitSemiColon()) { reportError("semicolon/newline not allowed after 'throw'"); } else { value = parseExpression(); } eatPossibleImplicitSemiColon(); return new ThrowStatementTree(getTreeLocation(start), value); }