Package easyIO
Class BacktrackScanner
- java.lang.Object
- 
- easyIO.BacktrackScanner
 
- 
- Direct Known Subclasses:
- Scanner
 
 public class BacktrackScanner extends java.lang.ObjectA scanner class that, unlikejava.util.Scanner, supports arbitrary lookahead and backtracking. The caller can usemark()to set some number of marks in the input stream, thenaccept()to erase the previous mark orabort()to roll back to (and erase) the previous mark. The marks function as a stack of previous points in the input. The class also allows reading a stream that is spread across multiple input sources, and keeps track of the current source, current line number, and current position within the line. Arbitrary lookahead is allowed, but the space consumed by a scanner is proportional to the number of chars between the first mark and last lookahead position.- See Also:
- easyIO.Scanner
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classBacktrackScanner.LocationAn input character along with information about the source of the character, and its line number and position within the line.
 - 
Constructor SummaryConstructors Constructor Description BacktrackScanner()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Roll the input position back to the most recent mark, and erase the mark, effectively restarting scanning from that position.voidaccept()Effect: Erase the previous mark from the input, effectively accepting all input up to the current position.voidadvance()Advance past the next character, if any.voidappendSource(java.io.Reader r, java.lang.String name)Add r to the input stream after existing inputs.intcharPos()voidclose()intdepth()The current number of marks.voiddump(java.lang.StringBuilder w)Dump the state of the scanner to w in a human-readable form.BacktrackScanner.LocationgetMarkLocation()Location in input source of the last mark.java.lang.StringgetToken()Return a string containing the characters from the most recent mark to the current position.booleanhasNext()Whether there is a character ahead in input.voidincludeSource(java.io.Reader r, java.lang.String name)Add r to the input stream ahead of any existing inputs.booleaninvariant()intlineNo()BacktrackScanner.Locationlocation()Location in input source of the current position.voidmark()Add a mark at the current position.charnext()Read the next character from the stream.intpeek()The next character ahead in the input.java.lang.Stringsource()voidstring(java.lang.String s)Scan the characters of string s from the input.java.lang.StringtoString()
 
- 
- 
- 
Method Detail- 
invariantpublic boolean invariant() 
 - 
dumppublic void dump(java.lang.StringBuilder w) Dump the state of the scanner to w in a human-readable form.
 - 
closepublic void close() throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
sourcepublic java.lang.String source() 
 - 
lineNopublic int lineNo() 
 - 
charPospublic int charPos() 
 - 
includeSourcepublic void includeSource(java.io.Reader r, java.lang.String name)Add r to the input stream ahead of any existing inputs.
 - 
appendSourcepublic void appendSource(java.io.Reader r, java.lang.String name)Add r to the input stream after existing inputs.
 - 
hasNextpublic boolean hasNext() Whether there is a character ahead in input.
 - 
peekpublic int peek() The next character ahead in the input. Equivalent to begin(); c = next(); abort(); return c;
 - 
locationpublic BacktrackScanner.Location location() Location in input source of the current position.
 - 
getMarkLocationpublic BacktrackScanner.Location getMarkLocation() Location in input source of the last mark.
 - 
markpublic void mark() Add a mark at the current position.
 - 
acceptpublic void accept() Effect: Erase the previous mark from the input, effectively accepting all input up to the current position.
 - 
depthpublic int depth() The current number of marks. Exposed for use in assertions, so client code can check that matching mark()...accept() calls occur at the same depth.
 - 
getTokenpublic java.lang.String getToken() Return a string containing the characters from the most recent mark to the current position.
 - 
abortpublic void abort() Roll the input position back to the most recent mark, and erase the mark, effectively restarting scanning from that position.
 - 
advancepublic void advance() Advance past the next character, if any. Do nothing if at end of input.
 - 
stringpublic void string(java.lang.String s) throws UnexpectedInputScan the characters of string s from the input.- Throws:
- UnexpectedInput- if something other than the expected characters are encountered.
 
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 
- 
 
-