Send bugs or comments to Bernd Kühl (bernd@informatik.uni-osnabrueck.de)

lolo
Class Scanner

java.lang.Object
  |
  +--lolo.Scanner
All Implemented Interfaces:
java.io.Serializable

public class Scanner
extends java.lang.Object
implements java.io.Serializable

A Scanner collects Scan objects to maintain a lexical scanner. The characters are read from an Input object.

A Scanner can be serialized to be reused.

Author:
Bernd Kühl (bernd@informatik.uni-osnabrueck.de)
See Also:
Mux, Scan, Input, scan(Input), Serialized Form

Inner Class Summary
static class Scanner.IllegalCharacterException
          An IllegalCharacterException is thrown, when no Scan instance matches the current character.
 
Field Summary
 boolean debug
          debug mode?
protected  int max
          Indexes in scans.
protected  int next
          Indexes in scans.
protected  boolean packed
          Marks if this Scanner is packed.
protected  Scan[] scans
          Array of all Scan objects.
 Scan[] table
          Array holding for every character-index a Scan or Mux object.
protected  boolean unicode
          Unicode (or ASCII) mode?
 
Constructor Summary
Scanner()
          Constructs an empty Scanner.
Scanner(Scan scan)
          Constructs a Scanner managing one Scan instance.
Scanner(Scan[] scans)
          Constructs a Scanner managing many Scan instances.
 
Method Summary
 boolean add(Scan scan)
          Adds a Scan instance to this Scanner.
 boolean add(Scan[] scans)
          Adds all elements of a Scan array to this Scanner.
 boolean contains(Scan scan)
          Returns if this Scanner contains the Scan instance.
protected  void enter(int index, Scan scan)
          Enters scan at index index into the table.
 boolean getUnicode()
          Returns if the current mode is Unicode.
 void pack()
          Packs the table with Scan or Mux objects.
 boolean packed()
          Returns if this Scanner is packed.
 boolean remove(Scan scan)
          Removes a Scan instance to this Scanner.
 Scan scan(Input input)
          Finds and returns the next winning Scan object or null at EOF.
 void setUnicode(boolean unicode)
          Set Unicode (or ASCII) mode mode.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scans

protected Scan[] scans
Array of all Scan objects.
See Also:
Scan

next

protected int next
Indexes in scans.

max

protected int max
Indexes in scans.

packed

protected boolean packed
Marks if this Scanner is packed.
See Also:
pack()

table

public transient Scan[] table
Array holding for every character-index a Scan or Mux object.
See Also:
Mux, Scan

debug

public boolean debug
debug mode?

unicode

protected boolean unicode
Unicode (or ASCII) mode?
Constructor Detail

Scanner

public Scanner()
Constructs an empty Scanner.

Scanner

public Scanner(Scan scan)
Constructs a Scanner managing one Scan instance.
See Also:
Scan

Scanner

public Scanner(Scan[] scans)
Constructs a Scanner managing many Scan instances.
See Also:
Scan
Method Detail

add

public boolean add(Scan scan)
            throws java.lang.IllegalArgumentException
Adds a Scan instance to this Scanner.
Parameters:
scan - the added recognizer.
Throws:
java.lang.IllegalArgumentException - if the argument is null.
See Also:
Scan

add

public boolean add(Scan[] scans)
            throws java.lang.IllegalArgumentException
Adds all elements of a Scan array to this Scanner.
Parameters:
scans - the added recognizers.
Throws:
java.lang.IllegalArgumentException - if the argument or the elements of the argument are null.
See Also:
Scan

remove

public boolean remove(Scan scan)
Removes a Scan instance to this Scanner.
See Also:
Scan

contains

public boolean contains(Scan scan)
Returns if this Scanner contains the Scan instance. The check is done by using equals().
Returns:
if this Scanner contains the Scan instance.
See Also:
Scan

packed

public boolean packed()
Returns if this Scanner is packed.
Returns:
if this Scanner is packed.

pack

public void pack()
Packs the table with Scan or Mux objects.
See Also:
Mux, Scan

enter

protected void enter(int index,
                     Scan scan)
Enters scan at index index into the table. This may creates a Mux object.
Parameters:
index - index into the table for scan.
scan - the new Scan object for table index index.
See Also:
Mux, Scan

scan

public Scan scan(Input input)
          throws Scanner.IllegalCharacterException,
                 java.io.IOException
Finds and returns the next winning Scan object or null at EOF.
Parameters:
the - character input source.
Returns:
the winning Scan object or null at EOF.
Throws:
Scanner.IllegalCharacterException - if no symbol was found.
java.io.IOException - if an I/O error occured.

setUnicode

public void setUnicode(boolean unicode)
Set Unicode (or ASCII) mode mode.
Parameters:
the - new mode.

getUnicode

public boolean getUnicode()
Returns if the current mode is Unicode.
Returns:
if the current mode is Unicode.

Send bugs or comments to Bernd Kühl (bernd@informatik.uni-osnabrueck.de)