Class TokenParser
java.lang.Object
org.projog.core.parser.TokenParser
Parses an input stream into discrete 'tokens' that are used to represent Prolog queries and rules.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Tokenprivate final Operandsprivate final CharacterParserprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static TokencreateToken(StringBuilder value, TokenType type) private static TokencreateToken(String value, TokenType type) private intescape(int escape) (package private) booleanhasNext()private static booleanisEndOfStream(int c) private static booleanisEscapeSequencePrefix(int c) (package private) booleanDoes the next value to be parsed represent a term (rather than a delimiter)(package private) booleanisImmediatelyFollowedByBracket(boolean rewind) private static booleanisMultiLineCommentEnd(int c1, int c2) private static booleanisMultiLineCommentStart(int c1, int c2) private static booleanisQuote(int c) private static booleanisSingleLineComment(int c) private static booleanisUnderscore(int c) private static booleanisValidForAtom(int c) private booleanisValidParseableElement(String commandName) private static booleanisVariable(int c) private static booleanisZero(int c) (package private) ParserExceptionnewParserException(String message) Returns a newParserExceptionwith the specified message.(package private) Tokennext()Parse and return the nextToken.private intprivate charparseHex()private TokenparseLeadingZero(int zero) Parses a character code and represents it as an integer.private TokenparseNumber(int startChar) Parses a number, starting with the specified character, read from the parser.private TokenReads aStringconsisting of all characters read from the parser up to the next'.private TokenparseSymbol(int c) private Tokenprivate Tokenprivate int(package private) voidRewinds the parser (i.e.private voidprivate voidprivate void
-
Field Details
-
parser
-
operands
-
lastParsedToken
-
rewound
private boolean rewound
-
-
Constructor Details
-
TokenParser
-
-
Method Details
-
hasNext
boolean hasNext()- Returns:
trueif there are more tokens to be parsed, elsefalse
-
next
Token next()Parse and return the nextToken.- Returns:
- the token that was parsed as a result of this call
- Throws:
ParserException- if there are no more tokens to parse (i.e. parser has reached the end of the underlying input stream)
-
parseToken
-
rewind
Rewinds the parser (i.e. "pushes-back" the last parsed token).The last parsed value will remain after the next call to
next()- Parameters:
value- the value to rewind- Throws:
IllegalArgumentException- if already in a rewound state (i.e. have already calledsince the last call toinvalid reference
TokenParser#rewind(String)next()), orvalueis not equal toinvalid reference
#getValue()
-
isImmediatelyFollowedByBracket
boolean isImmediatelyFollowedByBracket(boolean rewind) -
isFollowedByTerm
boolean isFollowedByTerm()Does the next value to be parsed represent a term (rather than a delimiter) -
newParserException
Returns a newParserExceptionwith the specified message. -
skipWhitespaceAndComments
private void skipWhitespaceAndComments() -
parseText
-
parseQuotedText
Reads aStringconsisting of all characters read from the parser up to the next'.If an atom's name is enclosed in quotes (i.e.
') then it may contain any character. -
parseLeadingZero
Parses a character code and represents it as an integer.e.g. the text
0'aresults in a token with the value97(the ascii value fora) being returned. -
parseEscapeSequence
private int parseEscapeSequence() -
parseUnicode
private int parseUnicode() -
parseHex
private char parseHex() -
parseNumber
Parses a number, starting with the specified character, read from the parser.Deals with numbers of the form
3.4028235E38. -
escape
private int escape(int escape) -
parseSymbol
-
skipWhitespace
private void skipWhitespace() -
skipMultiLineComment
private void skipMultiLineComment() -
isValidParseableElement
-
isEndOfStream
private static boolean isEndOfStream(int c) -
isSingleLineComment
private static boolean isSingleLineComment(int c) -
isMultiLineCommentStart
private static boolean isMultiLineCommentStart(int c1, int c2) -
isMultiLineCommentEnd
private static boolean isMultiLineCommentEnd(int c1, int c2) -
isValidForAtom
private static boolean isValidForAtom(int c) -
isVariable
private static boolean isVariable(int c) -
isUnderscore
private static boolean isUnderscore(int c) -
isQuote
private static boolean isQuote(int c) -
isZero
private static boolean isZero(int c) -
isEscapeSequencePrefix
private static boolean isEscapeSequencePrefix(int c) -
createToken
-
createToken
-