Class Scanner
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final Stringprivate booleanprivate final Readerprivate intprivate intprivate intprivate intprivate final StringBuilderHolds the characters of the currently scanned token.static final StringIf the source code is not read from a file, debuggers have a hard time locating the source file for source-level debugging.static final StringSetting this system property to 'true' enables source-level debugging.static final StringIf set to "true", then the temporary source code files are not deleted on exit.private intColumn number of the first character of the previously produced token (1 if token is immediately preceded by a line break).private intLine number of the previously produced token (typically starting at one). -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.This method is deprecated because it leaves the input file openDeprecated.This method is deprecated because it leaves the input file openDeprecated.This method is deprecated because it leaves the input file openScanner(String fileName, InputStream is) Sets up a scanner that reads tokens from the givenInputStreamin the platform default encoding.Scanner(String fileName, InputStream is, String encoding) Sets up a scanner that reads tokens from the givenInputStreamwith the given encoding (nullmeans platform default encoding).Sets up a scanner that reads tokens from the givenReader.Creates aScannerthat counts lines and columns from non-default initial values.Deprecated.This method is deprecated because it leaves the input file open -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Deprecated.This method is deprecated, because the concept described above is confusing.private intprivate static booleanisBinaryDigit(int c) private static booleanisDecimalDigit(int c) To comply with the JLS, this method does not allow for non-latin digit (likeCharacter.isDigit(char)does).private static booleanisHexDigit(int c) To comply with the JLS, this method does not allow for non-latin digit (likeCharacter.isDigit(char)does).private static booleanisOctalDigit(int c) location()private intpeek()Returns the next character, but does not consume it.private booleanChecks whether the next character is one of the expectedCharacters.private intReturns the next-but-one character, but does not consume any characters.private booleanpeekRead(int expected) Consumes the next character iff it equals the expected character.private booleanConsumes the next character iff it is one of the expectedCharactersproduce()Produces and returns the next token.private charread()Consumes and returns the next character.private TokenTypescan()private voidScans the next literal character into aStringBuilder.private TokenTypevoidsetIgnoreWhiteSpace(boolean value) If value istrue, then white space in the input stream is ignored, rather than scanned as aTokenType.WHITE_SPACEtoken.private Token
-
Field Details
-
SYSTEM_PROPERTY_SOURCE_DEBUGGING_ENABLE
Setting this system property to 'true' enables source-level debugging. Typically, this means that compilation is executed with "-g:all" instead of "-g:none".- See Also:
-
SYSTEM_PROPERTY_SOURCE_DEBUGGING_DIR
If the source code is not read from a file, debuggers have a hard time locating the source file for source-level debugging. As a workaround, a copy of the source code is written to a temporary file, which must be included in the debugger's source path. If this system property is set, the temporary source file is created in that directory, otherwise in the default temporary-file directory.- See Also:
-
SYSTEM_PROPERTY_SOURCE_DEBUGGING_KEEP
If set to "true", then the temporary source code files are not deleted on exit. That may be useful to interpret stack traces offline.- See Also:
-
sb
Holds the characters of the currently scanned token. -
fileName
-
in
-
ignoreWhiteSpace
private boolean ignoreWhiteSpace -
nextChar
private int nextChar -
nextButOneChar
private int nextButOneChar -
crLfPending
private boolean crLfPending -
nextCharLineNumber
private int nextCharLineNumber -
nextCharColumnNumber
private int nextCharColumnNumber -
tokenLineNumber
private int tokenLineNumberLine number of the previously produced token (typically starting at one). -
tokenColumnNumber
private int tokenColumnNumberColumn number of the first character of the previously produced token (1 if token is immediately preceded by a line break). -
JAVA_KEYWORDS
-
JAVA_OPERATORS
-
-
Constructor Details
-
Scanner
Deprecated.This method is deprecated because it leaves the input file open- Throws:
IOException
-
Scanner
Deprecated.This method is deprecated because it leaves the input file open- Throws:
IOException
-
Scanner
Deprecated.This method is deprecated because it leaves the input file open- Throws:
IOException
-
Scanner
Deprecated.This method is deprecated because it leaves the input file open- Throws:
IOException
-
Scanner
Sets up a scanner that reads tokens from the givenInputStreamin the platform default encoding.The fileName is solely used for reporting in thrown exceptions.
- Throws:
IOException
-
Scanner
public Scanner(@Nullable String fileName, InputStream is, @Nullable String encoding) throws IOException Sets up a scanner that reads tokens from the givenInputStreamwith the given encoding (nullmeans platform default encoding).The fileName is used for reporting errors during compilation and for source level debugging, and should name an existing file. If
nullis passed, and the system propertyorg.codehaus.janino.source_debugging.enableis set to "true", then a temporary file inorg.codehaus.janino.source_debugging.diror the system's default temp dir is created in order to make the source code available to a debugger.- Throws:
IOException
-
Scanner
Sets up a scanner that reads tokens from the givenReader.The fileName is used for reporting errors during compilation and for source level debugging, and should name an existing file. If
nullis passed, and the system propertyorg.codehaus.janino.source_debugging.enableis set to "true", then a temporary file inorg.codehaus.janino.source_debugging.diror the system's default temp dir is created in order to make the source code available to a debugger.- Throws:
IOException
-
Scanner
public Scanner(@Nullable String fileName, Reader in, int initialLineNumber, int initialColumnNumber) throws IOException Creates aScannerthat counts lines and columns from non-default initial values.- Throws:
IOException
-
-
Method Details
-
setIgnoreWhiteSpace
public void setIgnoreWhiteSpace(boolean value) If value istrue, then white space in the input stream is ignored, rather than scanned as aTokenType.WHITE_SPACEtoken. Since white space is typically quite numerous, this optimization may save considerable overhead. -
getFileName
-
close
Deprecated.This method is deprecated, because the concept described above is confusing. An application should close the underlyingInputStreamorReaderitselfCloses the character source (file,InputStream,Reader) associated with this object. The results of future calls toproduce()are undefined.- Throws:
IOException
-
location
-
token
-
produce
Produces and returns the next token. Notice that end-of-input is not signalized with anullproduct, but by anTokenType.END_OF_INPUT-type token.- Throws:
CompileExceptionIOException
-
scan
- Throws:
CompileExceptionIOException
-
scanNumericLiteral
- Throws:
CompileExceptionIOException
-
isDecimalDigit
private static boolean isDecimalDigit(int c) To comply with the JLS, this method does not allow for non-latin digit (likeCharacter.isDigit(char)does). -
isHexDigit
private static boolean isHexDigit(int c) To comply with the JLS, this method does not allow for non-latin digit (likeCharacter.isDigit(char)does). -
isOctalDigit
private static boolean isOctalDigit(int c) -
isBinaryDigit
private static boolean isBinaryDigit(int c) -
scanLiteralCharacter
Scans the next literal character into aStringBuilder.- Throws:
CompileExceptionIOException
-
peek
Returns the next character, but does not consume it.- Returns:
- -1 iff there is no next character, i.e the input stream is at end-of-input
- Throws:
CompileExceptionIOException
-
peek
Checks whether the next character is one of the expectedCharacters.It is not possible to peek exactly for "end-of-input"; use
peekRead(-1)instead.- Throws:
CompileExceptionIOException
-
peekButOne
Returns the next-but-one character, but does not consume any characters.- Throws:
CompileExceptionIOException
-
read
Consumes and returns the next character.- Throws:
CompileException- There is no next charcter, i.e. the input stream is at end-of-inputIOException
-
peekRead
Consumes the next character iff it equals the expected character.- Returns:
- Whether the next character equalled the expected character
- Throws:
CompileExceptionIOException
-
peekRead
Consumes the next character iff it is one of the expectedCharacters- Returns:
- Whether the next character was one of the expectedCharacters
- Throws:
CompileExceptionIOException
-
internalRead
- Returns:
- -1 iff there is no next character, i.e the input stream is at end-of-input
- Throws:
IOExceptionCompileException
-