public class Scanner extends BacktrackScanner
BacktrackScanner
extended with helpful methods for parsing common
things. Generally, all methods parse input starting at the current
position, and throw UnexpectedInput
if the expected input is not
found. If an exception is thrown, the current input position is left
unchanged.BacktrackScanner.Location
Constructor and Description |
---|
Scanner() |
Scanner(java.io.Reader r,
java.lang.String name)
Create scanner that reads from source input
r ,
calling the source name . |
Scanner(java.lang.String filename)
Create scanner that reads from file named
filename . |
Modifier and Type | Method and Description |
---|---|
void |
digits()
Scan one or more digits.
|
void |
eol()
Scan to the end of the current line or to the end of the input, whichever
is first.
|
void |
floatingPoint()
Scan a floating-point number.
|
void |
identifier()
Scan an identifier ala Java.
|
void |
integer()
Scan past an integer constant.
|
void |
newline()
Scan past a optional carriage return character and a newline character.
|
char |
nextDigit()
Scan past and return the next character if it is a digit.
|
double |
nextDouble()
Scan past a float-point constant and return its value as a
double |
java.lang.String |
nextIdentifier()
Scan past and return an identifier.
|
java.lang.String |
nextLine()
Scan past and return all text from the current position to the next
newline character.
|
void |
optDigits()
Scan past all digits at the current posn, if any.
|
void |
trailingWhitespace()
Scan past any whitespace up to the end of the line, the end of the file,
or the next non-whitespace character.
|
void |
whitespace()
Scan past any whitespace.
|
public Scanner()
public Scanner(java.io.Reader r, java.lang.String name)
r
,
calling the source name
.public Scanner(java.lang.String filename) throws java.io.FileNotFoundException
filename
. To read
directly from a string, use a StringReader
.java.io.FileNotFoundException
StringReader
public void whitespace()
public char nextDigit() throws UnexpectedInput
UnexpectedInput
public void optDigits()
public void integer() throws UnexpectedInput
UnexpectedInput
- if the characters at the current position are not a
integer literal.public void floatingPoint() throws UnexpectedInput
UnexpectedInput
- if the characters at the current position are not a
floating-point literal.public void digits() throws UnexpectedInput
UnexpectedInput
- if the next character is not a digit.public void identifier() throws UnexpectedInput
UnexpectedInput
public double nextDouble() throws UnexpectedInput
double
UnexpectedInput
- if the characters following the current position are not an double
literal.public java.lang.String nextLine() throws UnexpectedInput
UnexpectedInput
- if there is no terminated line after the current position.public java.lang.String nextIdentifier() throws UnexpectedInput
UnexpectedInput
- if the characters at the current position are not a
legal Java identifier.public void newline() throws UnexpectedInput
UnexpectedInput
- if the next characters are neither "\r\n" nor "\n".public void eol()
public void trailingWhitespace()