de.dante.extex.interpreter.max
Class Moritz

java.lang.Object
  extended byde.dante.extex.interpreter.max.Max
      extended byde.dante.extex.interpreter.max.Moritz
All Implemented Interfaces:
CommandObservable, Configurable, EofObservable, ErrorObservable, ExpandMacroObservable, ExpandObservable, Interpreter, LoadObservable, Localizable, LogEnabled, OpenFileObservable, OpenReaderObservable, OpenStringObservable, OutputStreamConsumer, PopObservable, PushObservable, StartObservable, StopObservable, StreamCloseObservable, TokenSource, TokenVisitor
Direct Known Subclasses:
StringSource

public class Moritz
extends Max
implements TokenSource, Configurable, StreamCloseObservable, PopObservable, PushObservable, EofObservable, OpenFileObservable, OpenStringObservable, OpenReaderObservable

This class provides the layer above the input streams and the tokenizer. It has additional methods for parsing. The details of the token streams are mostly hidden.

This class is the companion to Max. (The name is a joke for friends of Wilhelm Busch)

The Integer Register \maxRegister

The integer register \maxRegister controls the scanning of register names. The following interpretation for the values is used:

The integer register \max.register is not affected by grouping. This means that any assignment is always global.

The primitive \maxRegister is usually defined in the name space system thus you have to take special means to access it.

Examples

   \namespace{system}\maxRegister=1024\namespace{}  

Version:
$Revision: 1.106 $
Author:
Gerd Neugebauer, Michael Niedermair

Constructor Summary
Moritz()
          Creates a new object.
 
Method Summary
 void addStream(TokenStream theStream)
          Put a given stream on top of the stream stack.
 void closeAllStreams(Context context)
          All input streams are closed and not further Token is available for processing.
 void closeNextFileStream(Context context)
          Close all streams on the stack until a file stream is found.
 Box getBox(Flags flags, Context context, Typesetter typesetter)
          Parse the specification of a box.
 CodeToken getControlSequence(Context context)
          Get the next token from the token stream and check that it is a control sequence or active character.
 Font getFont(Context context, java.lang.String primitive)
          Parse the specification of a font.
 boolean getKeyword(Context context, java.lang.String s)
          Scan the expanded token stream for a sequence of letter tokens.
 Token getLastToken()
          Getter for the token just previously read from the token source.
 Locator getLocator()
          Getter for the locator.
 Token getNonSpace(Context context)
          Get the next token which has not the category code SPACE.
 long getNumber(Token token)
          Scan a number with a given first token.
 void getOptionalEquals(Context context)
          Skip spaces and if the next non-space character is an equal sign skip it as well and all spaces afterwards.
 Token getToken(Context context)
          Get the next token from the input streams.
 Tokens getTokens(Context context, TokenSource source, Typesetter typesetter)
          Get the next tokens form the input streams between { and }.
 TokenStreamFactory getTokenStreamFactory()
          Getter for the token stream factory.
 void push(Token token)
          Push back a token onto the input stream for subsequent reading.
 void push(Token[] tokens)
          Push back a list of tokens onto the input stream for subsequent reading.
 void push(Tokens tokens)
          Push back a list of tokens onto the input stream for subsequent reading.
 void registerObserver(EofObserver observer)
          Add an observer for the eof event.
 void registerObserver(OpenFileObserver observer)
          Register an expand observer for later use.
 void registerObserver(OpenReaderObserver observer)
          Register an open reader observer for later use.
 void registerObserver(OpenStringObserver observer)
          Register an expand observer for later use.
 void registerObserver(PopObserver observer)
          Add an observer for the pop event.
 void registerObserver(PushObserver observer)
          Add an observer for the push event.
 void registerObserver(StreamCloseObserver observer)
          Register an stream close observer for later use.
 UnicodeChar scanCharacterCode(Context context, Typesetter typesetter, java.lang.String primitive)
          This method scans a character code.
 Token scanNonSpace(Context context)
          Scan the input for the next token which has not the catcode SPACE.
 long scanNumber(Context context)
          Scan the input stream for tokens making up a number, this is a sequence of digits with category code OTHER.
 long scanNumber(Context context, Token token)
          Scan the input stream for tokens making up a number, i.e.
 java.lang.String scanRegisterName(Context context, TokenSource source, Typesetter typesetter, java.lang.String primitive)
          Scan the input streams for an entity to denote a register name.
 Token scanToken(Context context)
          Expand tokens from the input stream until an not expandable token is found.
 Tokens scanTokens(Context context, boolean reportUndefined, boolean ignoreUndefined, java.lang.String primitive)
          Get the next expanded token form the input streams between { and }.
 java.lang.String scanTokensAsString(Context context, java.lang.String primitive)
          Get the next expanded token form the input streams between a left brace character (usually {) and a right brace character (usually }) and convert it to a String.
 Tokens scanUnprotectedTokens(Context context, boolean reportUndefined, boolean ignoreUndefined, java.lang.String primitive)
          Get the next expanded token form the input streams between { and }.
 void setTokenStreamFactory(TokenStreamFactory factory)
          Setter for the token stream factory.
 void skipSpace()
          Skip spaces and check whether any tokens are left.
 void update(java.lang.String name, java.lang.String text)
          Send the string to the named observer.
 
Methods inherited from class de.dante.extex.interpreter.max.Max
configure, enableLocalization, enableLogging, execute, executeGroup, expand, expand, expandUnproteced, getContext, getErrorHandler, getInteraction, getLocalizer, getLogger, getTypesetter, initializeDate, loadFormat, loadUnit, registerObserver, registerObserver, registerObserver, registerObserver, registerObserver, registerObserver, registerObserver, run, run, setContext, setErrorHandler, setFontFactory, setInteraction, setJobname, setOutputStreamFactory, setTypesetter, visitActive, visitCr, visitEscape, visitLeftBrace, visitLetter, visitMacroParam, visitMathShift, visitOther, visitRightBrace, visitSpace, visitSubMark, visitSupMark, visitTabMark
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.dante.extex.interpreter.TokenSource
execute, executeGroup, expand
 
Methods inherited from interface de.dante.util.framework.configuration.Configurable
configure
 

Constructor Detail

Moritz

public Moritz()
Creates a new object.

Method Detail

addStream

public void addStream(TokenStream theStream)
Put a given stream on top of the stream stack. The reading occurs on this new stream before resorting to the previous streams.

Specified by:
addStream in interface TokenSource
Parameters:
theStream - the new stream to read from
See Also:
TokenSource.addStream( de.dante.extex.scanner.stream.TokenStream)

closeAllStreams

public void closeAllStreams(Context context)
                     throws InterpreterException
Description copied from interface: TokenSource
All input streams are closed and not further Token is available for processing. This normally means that the interpreter is forced to terminate more or less gracefully.

Specified by:
closeAllStreams in interface TokenSource
Parameters:
context - the interpreter context
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.closeAllStreams( de.dante.extex.interpreter.context.Context)

closeNextFileStream

public void closeNextFileStream(Context context)
                         throws InterpreterException
Description copied from interface: TokenSource
Close all streams on the stack until a file stream is found. This file stream is closed as last one. The other streams are left unchanged. If no file stream is found the all streams are closed and none is left.

Specified by:
closeNextFileStream in interface TokenSource
Parameters:
context - the interpreter context
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.closeNextFileStream( de.dante.extex.interpreter.context.Context)

getBox

public Box getBox(Flags flags,
                  Context context,
                  Typesetter typesetter)
           throws InterpreterException
Description copied from interface: TokenSource
Parse the specification of a box.

This method parses the following syntactic entity:

A Box

   ⟨box⟩ 
During the parsing the flags should be reset to something uncritical and restored at the end.

Specified by:
getBox in interface TokenSource
Parameters:
flags - the flags to be restored
context - the interpreter context
typesetter - the typesetter to use
Returns:
the box gathered
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.getBox( de.dante.extex.interpreter.Flags, de.dante.extex.interpreter.context.Context, de.dante.extex.typesetter.Typesetter)

getControlSequence

public CodeToken getControlSequence(Context context)
                             throws InterpreterException
Get the next token from the token stream and check that it is a control sequence or active character. At the end of all input streams the control sequence "inaccessible" is inserted and an exception is thrown. Thus this method will never return null.

Specified by:
getControlSequence in interface TokenSource
Parameters:
context - the interpreter context
Returns:
the token read
Throws:
InterpreterException - in case that the token stream is at its end or that the token read is not a control sequence token

getFont

public Font getFont(Context context,
                    java.lang.String primitive)
             throws InterpreterException
Description copied from interface: TokenSource
Parse the specification of a font.

This method parses the following syntactic entity:

A Font

   ⟨font⟩ 

Specified by:
getFont in interface TokenSource
Parameters:
context - the interpreter context
primitive - the name of the primitive for error messages
Returns:
a font specification
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.getFont( de.dante.extex.interpreter.context.Context, java.lang.String)

getKeyword

public boolean getKeyword(Context context,
                          java.lang.String s)
                   throws InterpreterException
Scan the expanded token stream for a sequence of letter tokens. If all tokens are found then they are removed from the input stream and true is returned. Otherwise all tokens are left in the input stream and false is returned.

Specified by:
getKeyword in interface TokenSource
Parameters:
context - the interpreter context
s - the tokens to scan
Returns:
true iff the tokens could have been successfully removed from the input stream
Throws:
InterpreterException - in case that no number is found or the end of file has been reached before an integer could be acquired

getLocator

public Locator getLocator()
Description copied from interface: TokenSource
Getter for the locator. The locator provides a means to get the information where something is coming from. Usually it points to a line in a file.

Specified by:
getLocator in interface TokenSource
Returns:
the current locator
See Also:
TokenSource.getLocator()

getNonSpace

public Token getNonSpace(Context context)
                  throws InterpreterException
Description copied from interface: TokenSource
Get the next token which has not the category code SPACE.

Specified by:
getNonSpace in interface TokenSource
Parameters:
context - the interpreter context
Returns:
the next non-space token or null at EOF
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.getNonSpace( de.dante.extex.interpreter.context.Context)

getNumber

public long getNumber(Token token)
               throws InterpreterException,
                      MissingNumberException
Scan a number with a given first token.

Parameters:
token - the first token to consider
Returns:
the value of the integer scanned
Throws:
InterpreterException - in case that no number is found or the end of file has been reached before an integer could be acquired
MissingNumberException - in case that no number is found or the end of file has been reached before an integer could be acquired

getOptionalEquals

public void getOptionalEquals(Context context)
                       throws InterpreterException
Skip spaces and if the next non-space character is an equal sign skip it as well and all spaces afterwards.

Specified by:
getOptionalEquals in interface TokenSource
Parameters:
context - the interpreter context
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.getOptionalEquals(Context)

getToken

public Token getToken(Context context)
               throws InterpreterException
Get the next token from the input streams. If the current input stream is at its end then the next one on the streamStack is used until a token could be read. If all stream are at the end then null is returned.

Whenever a file stream is closed then the tokens from the stream are discarted. This holds also for the tokens pushed back onto this stream.

Specified by:
getToken in interface TokenSource
Parameters:
context - the interpreter context
Returns:
the next token or null
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.getToken( de.dante.extex.interpreter.context.Context)

getLastToken

public Token getLastToken()
Description copied from interface: TokenSource
Getter for the token just previously read from the token source. This is something like a look-back function.

Specified by:
getLastToken in interface TokenSource
Returns:
the last token or null if not available
See Also:
TokenSource.getLastToken()

getTokens

public Tokens getTokens(Context context,
                        TokenSource source,
                        Typesetter typesetter)
                 throws InterpreterException
Description copied from interface: TokenSource
Get the next tokens form the input streams between { and }. If the current input stream is at its end then the next one on the streamStack is used until a token could be read. If all streams are at the end then an exception is thrown.

This method parses the following syntactic entity:

A Replacement Text

    ⟨replacement text⟩  

Specified by:
getTokens in interface TokenSource
Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
Returns:
the next tokens or null
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.getTokens( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter)

getTokenStreamFactory

public TokenStreamFactory getTokenStreamFactory()
Getter for the token stream factory.

Specified by:
getTokenStreamFactory in interface TokenSource
Returns:
the token stream factory

push

public void push(Token token)
          throws InterpreterException
Push back a token onto the input stream for subsequent reading.

Specified by:
push in interface TokenSource
Parameters:
token - the token to push
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.push( de.dante.extex.scanner.type.token.Token)

push

public void push(Token[] tokens)
          throws InterpreterException
Push back a list of tokens onto the input stream for subsequent reading.

Specified by:
push in interface TokenSource
Parameters:
tokens - the tokens to push
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.push( de.dante.extex.scanner.type.token.Token[])

push

public void push(Tokens tokens)
          throws InterpreterException
Push back a list of tokens onto the input stream for subsequent reading. In case that the argument is null then it is silently ignored.

If the current stream is null then all streams are at their end. In this case a new Token stream is created to hold the tokens.

Specified by:
push in interface TokenSource
Parameters:
tokens - the tokens to push
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.push( de.dante.extex.interpreter.type.tokens.Tokens)

registerObserver

public void registerObserver(EofObserver observer)
Add an observer for the eof event. This observer is triggered by an end of file on the token stream. This means that all tokens have been processed and all stream are at their end.

Specified by:
registerObserver in interface EofObservable
Parameters:
observer - the observer to add

registerObserver

public void registerObserver(OpenFileObserver observer)
Description copied from interface: OpenFileObservable
Register an expand observer for later use.

Specified by:
registerObserver in interface OpenFileObservable
Parameters:
observer - the observer to be registered
See Also:
OpenFileObservable.registerObserver(de.dante.extex.scanner.stream.observer.file.OpenFileObserver)

registerObserver

public void registerObserver(OpenReaderObserver observer)
Description copied from interface: OpenReaderObservable
Register an open reader observer for later use.

Specified by:
registerObserver in interface OpenReaderObservable
Parameters:
observer - the observer to be registered
See Also:
OpenReaderObservable.registerObserver(de.dante.extex.scanner.stream.observer.reader.OpenReaderObserver)

registerObserver

public void registerObserver(OpenStringObserver observer)
Description copied from interface: OpenStringObservable
Register an expand observer for later use.

Specified by:
registerObserver in interface OpenStringObservable
Parameters:
observer - the observer to be registered
See Also:
OpenStringObservable.registerObserver(de.dante.extex.scanner.stream.observer.string.OpenStringObserver)

registerObserver

public void registerObserver(PopObserver observer)
Add an observer for the pop event. This observer is triggered by a pop operation on the token stream. This means that a token has been extracted.

Specified by:
registerObserver in interface PopObservable
Parameters:
observer - the observer to add

registerObserver

public void registerObserver(PushObserver observer)
Add an observer for the push event. This observer is triggered by a push operation on the token stream. This means that a token has been placed on the current stream for subsequent reading.

Specified by:
registerObserver in interface PushObservable
Parameters:
observer - the observer to add

registerObserver

public void registerObserver(StreamCloseObserver observer)
Description copied from interface: StreamCloseObservable
Register an stream close observer for later use.

Specified by:
registerObserver in interface StreamCloseObservable
Parameters:
observer - the observer to be registered
See Also:
StreamCloseObservable.registerObserver( de.dante.extex.interpreter.observer.streamClose.StreamCloseObserver)

scanCharacterCode

public UnicodeChar scanCharacterCode(Context context,
                                     Typesetter typesetter,
                                     java.lang.String primitive)
                              throws InterpreterException
This method scans a character code.

The character code is either a number – after expansion – or the name of a Unicode character in braces.

Specified by:
scanCharacterCode in interface TokenSource
Parameters:
context - the interpreter context
typesetter - the typesetter
primitive - the name of the invoking primitive for error handling
Returns:
the value of the integer scanned
Throws:
InterpreterException - in case of an error
especially
InvalidCharacterException in case that no number is found or if it is out of the allowed range
EofException in case that an end of file has been encountered before the character code was complete
See Also:
TokenSource.scanCharacterCode( de.dante.extex.interpreter.context.Context, de.dante.extex.typesetter.Typesetter, java.lang.String)

scanNonSpace

public Token scanNonSpace(Context context)
                   throws InterpreterException
Scan the input for the next token which has not the catcode SPACE.

Specified by:
scanNonSpace in interface TokenSource
Parameters:
context - the interpreter context
Returns:
the next non-space token or null at EOF
Throws:
InterpreterException - in case of an error in scanToken()
See Also:
TokenSource.scanNonSpace( de.dante.extex.interpreter.context.Context)

scanNumber

public long scanNumber(Context context)
                throws InterpreterException
Description copied from interface: TokenSource
Scan the input stream for tokens making up a number, this is a sequence of digits with category code OTHER. The number can be preceded by optional white space. Alternate representations for an integer exist.

Specified by:
scanNumber in interface TokenSource
Parameters:
context - the interpreter context
Returns:
the value of the integer scanned
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.scanNumber(Context)

scanNumber

public long scanNumber(Context context,
                       Token token)
                throws InterpreterException
Description copied from interface: TokenSource
Scan the input stream for tokens making up a number, i.e. a sequence of digits with category code OTHER. The number can be preceded by optional white space.

This method implements the generalization of several syntactic definitions from TeX:

A Number

   ⟨number⟩ 

A number consists of a non-empty sequence of digits with category code OTHER.

Specified by:
scanNumber in interface TokenSource
Parameters:
context - the interpreter context
token - the first token to consider
Returns:
the value of the integer scanned
Throws:
InterpreterException - in case of an error in an observer
especially
MissingNumberException in case that no number could be read
See Also:
TokenSource.scanNumber( de.dante.extex.interpreter.context.Context, de.dante.extex.scanner.type.token.Token)

scanRegisterName

public java.lang.String scanRegisterName(Context context,
                                         TokenSource source,
                                         Typesetter typesetter,
                                         java.lang.String primitive)
                                  throws InterpreterException
Description copied from interface: TokenSource
Scan the input streams for an entity to denote a register name. Upon EOF null is returned.

A Register Name

A register name determines under which key a register can be addressed. In TeX this used to be a positive number only. This has been extended to allow also a token list in braces.

The alternative is controlled by the integer register \maxregister. The following interpretation of the value of this count is used:

  • If the value of this integer register is negative then a arbitrary non-negative number is allowed as register name as well as any list of tokens enclosed in braces.
  • If the value of this integer register is not-negative then a only a non-negative number is allowed as register name which does not exceed the value of the integer register.

The value of the integer register \maxRegister is set differently for various configurations of ExTeX:

  • TeX uses the value 255.
  • eTeX uses the value 32767.
  • Omega uses the value 65536.
  • ExTeX uses the value -1.

Te integer register \maxRegister is defined in the name space system. Thus special actions have to be used to acces it.

Syntax

   ⟨register name⟩
       → ⟨tokens⟩
        | ⟨number⟩  

Examples

  123
  {abc}
 

Specified by:
scanRegisterName in interface TokenSource
Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
primitive - the name of the invoking primitive for error handling
Returns:
the register name encountered
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.scanRegisterName( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter, java.lang.String)

scanToken

public Token scanToken(Context context)
                throws InterpreterException
Expand tokens from the input stream until an not expandable token is found. This not expandable token is returned.

Specified by:
scanToken in interface TokenSource
Parameters:
context - the interpreter context
Returns:
the next not expandable token
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.scanToken( de.dante.extex.interpreter.context.Context)

scanTokens

public Tokens scanTokens(Context context,
                         boolean reportUndefined,
                         boolean ignoreUndefined,
                         java.lang.String primitive)
                  throws InterpreterException
Description copied from interface: TokenSource
Get the next expanded token form the input streams between { and }. If the current input stream is at its end then the next one on the streamStack is used until a token could be read. If all stream are at the end then null is returned.

This method parses the following syntactic entity:

A General text

    ⟨general text⟩  

Specified by:
scanTokens in interface TokenSource
Parameters:
context - the interpreter context
primitive - the name of the invoking primitive for error handling
reportUndefined - indicator that an undefined control sequence leads to an exception. This parameter is effective only if ignoreUndefined is false
ignoreUndefined - indicator that an undefined control sequence should be treated as \relax
Returns:
the next tokens or null
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.scanTokens( de.dante.extex.interpreter.context.Context, boolean, boolean, java.lang.String)

scanTokensAsString

public java.lang.String scanTokensAsString(Context context,
                                           java.lang.String primitive)
                                    throws InterpreterException
Description copied from interface: TokenSource
Get the next expanded token form the input streams between a left brace character (usually {) and a right brace character (usually }) and convert it to a String. If the current input stream is at its end then the next one on the streamStack is used until a token could be read. If all stream are at the end then null is returned.

Specified by:
scanTokensAsString in interface TokenSource
Parameters:
context - the interpreter context
primitive - the name of the invoking primitive for error handling
Returns:
the next tokens as String or null
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.scanTokensAsString( de.dante.extex.interpreter.context.Context, java.lang.String)

scanUnprotectedTokens

public Tokens scanUnprotectedTokens(Context context,
                                    boolean reportUndefined,
                                    boolean ignoreUndefined,
                                    java.lang.String primitive)
                             throws InterpreterException
Description copied from interface: TokenSource
Get the next expanded token form the input streams between { and }. If the current input stream is at its end then the next one on the streamStack is used until a token could be read. If all stream are at the end then null is returned.

Normally all expandable tokens are expanded. This method honors the protected mark and does not try to expand protected code.

Specified by:
scanUnprotectedTokens in interface TokenSource
Parameters:
context - the interpreter context
primitive - the name of the invoking primitive for error handling
reportUndefined - indicator that an undefined control sequence leads to an exception. This parameter is effective only if ignoreUndefined is false
ignoreUndefined - indicator that an undefined control sequence should be treated as \relax
Returns:
the next tokens or null
Throws:
InterpreterException - in case of an error
See Also:
TokenSource.scanUnprotectedTokens( de.dante.extex.interpreter.context.Context, boolean, boolean, java.lang.String)

setTokenStreamFactory

public void setTokenStreamFactory(TokenStreamFactory factory)
                           throws ConfigurationException
Setter for the token stream factory.

Specified by:
setTokenStreamFactory in interface Interpreter
Parameters:
factory - the token stream factory
Throws:
ConfigurationException - this exception is never thrown. It is defined here to provide an exit for derived classes

skipSpace

public void skipSpace()
Description copied from interface: TokenSource
Skip spaces and check whether any tokens are left.

This method corresponds to the following specification:

Optional Spaces

This syntactic entity corresponds to an arbitrary number of white-space characters. White-space characters include space, ta and newline characters.

   ⟨optional spaces⟩
     → [ \t\n]*  

Specified by:
skipSpace in interface TokenSource
See Also:
TokenSource.skipSpace()

update

public void update(java.lang.String name,
                   java.lang.String text)
            throws NotObservableException
Description copied from interface: TokenSource
Send the string to the named observer. The observer must be capable to deal with a string argument.

Specified by:
update in interface TokenSource
Parameters:
name - name of the observer
text - the text to send to the observer
Throws:
NotObservableException - in case that the named observer is not accessible
See Also:
TokenSource.update(java.lang.String, java.lang.String)