org.extex.base.parser
Class ConstantCountParser

java.lang.Object
  extended by org.extex.base.parser.ConstantCountParser
All Implemented Interfaces:
CountParser, Parser<Count>

public final class ConstantCountParser
extends java.lang.Object
implements Parser<Count>, CountParser

This class represents a long integer value. It is used for instance as count register.

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

Constructor Summary
ConstantCountParser()
          Creates a new object.
 
Method Summary
 Count parse(Context context, TokenSource source, Typesetter typesetter)
          Parse a value of the given type
 long parseInteger(Context context, TokenSource source, Typesetter typesetter)
          Parse an integer.
 long parseNumber(Context context, TokenSource source, Typesetter typesetter)
          Parse a non-negative number.
static long scanInteger(Context context, TokenSource source, Typesetter typesetter)
          Scan the input stream for tokens making up an integer, this is a number optionally preceded by a sign (+ or -).
static long scanNumber(Context context, TokenSource source, Typesetter typesetter)
          Scan the input stream for tokens making up a number.
static long scanNumber(Context context, TokenSource source, Typesetter typesetter, Token token)
          Scan the input stream for tokens making up a number, this is a sequence of digits with category code OTHER.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstantCountParser

public ConstantCountParser()
Creates a new object.

Method Detail

scanInteger

public static long scanInteger(Context context,
                               TokenSource source,
                               Typesetter typesetter)
                        throws HelpingException,
                               TypesetterException
Scan the input stream for tokens making up an integer, this is a number optionally preceded by a sign (+ or -). The number can be preceded by optional white space. White space is also ignored between the sign and the number. All non-whitespace characters must have the category code OTHER.

This method parses the following syntactic entity:

A Number

 ⟨number⟩ 

A number consists of a non-empty sequence of digits with category code OTHER. The number is optionally preceded by white space and a sign + or -.

Tokens are expanded while gathering the requested values.

Parameters:
context - the processor context
source - the source for new tokens
typesetter - the typesetter to use for conversion
Returns:
the value of the count
Throws:
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter

scanNumber

public static long scanNumber(Context context,
                              TokenSource source,
                              Typesetter typesetter)
                       throws HelpingException,
                              TypesetterException
Scan the input stream for tokens making up a number. A number is 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.

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.

Parameters:
context - the processor context
source - the source for new tokens
typesetter - the typesetter
Returns:
the value of the integer scanned
Throws:
HelpingException - in case that no number is found or the end of file has been reached before an integer could be acquired
TypesetterException - in case of an error in the typesetter

scanNumber

public static long scanNumber(Context context,
                              TokenSource source,
                              Typesetter typesetter,
                              Token token)
                       throws HelpingException,
                              TypesetterException
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.

Parameters:
context - the processor context
source - the source for new tokens
typesetter - the typesetter
token - the first token
Returns:
the value of the integer scanned
Throws:
HelpingException - in case that no number is found or the end of file has been reached before an integer could be acquired
TypesetterException - in case of an error in the typesetter

parse

public Count parse(Context context,
                   TokenSource source,
                   Typesetter typesetter)
            throws HelpingException,
                   TypesetterException
Parse a value of the given type

Specified by:
parse in interface Parser<Count>
Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
Returns:
the value
Throws:
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter
See Also:
Parser.parse(org.extex.interpreter.context.Context, org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)

parseInteger

public long parseInteger(Context context,
                         TokenSource source,
                         Typesetter typesetter)
                  throws HelpingException,
                         TypesetterException
Parse an integer. This number can either be positive or negative.

Specified by:
parseInteger in interface CountParser
Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
Returns:
the value
Throws:
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter
See Also:
CountParser.parseInteger(org.extex.interpreter.context.Context, org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)

parseNumber

public long parseNumber(Context context,
                        TokenSource source,
                        Typesetter typesetter)
                 throws HelpingException,
                        TypesetterException
Parse a non-negative number.

Specified by:
parseNumber in interface CountParser
Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
Returns:
the value
Throws:
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter
See Also:
CountParser.parseNumber(org.extex.interpreter.context.Context, org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)