org.inria.ns.reflex.util
Class TrackableReaderScanner

java.lang.Object
  extended by org.inria.ns.reflex.util.Scanner
      extended by org.inria.ns.reflex.util.ReaderScanner
          extended by org.inria.ns.reflex.util.TrackableReaderScanner
All Implemented Interfaces:
Trackable

public class TrackableReaderScanner
extends ReaderScanner
implements Trackable

A scanner that tracks the current line and column.

Author:
Philippe Poulard

Constructor Summary
TrackableReaderScanner(Reader reader)
          Create a new scanner.
TrackableReaderScanner(Reader reader, int line, int column)
          Create a new scanner with an initial position.
 
Method Summary
 void cancel()
          Cancel the current mark.
 void consume()
          Consume the characters read so far.
 int getColumnNumber()
          Return the current column number.
 int getLineNumber()
          Return the current line number.
 void mark(int limit)
          Mark the current position.
 void read()
          Read a character.
 
Methods inherited from class org.inria.ns.reflex.util.ReaderScanner
getRemainder, getRemainderString
 
Methods inherited from class org.inria.ns.reflex.util.Scanner
getPosition, getSourceIndex, hasNext, hasNextChar, hasNextChar, hasNextString, lookAhead, nextChar, nextChar, nextNumber, nextNumber, nextObject, nextString, nextString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TrackableReaderScanner

public TrackableReaderScanner(Reader reader)
                       throws IOException
Create a new scanner.

Parameters:
reader - The input to read.
Throws:
IOException - When an I/O error occur.

TrackableReaderScanner

public TrackableReaderScanner(Reader reader,
                              int line,
                              int column)
                       throws IOException
Create a new scanner with an initial position.

Parameters:
reader - The input to read.
line - The initial line number.
column - The initial column number.
Throws:
IOException - When an I/O error occur.
Method Detail

getColumnNumber

public int getColumnNumber()
Return the current column number.

Specified by:
getColumnNumber in interface Trackable
Returns:
The current column number
See Also:
Trackable.getColumnNumber()

getLineNumber

public int getLineNumber()
Return the current line number.

Specified by:
getLineNumber in interface Trackable
Returns:
The current line number.
See Also:
Trackable.getLineNumber()

read

public void read()
          throws IOException
Read a character. The column and line are updated.

Overrides:
read in class ReaderScanner
Throws:
IOException - When an I/O error occur.
See Also:
#hasNextChar(char), Scanner.nextChar(), Scanner.lookAhead()

mark

public void mark(int limit)
          throws IOException
Mark the current position. The current column and line are saved.

Overrides:
mark in class ReaderScanner
Parameters:
limit - The max number of characters than can be buffered
Throws:
IOException - When an I/O error occur.
See Also:
Reader.mark(int)

cancel

public void cancel()
            throws IOException
Cancel the current mark. The previous column and line are restored.

Overrides:
cancel in class ReaderScanner
Throws:
IOException - When an I/O error occur.
See Also:
ReaderScanner.mark(int)

consume

public void consume()
             throws IOException
Consume the characters read so far. The previous column and line are removed.

Overrides:
consume in class ReaderScanner
Throws:
IOException - When an I/O error occur.
See Also:
ReaderScanner.mark(int)