de.dante.extex.interpreter.primitives.conditional
Class AbstractIf

java.lang.Object
  extended byde.dante.extex.interpreter.type.AbstractCode
      extended byde.dante.extex.interpreter.primitives.conditional.AbstractIf
All Implemented Interfaces:
Code, ExpandableCode, Localizable, java.io.Serializable
Direct Known Subclasses:
If, Ifcase, Ifcat, Ifcsname, Ifdefined, Ifdim, Ifeof, Iffalse, Iffontchar, Ifhbox, Ifhmode, Ifinner, Ifmmode, Ifnum, Ifodd, Ifscaled, Iftrue, Ifvbox, Ifvmode, Ifvoid, Ifx

public abstract class AbstractIf
extends AbstractCode
implements ExpandableCode

This is the abstract base class for all ifs.

If you want to implement an if-like primitive you should derive it from this class. All you have to do is to implement the method conditional(). Here you define the expression evaluated to determine whether the if or the else branch should be taken.

Version:
$Revision: 1.25 $
Author:
Gerd Neugebauer
See Also:
Serialized Form

Field Summary
 
Fields inherited from class de.dante.extex.interpreter.type.AbstractCode
serialVersionUID
 
Constructor Summary
AbstractIf(java.lang.String name)
          Creates a new object.
 
Method Summary
protected abstract  boolean conditional(Context context, TokenSource source, Typesetter typesetter)
          This method computes the boolean value of the conditional.
 void execute(Flags prefix, Context context, TokenSource source, Typesetter typesetter)
          This method takes the first token and executes it.
 void expand(Flags prefix, Context context, TokenSource source, Typesetter typesetter)
          This method takes the first token and expands it.
protected static Localizer getMyLocalizer()
          Getter for the localizer.
 boolean isIf()
          The ifs are characterized by the return value true of this method.
protected static boolean skipToElseOrFi(Context context, TokenSource source)
          Skip to the next matching \fi or \else Token counting the intermediate \ifs and \fis.
 
Methods inherited from class de.dante.extex.interpreter.type.AbstractCode
enableLocalization, getLocalizer, getName, isOuter, printable, printableControlSequence, readResolve, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractIf

public AbstractIf(java.lang.String name)
Creates a new object.

Parameters:
name - the name for debugging
Method Detail

getMyLocalizer

protected static Localizer getMyLocalizer()
Getter for the localizer.

Returns:
the localizer

skipToElseOrFi

protected static boolean skipToElseOrFi(Context context,
                                        TokenSource source)
                                 throws InterpreterException
Skip to the next matching \fi or \else Token counting the intermediate \ifs and \fis.

This method implements to the absorption of tokens at high speed.

Parameters:
context - the interpreter context
source - the source for new tokens
Returns:
true if a matching \else has been found; otherwise return false if a matching \fi has been found
Throws:
InterpreterException - in case of en error

conditional

protected abstract boolean conditional(Context context,
                                       TokenSource source,
                                       Typesetter typesetter)
                                throws InterpreterException
This method computes the boolean value of the conditional. If the result is true then the then branch is expanded and the else branch is skipped. Otherwise the then branch is skipped and the else branch is expanded.

Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
Returns:
the boolean value
Throws:
InterpreterException - in case of en error

execute

public void execute(Flags prefix,
                    Context context,
                    TokenSource source,
                    Typesetter typesetter)
             throws InterpreterException
Description copied from interface: Code
This method takes the first token and executes it. The result is placed on the stack. This operation might have side effects. To execute a token it might be necessary to consume further tokens.

Specified by:
execute in interface Code
Overrides:
execute in class AbstractCode
Throws:
InterpreterException
See Also:
Code.execute( de.dante.extex.interpreter.Flags, de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter)

expand

public void expand(Flags prefix,
                   Context context,
                   TokenSource source,
                   Typesetter typesetter)
            throws InterpreterException
Description copied from interface: ExpandableCode
This method takes the first token and expands it. The result is placed on the stack. This means that expandable code does one step of expansion and puts the result on the stack. To expand a token it might be necessary to consume further tokens.

Specified by:
expand in interface ExpandableCode
Parameters:
prefix - the prefix flags controlling the expansion
context - the interpreter context
source - the token source
typesetter - the typesetter
Throws:
InterpreterException - in case of an error
See Also:
ExpandableCode.expand( de.dante.extex.interpreter.Flags, de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter)

isIf

public boolean isIf()
The ifs are characterized by the return value true of this method. Thus the overwritten method returning the constant is provided in this abstract base class.

Specified by:
isIf in interface Code
Overrides:
isIf in class AbstractCode
See Also:
Code.isIf()