/** * Returns the next token. Does not consume any tokens. */ private Token peekToken() { return peekToken(0); }
/** * Returns the line number of the next token. */ private int getNextLine() { return peekToken().location.start.line; }
/** * Returns the line number of the next token. */ private int getNextLine() { return peekToken().location.start.line; }
/** * Returns the next token. Does not consume any tokens. */ private Token peekToken() { return peekToken(0); }
/** * Returns a SourcePosition for the start of a parse tree that starts at the current location. */ private SourcePosition getTreeStartLocation() { return peekToken().location.start; }
/** * Returns the TokenType of the index-th next token. Does not consume any tokens. */ private TokenType peekType(int index) { return peekToken(index).type; }
/** * Returns a SourcePosition for the start of a parse tree that starts at the current location. */ private SourcePosition getTreeStartLocation() { return peekToken().location.start; }
/** * Returns the TokenType of the index-th next token. Does not consume any tokens. */ private TokenType peekType(int index) { return peekToken(index).type; }
private boolean peekClassElement() { Token token = peekToken(); switch (token.type) { case IDENTIFIER: case STAR: case STATIC: case OPEN_SQUARE: case SEMI_COLON: return true; default: return Keywords.isKeyword(token.type); } }
private boolean peekPredefinedString(int index, String string) { return peek(index, TokenType.IDENTIFIER) && ((IdentifierToken) peekToken(index)).value.equals(string); }
private boolean peekPredefinedString(int index, String string) { return peek(index, TokenType.IDENTIFIER) && ((IdentifierToken) peekToken(index)).value.equals(string); }
private boolean peekInterfaceElement() { Token token = peekToken(); switch (token.type) { case NEW: case IDENTIFIER: case OPEN_SQUARE: case STAR: case OPEN_ANGLE: case OPEN_PAREN: return true; default: return Keywords.isKeyword(token.type); } }
private Token eatObjectLiteralPropertyName() { Token token = peekToken(); switch (token.type) { case STRING: case NUMBER: return nextToken(); case IDENTIFIER: default: return eatIdOrKeywordAsId(); } }
private Token eatObjectLiteralPropertyName() { Token token = peekToken(); switch (token.type) { case STRING: case NUMBER: return nextToken(); case IDENTIFIER: default: return eatIdOrKeywordAsId(); } }
private boolean peekImplicitSemiColon(int index) { boolean lineAdvanced; if (index == 0) { lineAdvanced = getNextLine() > getLastLine(); } else { lineAdvanced = peekToken(index).location.start.line > peekToken(index - 1).location.end.line; } return lineAdvanced || peek(index, TokenType.SEMI_COLON) || peek(index, TokenType.CLOSE_CURLY) || peek(index, TokenType.END_OF_FILE); }
private boolean peekImplicitSemiColon(int index) { boolean lineAdvanced; if (index == 0) { lineAdvanced = getNextLine() > getLastLine(); } else { lineAdvanced = peekToken(index).location.start.line > peekToken(index - 1).location.end.line; } return lineAdvanced || peek(index, TokenType.SEMI_COLON) || peek(index, TokenType.CLOSE_CURLY) || peek(index, TokenType.END_OF_FILE); }
/** * Consumes an identifier token that is not a reserved word. * @see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" */ private IdentifierToken eatId() { if (peekId()) { return eatIdOrKeywordAsId(); } else { reportExpectedError(peekToken(), TokenType.IDENTIFIER); 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"); }
/** * 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"); }
/** * Consumes an identifier token that is not a reserved word. * @see "http://www.ecma-international.org/ecma-262/5.1/#sec-7.6" */ private IdentifierToken eatId() { if (peekId()) { return eatIdOrKeywordAsId(); } else { reportExpectedError(peekToken(), TokenType.IDENTIFIER); if (peekIdOrKeyword()) { return eatIdOrKeywordAsId(); } else { return null; } } }