Package easyIO
Class Scanner
- java.lang.Object
-
- easyIO.BacktrackScanner
-
- easyIO.Scanner
-
public class Scanner extends BacktrackScanner
ABacktrackScannerextended with convenience methods for parsing common things like integers and identifiers. Compared to ajava.util.Scanner, it has the ability to peek() at the next character on the input and the ability to read its input from multiple Readers, which may be added on the fly. Beyond this, it can also do arbitary lookahead and rollback of the input stream using the mark(), accept(), and abort() methods fromBacktrackScanner. Generally, all methods parse input starting at the current position, and throwUnexpectedInputif the expected input is not found. If an exception is thrown, the current input position is left unchanged.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class easyIO.BacktrackScanner
BacktrackScanner.Location
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconsume(java.lang.String s)Scan past the specified string.voiddigits()Scan one or more digits.voideol()Scan to the end of the current line or to the end of the input, whichever is first.voidfloatingPoint()Scan a floating-point number.voididentifier()Scan an identifier ala Java.voidinteger()Scan past an integer constant.voidnewline()Scan past a optional carriage return character and a newline character.charnextDigit()Scan past and return the next character if it is a digit.doublenextDouble()Scan past a floating-point constant and return its value as adoublejava.lang.StringnextIdentifier()Scan past and return an identifier.intnextInt()Scan past an integer constant and return its value.java.lang.StringnextLine()Scan past and return all text from the current position to the next newline character.voidoptDigits()Scan past all digits at the current posn, if any.voidtrailingWhitespace()Scan past any whitespace up to the end of the line, the end of the file, or the next non-whitespace character.voidwhitespace()Scan past any whitespace.
-
-
-
Constructor Detail
-
Scanner
public Scanner()
-
Scanner
public Scanner(java.io.Reader r, java.lang.String name)Create scanner that reads from source inputr, calling the sourcename.
-
Scanner
public Scanner(java.lang.String filename) throws java.io.FileNotFoundExceptionCreate scanner that reads from file namedfilename. To read directly from a string, use aStringReader.- Throws:
java.io.FileNotFoundException- See Also:
StringReader
-
-
Method Detail
-
whitespace
public void whitespace()
Scan past any whitespace.
-
consume
public void consume(java.lang.String s) throws UnexpectedInputScan past the specified string.- Throws:
UnexpectedInput- if anything other than the expected string is encountered, leaving the scanner at the position where an unexpected character is reached.
-
nextDigit
public char nextDigit() throws UnexpectedInputScan past and return the next character if it is a digit.- Throws:
UnexpectedInput
-
optDigits
public void optDigits()
Scan past all digits at the current posn, if any.
-
integer
public void integer() throws UnexpectedInputScan past an integer constant.- Throws:
UnexpectedInput- if the characters at the current position are not a integer literal.
-
floatingPoint
public void floatingPoint() throws UnexpectedInputScan a floating-point number.- Throws:
UnexpectedInput- if the characters at the current position are not a floating-point literal.
-
digits
public void digits() throws UnexpectedInputScan one or more digits.- Throws:
UnexpectedInput- if the next character is not a digit.
-
identifier
public void identifier() throws UnexpectedInputScan an identifier ala Java.- Throws:
UnexpectedInput- if the next characters are not an identifier.
-
nextInt
public int nextInt() throws UnexpectedInputScan past an integer constant and return its value.- Throws:
UnexpectedInput- if the characters following the current position are not an integer literal.
-
nextDouble
public double nextDouble() throws UnexpectedInputScan past a floating-point constant and return its value as adouble- Throws:
UnexpectedInput- if the characters following the current position are not a legal representation of a double literal.
-
nextLine
public java.lang.String nextLine() throws UnexpectedInputScan past and return all text from the current position to the next newline character.- Throws:
UnexpectedInput- if there is no terminated line after the current position.
-
nextIdentifier
public java.lang.String nextIdentifier() throws UnexpectedInputScan past and return an identifier.- Throws:
UnexpectedInput- if the characters at the current position are not a legal Java identifier.
-
newline
public void newline() throws UnexpectedInputScan past a optional carriage return character and a newline character.- Throws:
UnexpectedInput- if the next characters are neither "\r\n" nor "\n".
-
eol
public void eol()
Scan to the end of the current line or to the end of the input, whichever is first.
-
trailingWhitespace
public void trailingWhitespace()
Scan past any whitespace up to the end of the line, the end of the file, or the next non-whitespace character.
-
-