org.codehaus.janino

Class Scanner

public class Scanner extends Object

Splits up a character stream into tokens and returns them as java.lang.String String objects.

The optionalFileName parameter passed to many constructors should point

Nested Class Summary
classScanner.EOFToken
classScanner.IdentifierToken
classScanner.KeywordToken
classScanner.LiteralToken
The type of the value parameter determines the type of the literal token:
Type/value returned by getLiteralValueLiteral
StringSTRING literal
CharacterCHAR literal
IntegerINT literal
LongLONG literal
FloatFLOAT literal
DoubleDOUBLE literal
BooleanBOOLEAN literal
nullNULL literal
classScanner.OperatorToken
classScanner.ScanException
An exception that reflects an error during parsing.
abstract classScanner.Token
Field Summary
static IntegerMAGIC_INTEGER
This reference represents the "magic" literal "2147483648" which is only allowed in a negated context.
static LongMAGIC_LONG
This reference represents the "magic" literal "9223372036854775808L" which is only allowed in a negated context.
Constructor Summary
Scanner(String fileName)
Set up a scanner that reads tokens from the given file in the default charset.
Scanner(String fileName, String encoding)
Set up a scanner that reads tokens from the given file in the given encoding.
Scanner(File file)
Set up a scanner that reads tokens from the given file in the platform default encoding.
Scanner(File file, String optionalEncoding)
Set up a scanner that reads tokens from the given file in the given encoding.
Scanner(String optionalFileName, InputStream is)
Set up a scanner that reads tokens from the given InputStream in the platform default encoding.
Scanner(String optionalFileName, InputStream is, String optionalEncoding)
Set up a scanner that reads tokens from the given InputStream with the given optionalEncoding (null means platform default encoding).
Scanner(String optionalFileName, Reader in)
Set up a scanner that reads tokens from the given Reader.
Scanner(String optionalFileName, Reader in, short initialLineNumber, short initialColumnNumber)
Creates a Scanner that counts lines and columns from non-default initial values.
Method Summary
voidclose()
Closes the character source (file, InputStream, Reader) associated with this object.
Stringdoc()
Get the text of the doc comment (a.k.a.
StringgetFileName()
Return the file name optionally passed to the constructor.
static StringliteralValueToString(Object v)
Locationlocation()
Returns the Location of the next token.
Scanner.Tokenpeek()
Peek the next token, but don't remove it from the input.
Scanner.TokenpeekNextButOne()
Peek the next but one token, neither remove the next nor the next but one token from the input.
Scanner.Tokenread()
Read the next token from the input.
voidsetWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a WarningHandler.

Field Detail

MAGIC_INTEGER

public static final Integer MAGIC_INTEGER
This reference represents the "magic" literal "2147483648" which is only allowed in a negated context.

MAGIC_LONG

public static final Long MAGIC_LONG
This reference represents the "magic" literal "9223372036854775808L" which is only allowed in a negated context.

Constructor Detail

Scanner

public Scanner(String fileName)

Deprecated:

Set up a scanner that reads tokens from the given file in the default charset.

This method is deprecated because it leaves the input file open.

Scanner

public Scanner(String fileName, String encoding)

Deprecated:

Set up a scanner that reads tokens from the given file in the given encoding.

This method is deprecated because it leaves the input file open.

Scanner

public Scanner(File file)

Deprecated:

Set up a scanner that reads tokens from the given file in the platform default encoding.

This method is deprecated because it leaves the input file open.

Scanner

public Scanner(File file, String optionalEncoding)

Deprecated:

Set up a scanner that reads tokens from the given file in the given encoding.

This method is deprecated because it leaves the input file open.

Scanner

public Scanner(String optionalFileName, InputStream is)
Set up a scanner that reads tokens from the given InputStream in the platform default encoding.

The fileName is solely used for reporting in thrown exceptions.

Scanner

public Scanner(String optionalFileName, InputStream is, String optionalEncoding)
Set up a scanner that reads tokens from the given InputStream with the given optionalEncoding (null means platform default encoding).

The optionalFileName is used for reporting errors during compilation and for source level debugging, and should name an existing file. If null is passed, and the system property org.codehaus.janino.source_debugging.enable is set to "true", then a temporary file in org.codehaus.janino.source_debugging.dir or the system's default temp dir is created in order to make the source code available to a debugger.

Scanner

public Scanner(String optionalFileName, Reader in)
Set up a scanner that reads tokens from the given Reader.

The optionalFileName is used for reporting errors during compilation and for source level debugging, and should name an existing file. If null is passed, and the system property org.codehaus.janino.source_debugging.enable is set to "true", then a temporary file in org.codehaus.janino.source_debugging.dir or the system's default temp dir is created in order to make the source code available to a debugger.

Scanner

public Scanner(String optionalFileName, Reader in, short initialLineNumber, short initialColumnNumber)
Creates a Scanner that counts lines and columns from non-default initial values.

Method Detail

close

public void close()

Deprecated:

Closes the character source (file, InputStream, Reader) associated with this object. The results of future calls to peek and read are undefined.

This method is deprecated, because the concept described above is confusing. An application should close the underlying InputStream or Reader itself.

doc

public String doc()
Get the text of the doc comment (a.k.a. "JAVADOC comment") preceeding the next token.

Returns: null if the next token is not preceeded by a doc comment

getFileName

public String getFileName()
Return the file name optionally passed to the constructor.

literalValueToString

public static String literalValueToString(Object v)

location

public Location location()
Returns the Location of the next token.

peek

public Scanner.Token peek()
Peek the next token, but don't remove it from the input.

peekNextButOne

public Scanner.Token peekNextButOne()
Peek the next but one token, neither remove the next nor the next but one token from the input.

This makes parsing so much easier, e.g. for class literals like Map.class.

read

public Scanner.Token read()
Read the next token from the input.

setWarningHandler

public void setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a WarningHandler.

Notice that there is no Scanner.setErrorHandler() method, but scan errors always throw a ScanException. The reason being is that there is no reasonable way to recover from scan errors and continue scanning, so there is no need to install a custom scan error handler.

Parameters: optionalWarningHandler null to indicate that no warnings be issued