Source
object into the
TokenBuilder
object.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the token builder.Returns the source.void
Reads a comment from the source.void
readFilename
(char terminator) Reads characters from the source up tp the specified terminator character (including the terminator character).void
Reads an identifier.int
Reads at most the specified number of characters while the specified predicate with the character returnstrue
.void
Reads a preprocessing number.void
Reads characters from the source until just before a newline character.void
readStringOrCharacter
(char terminator) Reads characters from the source up tp the specified terminator character (including the terminator character).readTokenOtherwise
(Case.Mapper mapper, DefaultTokenizer otherwise) Reads characters according to the specified mapper.void
readZeroOrMoreChars
(Predicate<Character> accepts) Reads zero or more characters while the specified predicate with the character returnstrue
.readZeroOrOneChar
(Predicate<Character> accepts) Reads at most one character with which the specified predicate returnstrue
.Returns a new token with the specified token type.tryReadToken
(Case.Mapper mapper, Tokenizer otherwise) Reads characters according to the specified mapper.tryReadToken
(Case.Mapper mapper, TokenType otherwise) Reads characters according to the specified mapper.
-
Constructor Details
-
Transcriber
Creates a new instance.- Parameters:
source
- The source that provides the stream of the source file.
-
-
Method Details
-
getSource
Returns the source.- Returns:
- The source.
-
getBuilder
Returns the token builder.- Returns:
- The token builder.
-
toToken
Returns a new token with the specified token type.Invocation of this method is equivalent to:
getBuilder().toToken(type)
- Parameters:
type
- The token type.- Returns:
- The new token.
-
readComment
Reads a comment from the source.The token builder must have stored the slash and asterisk.
This method will return when it reads the end of the comment (asterisk and slash) or reaches EOF.
- Throws:
IOException
- If an I/O error occurs.
-
readSingleLine
Reads characters from the source until just before a newline character.This method will return when it reads characters up to just before the newline character or reaches EOF.
- Throws:
IOException
- If an I/O error occurs.
-
readFilename
Reads characters from the source up tp the specified terminator character (including the terminator character).This method will return when it reads the specified terminator character or reaches EOF.
- Parameters:
terminator
- The character that terminates the filename.- Throws:
IOException
- If an I/O error occurs.
-
readStringOrCharacter
Reads characters from the source up tp the specified terminator character (including the terminator character).The token builder must have stored either single- or double-quote character.
This method takes escape sequences into account.
This method will return when it reads the specified terminator character (except within an escape sequence) or reaches EOF.
When this method reaches a newline character, it will return without reading it.
- Parameters:
terminator
- The terminator character.- Throws:
IOException
- If an I/O error occurs.
-
readMax
Reads at most the specified number of characters while the specified predicate with the character returnstrue
.This method will return when it reaches EOF.
- Parameters:
max
- The maximum number of characters.accepts
- The predicate that returnstrue
if the specified character is accepted.- Returns:
- The number of characters actually read.
- Throws:
IOException
- If an I/O error occurs.
-
readIdentifier
Reads an identifier.The token builder must have stored the first character of an identifier. It may also have stored the second and subsequent characters of an identifier.
The second and subsequent character of an identifier must be either:
- An underscore character, an uppercase or lowercase letter, or a
digit (
[_A-Za-z0-9]
) - Universal character names (
\
uXXXX
or\
UXXXXXXXX
,X
is a hexadecimal digit) - Other implementation-defined characters
The other implementation-defined characters are as follows:
- The first character: a character with which the
Character.isUnicodeIdentifierStart(int)
method returnstrue
- The second and subsequent character: a character with which the
Character.isUnicodeIdentifierPart(int)
method returnstrue
This method will return when it reaches EOF.
When this method reaches a character that is not an identifier, it will return without reading it.
- Throws:
IOException
- If an I/O error occurs.
- An underscore character, an uppercase or lowercase letter, or a
digit (
-
readZeroOrMoreChars
Reads zero or more characters while the specified predicate with the character returnstrue
.This method will return when it reaches EOF.
- Parameters:
accepts
- The predicate that returnstrue
if the specified character is accepted.- Throws:
IOException
- If an I/O error occurs.
-
readZeroOrOneChar
Reads at most one character with which the specified predicate returnstrue
.This method will return when it reaches EOF.
- Parameters:
accepts
- The predicate that returnstrue
if the specified character is accepted.- Returns:
- The character to have read, or
null
if no character has been read. - Throws:
IOException
- If an I/O error occurs.
-
readNumber
Reads a preprocessing number.The token builder must have stored the first character of a preprocessing number. It may also have stored the second and subsequent characters of a preprocessing number.
This method will return when it reaches EOF.
When this method reaches a character that is not a preprocessing number, it will return without reading it.
- Throws:
IOException
- If an I/O error occurs.
-
tryReadToken
Reads characters according to the specified mapper.This method reads the character that the mapper maps to the
Tokenizer
object and then invokes the tokenizer withthis
transcriber.When this method reaches a character and the mapper does not map the character or reaches EOF, it returns the specified token type
otherwise
without reading any character.- Parameters:
mapper
- The mapper.otherwise
- The token type that this method returns either if it reaches a character thatmapper
does not map, or if it reaches EOF.- Returns:
- The token type that the tokenizer returns if the
mapper
maps the character to the tokenizer. Otherwise,otherwise
. - Throws:
IOException
- If an I/O error occurs.
-
tryReadToken
Reads characters according to the specified mapper.This method reads the character that the mapper maps to the
Tokenizer
object and then invokes the tokenizer withthis
transcriber.When this method reaches a character and the mapper does not map the character or reaches EOF, it invokes the tokenizer
otherwise
without reading any character.- Parameters:
mapper
- The mapper.otherwise
- The tokenizer that this method invokes either if it reaches a character thatmapper
does not map, or if it reaches EOF.- Returns:
- The token type that the tokenizer returns if the
mapper
maps the character to the tokenizer. Otherwise, the token type that the tokenizerotherwise
returns. - Throws:
IOException
- If an I/O error occurs.
-
readTokenOtherwise
public TokenType readTokenOtherwise(Case.Mapper mapper, DefaultTokenizer otherwise) throws IOException Reads characters according to the specified mapper.This method reads the character that the mapper maps to the
Tokenizer
object and then invokes the tokenizer withthis
transcriber.When this method reads a character and the mapper does not map the character, it invokes the default tokenizer
otherwise
with it.When this method reaches EOF, it returns
null
without reading any character.- Parameters:
mapper
- The mapper.otherwise
- The default tokenizer that this method invokes if it has read a character thatmapper
does not map.- Returns:
- The token type that the tokenizer returns if the
mapper
maps the character to the tokenizer. The token type that the default tokenizerotherwise
returns if themapper
does not map the character.null
if this method reaches EOF. - Throws:
IOException
- If an I/O error occurs.
-