mark.core.text
Class Scanner

java.lang.Object
  |
  +--mark.core.text.Scanner
Direct Known Subclasses:
HTMLWordScanner, NonwhiteScanner, WordAndPunctuationScanner

public abstract class Scanner
extends java.lang.Object

A Scanner returns tokens from a character source until there are no tokens left.


Constructor Summary
Scanner()
           
 
Method Summary
static Scanner forName(java.lang.String n, java.io.Reader r)
          Given a scanner class' name and a java.io.Reader token source, returns an instance of the scanner set up to read from the given token source.
abstract  Token getNextToken()
           
 Token nextToken()
          Returns the next token or null if there are no tokens left.
protected  java.lang.String nextTokenString()
          Returns a string representation of the next token.
 void pushBack(Token t)
          Places the given token at the front of the Scanner's token queue.
 void readTokens(boolean lowerCase, java.util.Collection c)
          Adds all token strings from the given token source to the given collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scanner

public Scanner()
Method Detail

getNextToken

public abstract Token getNextToken()

nextToken

public Token nextToken()
                throws java.lang.Exception
Returns the next token or null if there are no tokens left.

Returns:
the next token or null if there are no tokens left.
Throws:
java.lang.Exception - if something goes wrong.

pushBack

public void pushBack(Token t)
Places the given token at the front of the Scanner's token queue.

Parameters:
t - the token to push back.

nextTokenString

protected java.lang.String nextTokenString()
                                    throws java.lang.Exception
Returns a string representation of the next token. If there are no tokens, returns null.

Returns:
the string representation of the next token or null if there aren't any tokens.
Throws:
java.lang.Exception - if something goes wrong.

readTokens

public void readTokens(boolean lowerCase,
                       java.util.Collection c)
                throws java.lang.Exception
Adds all token strings from the given token source to the given collection.

Parameters:
lowerCase - whether to convert to lower-case.
c - the Collection.
Throws:
java.lang.Exception - if something goes wrong.

forName

public static Scanner forName(java.lang.String n,
                              java.io.Reader r)
                       throws java.lang.Exception
Given a scanner class' name and a java.io.Reader token source, returns an instance of the scanner set up to read from the given token source.

Parameters:
n - the name of the scanner class.
r - a java.io.Reader the token source.
Throws:
java.lang.Exception - if something goes wrong.