org.extex.unit.tex.macro.util
Class MacroPattern

java.lang.Object
  extended by org.extex.scanner.type.tokens.Tokens
      extended by org.extex.unit.tex.macro.util.MacroPattern
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Token>, FixedTokens

public class MacroPattern
extends Tokens

This class provides a container for the pattern of a macro.

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

Field Summary
static MacroPattern EMPTY
          The constant EMPTY contains the empty macro pattern.
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
 
Constructor Summary
protected MacroPattern(CodeToken cs)
          Creates a new object.
protected MacroPattern(Tokens tokens)
          Creates a new object.
 
Method Summary
protected  void compile(Context context)
          Compile the pattern into a list of function elements to perform the operations required for doing the matching.
static MacroPattern getPattern(Context context, TokenSource source, boolean longP, CodeToken cs)
          Parse a pattern specification.
protected static Tokens getTokenOrBlock(Context context, TokenSource source, Typesetter typesetter, CodeToken cs)
          Get a single token or a block if the first token is a LeftBraceToken.
 Tokens[] match(Context context, TokenSource source, Typesetter typesetter, boolean notLong, ArgumentMatchingObserver observer)
          Match the pattern of this macro with the next tokens from the token source.
protected  void setArity(int arity)
          Setter for the arity.
 java.lang.String toString()
          Return a String, which show all tokens in the list.
 
Methods inherited from class org.extex.scanner.type.tokens.Tokens
add, add, clear, equals, get, hashCode, insert, iterator, length, pop, push, removeFirst, removeLast, show, toString, toString, toText, toText
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final MacroPattern EMPTY
The constant EMPTY contains the empty macro pattern. This can be used in a poor man's factory.


serialVersionUID

protected static final long serialVersionUID
The constant serialVersionUID contains the id for serialization.

See Also:
Constant Field Values
Constructor Detail

MacroPattern

protected MacroPattern(CodeToken cs)
Creates a new object.

Parameters:
cs - the name of the invoking macro

MacroPattern

protected MacroPattern(Tokens tokens)
Creates a new object.

Parameters:
tokens - the tokens contained
Method Detail

getPattern

public static MacroPattern getPattern(Context context,
                                      TokenSource source,
                                      boolean longP,
                                      CodeToken cs)
                               throws HelpingException
Parse a pattern specification.

Parameters:
context - the processor context
source - the source for new tokens
longP - indicator for the long flag
cs - the macro being defined
Returns:
the tokens read
Throws:
HelpingException - in case of an error

getTokenOrBlock

protected static Tokens getTokenOrBlock(Context context,
                                        TokenSource source,
                                        Typesetter typesetter,
                                        CodeToken cs)
                                 throws HelpingException,
                                        TypesetterException
Get a single token or a block if the first token is a LeftBraceToken.

Parameters:
context - the processor context
source - the source for new tokens
typesetter - the typesetter
cs - the control sequence for error reporting
Returns:
the tokens accumulated
Throws:
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter

compile

protected void compile(Context context)
                throws HelpingException
Compile the pattern into a list of function elements to perform the operations required for doing the matching.

Parameters:
context - the interpreter context
Throws:
HelpingException - in case of an error

match

public Tokens[] match(Context context,
                      TokenSource source,
                      Typesetter typesetter,
                      boolean notLong,
                      ArgumentMatchingObserver observer)
               throws HelpingException,
                      TypesetterException
Match the pattern of this macro with the next tokens from the token source. As a result the matching arguments are stored in an array of Tokens. This array is returned.

Note that the first argument – denoted #1 – can be found at position 0 of the array.

Parameters:
context - the processor context
source - the source for new tokens
typesetter - the typesetter
notLong -
observer - the observer for argument matching events
Returns:
a new array of parameters which have been found during the matching. Note that some of the elements of the array might be null.
Throws:
HelpingException - in case of an error during the matching
TypesetterException - in case of an error in the typesetter

setArity

protected void setArity(int arity)
Setter for the arity.

Parameters:
arity - the new arity

toString

public java.lang.String toString()
Return a String, which show all tokens in the list.

Specified by:
toString in interface FixedTokens
Overrides:
toString in class Tokens
Returns:
a String, which show all tokens in the list
See Also:
Tokens.toString()