|
Stefy | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--stefy.avm.Tokenizer
Tokenizer class (DD) is an advanced tokenizer similar to the standard StringTokenizer or StreamTokenizer.
Field Summary | |
double |
dval
Double value of the current token. |
int |
ival
Integer (int) value of the current token. |
java.lang.String[] |
saval
An array of strings obtained after parsing some compelx tokens (eg, XML tags). |
java.lang.String |
sval
String value of the current token. |
static int |
TT_CONTROL
The token type denoting a control word (reserved word, keyword). |
static int |
TT_DOUBLE
The token type denoting a floating-point number. |
static int |
TT_EOF
The token type denoting the end of file. |
static int |
TT_EOL
The token type denoting the end of line. |
static int |
TT_HEADER
The token type denoting header (e.g., RFC822 (e-mail) header). |
static int |
TT_INTEGER
The token type denoting an integer number. |
static int |
TT_QUOTE
Default quote token type. |
static int |
TT_SPC
The token type denoting white space (not EOL). |
static int |
TT_WORD
The token type denoting a word. |
static int |
TT_XMLTAG
The token type denoting XML tag (may not be precisely according to the standard). |
int |
ttype
Current token type. |
Constructor Summary | |
Tokenizer(java.io.InputStream is)
Constructs tokenizer on a given InputStream. |
|
Tokenizer(java.io.Reader r)
Constructs tokenizer on a Reader. |
|
Tokenizer(java.lang.String s)
Constructs tokenizer on a given string. |
Method Summary | |
void |
addControlString(java.lang.String ctrl)
Adds a control string, usually: a keyword, reserved word, multi-character operator, and similar. |
void |
alphanumChars(int low,
int hi)
Specifies that all characters c in the range low <= c <= high
have "alphanum" attribute set. |
void |
assertToken(int ttype,
java.lang.String s)
Asserts certain token type (ttype) and the value of sval. |
void |
assertToken(java.lang.String ttname,
java.lang.String s)
Asserts certain token type (ttype), given its name, and the value of sval. |
int |
colno()
Get the current column number of the input. |
void |
defaultSyntax()
Sets the tokenizer configuration to default values. |
int |
defineQuotes(java.lang.String pref,
java.lang.String suf,
java.lang.String ttname)
Define quotes. |
void |
defQuoteSub(java.lang.String pref,
java.lang.String suf,
java.lang.String sub,
java.lang.String rep)
Defines a substitution of a quote type. |
void |
emailHeaders(boolean flag)
Activates recognition of RFC822 (e-mail) headers. |
void |
error(java.lang.String s)
Report an error while parsing. |
java.lang.String |
getLastPreRead()
Returns a "raw" string value composed of all characters that were read during the recognition of the last token, but before the beginning of the token. |
java.lang.String |
getLastRead()
Returns a "raw" string value composed of all characters that were read during the recognition of the last token. |
int |
getTtype(java.lang.String ttname)
Get ttype number. |
boolean |
hasMoreTokens()
Verifies whether there are more tokens (i.e., whether the current token is of type TT_EOF . |
int |
lineno()
Get the current line number of the input. |
int |
nextToken()
Reads next token. |
void |
ordinaryChar(int c)
|
boolean |
parseDoubles(boolean flag)
Activates recognition of floating-point numbers (default is false). |
void |
parseIntegers(boolean flag)
Specifies whether this tokenizer should recognize integers. |
void |
parseNumbers(boolean flag)
Specifies whether this tokenizer should recognize numbers. |
Tokenizer |
popConfig()
Pops the current tokenizer configuration from an internal stack. |
Tokenizer |
pushConfig()
Pushes the current tokenizer configuration to an internal stack. |
void |
quoteChar(int b)
Set a character to be a quote character. |
double |
readDval(int ttype)
Verifies that the current token is of type ttype, returns its dval , and reads next token. |
double |
readDval(java.lang.String ttname)
Verifies that the type name of the current token is ttname, returns its ival , and reads next token. |
int |
readIval(int ttype)
Verifies that the current token is of type ttype, returns its ival , and reads next token. |
int |
readIval(java.lang.String ttname)
Verifies that the type name of the current token is ttname, returns its ival , and reads next token. |
java.lang.String |
readSval(int ttype)
Verifies that the current token is of type ttype, returns its sval , and reads next token. |
java.lang.String |
readSval(java.lang.String ttname)
Verifies that the type name of the current token is ttname, returns its sval , and reads next token. |
void |
readToken(int ttype,
java.lang.String s)
Reports an error if it does not see a token of type ttype, and sval equal to s. |
void |
readToken(java.lang.String ttname,
java.lang.String s)
Reports an error if it does not see a token with token name ttname, and sval equal to s. |
int |
rereadToken()
Return to the beginning of the last read token and read a token again (with possibly another rules). |
void |
resetSyntax()
Resets syntax: all characters are ordinary characters. |
boolean |
seeToken(int ttype,
java.lang.String s)
Check if the current token is the token ttype with
the string value s . |
boolean |
seeToken(java.lang.String ttname,
java.lang.String s)
Check if the current token has the token type name ttname, and has the sval value s . |
void |
setEscapeCharacter(int i)
Sets the escape character for control tokens. |
void |
setIgnore(int ttype,
boolean f)
Specifies that a token type should be ignored. |
java.lang.String |
toString()
Returns the string representation of the current stream token. |
java.lang.String |
ttName(int tt)
Get ttype name. |
void |
whitespaceChars(int low,
int hi)
Specifies that all characters c in the range low <= c <= high
have "whitespace" attribute set. |
void |
wordChar(int c)
Specifies the character c have "alpha" and
"alphanum" attributes set. |
void |
wordChars(int low,
int hi)
Specifies that all characters c in the range low <= c <= high
have "alpha" and "alphanum" attributes set. |
void |
wordChars(java.lang.String s)
Specifies that all characters c in the string s have "alpha" and "alphanum" attributes set. |
void |
XMLtags(boolean flag)
Activates recognition of XML tags. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public int ttype
public static final int TT_EOF
public static final int TT_SPC
public static final int TT_EOL
public static final int TT_INTEGER
public static final int TT_WORD
public static final int TT_CONTROL
public static final int TT_HEADER
public static final int TT_XMLTAG
public static final int TT_QUOTE
public static final int TT_DOUBLE
public java.lang.String sval
public int ival
public double dval
public java.lang.String[] saval
Constructor Detail |
public Tokenizer(java.lang.String s)
s
- the stringpublic Tokenizer(java.io.InputStream is)
is
- the input streampublic Tokenizer(java.io.Reader r)
r
- the readerMethod Detail |
public Tokenizer pushConfig()
public Tokenizer popConfig()
pushConfig()
public void setIgnore(int ttype, boolean f)
setIgnore( defineQuotes("//", "\n", "IGNORED"), true)
or, a normal Java-like line comment can be specified as:
setIgnore( defineQuotes("/*", "*/", "IGNORED"), true)
ttype
- token typef
- boolean flag (true meanse ignore)public void resetSyntax()
public void defaultSyntax()
More precisely, the method consists of the following instructions:
config.reset(); whitespaceChars(0, ' '); wordChars('A', 'Z'); wordChars('a', 'z'); wordChar('_'); alphanumChars('0', '9'); parseNumbers(true); defineQuotes("'", "'", null); defQuoteSub ("'", "'", "\\'", "'"); defQuoteSub ("'", "'", "\\\\", "\\"); defineQuotes("\"", "\"", null); defQuoteSub ("\"", "\"", "\\\"", "\""); defQuoteSub ("\"", "\"", "\\\\", "\\"); defQuoteSub ("\"", "\"", "\\n", "\n"); defQuoteSub ("\"", "\"", "\\b", "\b"); defQuoteSub ("\"", "\"", "\\f", "\f"); defQuoteSub ("\"", "\"", "\\t", "\r"); defQuoteSub ("\"", "\"", "\\t", "\t"); setIgnore(TT_EOL, true); setIgnore(TT_SPC, true);
public void setEscapeCharacter(int i)
i
- the ASCII value of the escape character, -1 for not
having an escape character.public void addControlString(java.lang.String ctrl)
public void emailHeaders(boolean flag)
flag
- true to activate, false to deactivate.public void XMLtags(boolean flag)
flag
- true to activate, false to deactivate.public boolean parseDoubles(boolean flag)
flag
- true to activate, false to deactivate.public java.lang.String ttName(int tt)
tt
- a token type (ttype)public int getTtype(java.lang.String ttname)
ttname
- a token type namepublic void quoteChar(int b)
quoteChar('\'')
defines quote to be a
quote character. You may want to invoke:
defQuoteSub(b,"\\"+(char)b, ""+(char)b)
afterwards.b
- the quote characterpublic int defineQuotes(java.lang.String pref, java.lang.String suf, java.lang.String ttname)
pref
- is the prefix stringsuf
- is the suffix stringttname
- token type name, if null, the generic QUOTE is usedpublic void defQuoteSub(java.lang.String pref, java.lang.String suf, java.lang.String sub, java.lang.String rep)
defQuoteSub("\"","\"","\\\"","\"")
and defQuoteSub("\"","\"","\\n","\n")
.
It calls defineQuotes(pref,suf,null))
.pref
- the quote prefix stringsuf
- the quote suffix stringsub
- the string to be substitutedrep
- the replacementpublic void wordChar(int c)
c
have "alpha" and
"alphanum" attributes set.
A word token consists of an "alpha" character followed by zero or
more "alphanum" characters.c
- the character.wordChars(String)
,
wordChars(int, int)
,
sval
,
TT_WORD
,
ttype
public void ordinaryChar(int c)
public void wordChars(java.lang.String s)
s
have "alpha" and "alphanum" attributes set.
A word token consists of an "alpha" character followed by zero or
more "alphanum" characters.s
- the string of characters.wordChar(int)
,
wordChars(int, int)
,
sval
,
TT_WORD
,
ttype
public void wordChars(int low, int hi)
low <= c <= high
have "alpha" and "alphanum" attributes set. A word token
consists of an "alpha" character followed by zero or more
"alphanum" characters.low
- the low end of the range.hi
- the high end of the range.public void whitespaceChars(int low, int hi)
low <= c <= high
have "whitespace" attribute set.low
- the low end of the range.hi
- the high end of the range.public void alphanumChars(int low, int hi)
low <= c <= high
have "alphanum" attribute set.low
- the low end of the range.hi
- the high end of the range.public void parseIntegers(boolean flag)
true, the characters:
0 1 2 3 4 5 6 7 8 9
get the "digit" attribute set, and their "alpha" attribute
(starting a word) is reset.
If the argument is false
, then all characters get
the attribute "digit" reset.
For all integers, the values of the fields ival
and
sval
are set, and the ttype
gets value
TT_INTEGER
.
- Parameters:
flag
- true
indicates that integers are parsed;
false
indicates that numbers are not parsed.- See Also:
sval
,
TT_INTEGER
,
ttype
,
parseNumbers(boolean)
public void parseNumbers(boolean flag)
parseIngeters
and parseDoubles
.flag
- true
indicates that numbers are parsed;
and false
indicates that numbers are not parsed.public int lineno()
public int colno()
public int rereadToken() throws java.io.IOException
public java.lang.String getLastPreRead()
public java.lang.String getLastRead()
public int nextToken() throws java.io.IOException
public boolean hasMoreTokens()
TT_EOF
.ttype !=TT_EOF
)public boolean seeToken(int ttype, java.lang.String s)
ttype
with
the string value s
. If the string is null, it will
not be compared.ttype
- token types
- the string value (if null, it is not compared)public boolean seeToken(java.lang.String ttname, java.lang.String s)
s
. If s
is null, it
will not be compared.ttname
- token types
- the string value (if null, it is not compared)public void readToken(int ttype, java.lang.String s) throws java.io.IOException
ttype
- expected token types
- expected svalpublic void readToken(java.lang.String ttname, java.lang.String s) throws java.io.IOException
ttname
- expected token type names
- expected svalpublic void assertToken(int ttype, java.lang.String s) throws java.io.IOException
ttype
- expected token types
- expected sval, if null then it is not checked.public void assertToken(java.lang.String ttname, java.lang.String s) throws java.io.IOException
ttype
- expected token type names
- expected sval, if null then it is not checked.public java.lang.String readSval(int ttype) throws java.io.IOException
sval
, and reads next token.ttype
- expected token typepublic java.lang.String readSval(java.lang.String ttname) throws java.io.IOException
sval
, and reads next token.ttype
- expected token typepublic int readIval(int ttype) throws java.io.IOException
ival
, and reads next token.ttype
- expected token typepublic int readIval(java.lang.String ttname) throws java.io.IOException
ival
, and reads next token.
The name "NUMBER"
is special since it allows for
INTEGER as well as DOUBLE type.ttype
- expected token typepublic double readDval(int ttype) throws java.io.IOException
dval
, and reads next token.ttype
- expected token typepublic double readDval(java.lang.String ttname) throws java.io.IOException
ival
, and reads next token.
The name "NUMBER"
is special since it allows for
INTEGER as well as DOUBLE type.ttype
- expected token typepublic java.lang.String toString()
ttype
, nval
, and sval
fields.java.io.StreamTokenizer#nval
,
java.io.StreamTokenizer#sval
,
java.io.StreamTokenizer#ttype
public void error(java.lang.String s)
s
- the error message.
|
Stefy | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |