📄 scan.java
字号:
package lolo;import java.io.IOException;import java.io.Serializable;/** The abstract base class for recognizer classes. * * @author <a href="http://www.inf.uos.de/bernd" target="_blank">Bernd Kühl</a> (<a href="mailto:bernd@informatik.uni-osnabrueck.de">bernd@informatik.uni-osnabrueck.de</a>) */public abstract class Scan implements Serializable { /** Resets this instance. */ public abstract void reset(); /** The action object; can be <tt>null</tt> for no action. * * @serial if action is serializable and not <tt>null</tt>. * @see lolo.Scan.Action */ protected transient Action action; /** Returns the action object. * * @return the action object. * @see lolo.Scan.Action */ public Action getAction() { return action; } /** Sets the action object. * * @param action the new action object. * @see lolo.Scan.Action * @return <tt>this</tt> for cascading method calls. */ public Scan setAction(Action action) { this.action = action; return this; } /** If <tt>action</tt> is not <tt>null</tt>, then the action method is called for this object. * * @param buffer the character buffer holding the characters of the symbol. * @param off offset into the buffer. * @param len number of characters for the symbol. * @see lolo.Scan#action */ public void action(char [] buffer, int off, int len) { if (action != null) action.action(this, buffer, off, len); } /** Action code for a recognized symbols is represented by <tt>Action</tt> objects. * * @author <a href="http://www.inf.uos.de/bernd" target="_blank">Bernd Kühl</a> (<a href="mailto:bernd@informatik.uni-osnabrueck.de">bernd@informatik.uni-osnabrueck.de</a>) * @see lolo.Scan#getAction * @see lolo.Scan#setAction(lolo.Scan.Action) * @see lolo.Scan#action */ public interface Action { /** Called to perform action code for a scanned symbol. * * @param sender the symbol scanner object as sender of this method. * @param buffer the character buffer holding the characters of the symbol. * @param off offset into the buffer. * @param len number of characters for the symbol. */ public void action(Scan sender, char [] buffer, int off, int len); } /** Marks if the symbol will be ignored. */ protected boolean ignore; /** Sets the ignore state. * * @param ignore the new ignore state. * @return <tt>this</tt> for cascading method calls. */ public Scan setIgnore(boolean ignore) { this.ignore = ignore; return this; } /** Returns the ignore state. * * @return the ignore state. */ public boolean getIgnore() { return ignore; } /** Subclasses have to implement this method to indicate whether some * other object is "equal to" this one. * * @return <tt>true</tt> if this object is the same as the argument; <tt>false</tt> otherwise. */ public abstract boolean equals(Object o); /** Subclasses have to implement this method to return a hash code value * for the receiver. * * @return a hash code value for this object. */ public abstract int hashCode(); /** Called by a <tt>Scanner</tt> for every new character. * * @return a <tt>State</tt> object to signal whether more characters are wanted and whether a symbol is found. * @see lolo.Scan.State * @see lolo.Scanner */ public abstract State nextChar(char ch); /** A simple class to mark the result for <tt>nextChar()</tt>. * * @author <a href="http://www.inf.uos.de/bernd" target="_blank">Bernd Kühl</a> (<a href="mailto:bernd@informatik.uni-osnabrueck.de">bernd@informatik.uni-osnabrueck.de</a>) * @see lolo.Scan#nextChar(char) */ public static class State implements Serializable { /** Creates a State object. */ public State() {} /** Sets the object to signal whether more characters are wanted and whether a symbol was found. * * @param more The <tt>Scan</tt> instance wants more characters? * @param found The <tt>Scan</tt> instance just found a symbol? * @return <tt>this</tt>. */ public State set(boolean more, boolean found) { this.more = more; this.found = found; return this; } /** The <tt>Scan</tt> instance wants more characters? */ public boolean more; /** The <tt>Scan</tt> instance just found a symbol? */ public boolean found; /** Returns a string representation of the object. * * @return a string representation of the object. */ public String toString() { return "State[more: "+more+",found: "+found+"]"; } } /** Deserializes a <tt>Scan</tt> object and (optional) the serialized action object. */ private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); if (stream.readBoolean()) action = (Action) stream.readObject(); } /** Serializes the <tt>Scan</tt> object and it's action object (if that is serializable). */ private void writeObject(java.io.ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); boolean b = action != null && action instanceof Serializable; stream.writeBoolean(b); if (b) stream.writeObject(action); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -