|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.extex.scanner.type.token.TokenFactoryImpl
public class TokenFactoryImpl
This is a implementation of a token factory. This means that the factory pattern is applied here. This pattern opens the possibility to cache the instances for Tokens to reduce the number of objects present in the system.
In addition the visitor pattern is used to select the appropriate instantiation method. The visit methods are not meant to be used externally. They are purely internal. Despite their general definition the visit methods are in fact used in the following way:
Token visit*(String value, UnicodeChar character) throws CatcodeException
This means that they are expected to return the new token. The first argument is the value, which is mainly meaningful for control sequence tokens. The third argument contains the Unicode character for single letter tokens.
| Constructor Summary | |
|---|---|
TokenFactoryImpl()
Creates a new object. |
|
| Method Summary | |
|---|---|
Token |
createToken(Catcode code,
int c,
java.lang.String namespace)
Create a new Token of the
appropriate kind. |
Token |
createToken(Catcode code,
UnicodeChar c,
java.lang.String namespace)
Get an instance of a token with a given Catcode and Unicode character value. |
Token |
createToken(Catcode code,
UnicodeChar esc,
java.lang.String value,
java.lang.String namespace)
Get an instance of a token with a given Catcode and value. |
Tokens |
toTokens(java.lang.CharSequence s)
Convert a character sequence to a list of tokens. |
Tokens |
toTokens(long l)
Convert a long value into a list of tokens. |
Token |
visitActive(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
Active characters are cached. |
Token |
visitComment(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
Comments are ignored thus null is returned in any case. |
Token |
visitCr(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
There is only one CrToken. |
Token |
visitEscape(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
This visit method is invoked on an escape token. |
Token |
visitIgnore(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
Ignored characters are simply ignored;-) |
Token |
visitInvalid(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
Invalid characters are ignored; even without any error message. |
Token |
visitLeftBrace(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
A left brace token is expected to take a single character only. |
Token |
visitLetter(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
A letter token is expected to take a single character only. |
Token |
visitMacroParam(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
This visit method is invoked on a macro parameter token. |
Token |
visitMathShift(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
This visit method is invoked on a math shift token. |
Token |
visitOther(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
This visit method is invoked on an other token. |
Token |
visitRightBrace(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
This visit method is invoked on a right brace token. |
Token |
visitSpace(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
There is only one space token. |
Token |
visitSubMark(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
This visit method is invoked on a sub mark token. |
Token |
visitSupMark(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
This visit method is invoked on a sup mark token. |
Token |
visitTabMark(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
This visit method is invoked on a tab mark token. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TokenFactoryImpl()
| Method Detail |
|---|
public Token createToken(Catcode code,
int c,
java.lang.String namespace)
throws CatcodeException
Token of the
appropriate kind. Tokens are immutable (no setters) thus the factory
pattern can be applied.
createToken in interface TokenFactorycode - the category codec - the character valuenamespace - the name space to use
CatcodeException - in case of an errorTokenFactory.createToken(
org.extex.scanner.type.Catcode, int, java.lang.String)
public Token createToken(Catcode code,
UnicodeChar c,
java.lang.String namespace)
throws CatcodeException
createToken in interface TokenFactorycode - the catcodec - the Unicode character valuenamespace - the name space for the token. This is relevant for
ACTIVE and ESCAPE category codes only.
CatcodeException - in case of an errorTokenFactory.createToken(
org.extex.scanner.type.Catcode, org.extex.core.UnicodeChar,
java.lang.String)
public Token createToken(Catcode code,
UnicodeChar esc,
java.lang.String value,
java.lang.String namespace)
throws CatcodeException
createToken in interface TokenFactorycode - the catcodeesc - the Unicode character value of the escape charactervalue - the valuenamespace - the name space for the token. This is relevant for
ACTIVE and ESCAPE category codes only.
CatcodeException - in case of an errorTokenFactory.createToken(
org.extex.scanner.type.Catcode, org.extex.core.UnicodeChar,
java.lang.String, java.lang.String)
public Tokens toTokens(java.lang.CharSequence s)
throws CatcodeException
Each character of the string is converted into a OtherToken
and added to the internal list. An exception is made for spaces which are
converted into a SpaceToken.
toTokens in interface TokenFactorys - the character sequence to translate to tokens
CatcodeException - in case of an errorTokenFactory.toTokens(java.lang.CharSequence)
public Tokens toTokens(long l)
throws CatcodeException
Each character is converted into a OtherToken and added to
the internal list.
toTokens in interface TokenFactoryl - the value to convert
CatcodeException - in case of an errorTokenFactory.toTokens(long)
public Token visitActive(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
visitActive in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitActive( java.lang.Object,
java.lang.Object, java.lang.Object)
public Token visitComment(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
null is returned in any case.
visitComment in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
nullCatcodeVisitor.visitComment(
java.lang.Object, java.lang.Object, java.lang.Object)
public Token visitCr(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
visitCr in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeVisitor.visitCr(java.lang.Object,
java.lang.Object, java.lang.Object)
public Token visitEscape(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
visitEscape in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitEscape( java.lang.Object,
java.lang.Object, java.lang.Object)
public Token visitIgnore(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
visitIgnore in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value token or nulluchar - the requested character codenamespace - the third argument is ignored
nullCatcodeVisitor.visitIgnore( java.lang.Object,
java.lang.Object, java.lang.Object)
public Token visitInvalid(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
visitInvalid in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value token or nulluchar - the requested character codenamespace - the third argument is ignored
nullCatcodeVisitor.visitInvalid(
java.lang.Object, java.lang.Object, java.lang.Object)
public Token visitLeftBrace(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
visitLeftBrace in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitLeftBrace(
java.lang.Object, java.lang.Object, java.lang.Object)
public Token visitLetter(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
visitLetter in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitLetter( java.lang.Object,
java.lang.Object, java.lang.Object)
public Token visitMacroParam(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
CatcodeVisitor
visitMacroParam in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitMacroParam(
java.lang.Object, java.lang.Object, java.lang.Object)
public Token visitMathShift(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
CatcodeVisitor
visitMathShift in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitMathShift(
java.lang.Object, java.lang.Object, java.lang.Object)
public Token visitOther(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
CatcodeVisitor
visitOther in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitOther( java.lang.Object,
java.lang.Object, java.lang.Object)
public Token visitRightBrace(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
CatcodeVisitor
visitRightBrace in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitRightBrace(
java.lang.Object, java.lang.Object, java.lang.Object)
public Token visitSpace(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
visitSpace in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value token or nulluchar - the requested character codenamespace - the third argument is ignored
CatcodeVisitor.visitSpace( java.lang.Object,
java.lang.Object, java.lang.Object),
"The TeXbook [Chapter 8, p. 47]"
public Token visitSubMark(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
CatcodeVisitor
visitSubMark in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitSubMark(
java.lang.Object, java.lang.Object, java.lang.Object)
public Token visitSupMark(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
CatcodeVisitor
visitSupMark in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitSupMark(
java.lang.Object, java.lang.Object, java.lang.Object)
public Token visitTabMark(java.lang.String value,
UnicodeChar uchar,
java.lang.String namespace)
throws CatcodeException
CatcodeVisitor
visitTabMark in interface CatcodeVisitor<Token,java.lang.String,UnicodeChar,java.lang.String>value - the string value of the tokenuchar - the character value of the tokennamespace - the name space of the token
CatcodeException - in case of an errorCatcodeVisitor.visitTabMark(
java.lang.Object, java.lang.Object, java.lang.Object)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||