Class dnx.lr.VRMLTokenizer
All Packages Class Hierarchy This Package Previous Next Index
Class dnx.lr.VRMLTokenizer
java.lang.Object
|
+----dnx.lr.VRMLTokenizer
- public class VRMLTokenizer
- extends Object
This class is a dedicated VRML tokenizer (aka lexer). It behaves
similarly to StreamTokenizer but breaks up its input (a .wrl file)
into individual VRML tokens.
The general idea is that you call nextToken() to retrieve the next
token and return its type. The types defined are (some of these
are actually states rather than types):
ID == VRML token (word, basically) or special character
STRING == string enclosed in quotes
INTEGER == integer
FLOAT == floating-point value
EOF == no more tokens; end of file reached
START == no tokens yet; at beginning of file
Once you know the type of the current token, you call getIntegerValue(),
getStringValue(), etc. to retrieve the value.
Alternatively, you can call expect(), which reads the next token and
throws an error if it's not of the specified type; or expectKeyword(),
if you want to see a particular keyword (i.e. ID).
-
charno
-
-
EOF
-
-
FLOAT
-
-
ID
-
-
INTEGER
-
-
START
-
-
STRING
-
-
VRMLTokenizer(InputStream)
- Create a new VRMLTokenizer from an input stream.
-
abortReading()
- Indicate that reading should terminate as soon as possible.
-
expect(int)
- Read the next token; if it not of the expected type, throw
a VRMLSyntaxException.
-
expectKeyword(String)
- Read the next token; if it is not a valid ID matching word,
throw a VRMLSyntaxException.
-
getDoubleValue()
- Return the value of a valid floating point token
-
getFloatValue()
- Return the value of a valid floating point token
-
getIDValue()
- Return the value of a valid ID token
-
getIntegerValue()
- Return the value of a valid integer token.
-
getLineno()
- Return the line number of the token that is about to be read.
-
getLinenoOfLastToken()
- Return the line number of the token most recently read.
-
getStringValue()
- Return the value of a valid string token
-
getTokenType()
- Return the current token type.
-
nextToken()
- Read another token and return its type.
-
pushBack()
- Push back the last token read; this class supports only one
token of pushback.
-
tryFloat()
- Check to see if the next token is a float.
-
tryID()
- Check to see if the next token is an identifier.
-
tryInteger()
- Check to see if the next token is an integer.
-
tryKeyword(String)
- Check to see if the type of the next token matches
tryType.
-
tryString()
- Check to see if the next token is a string.
-
tryType(int)
- Check to see if the type of the next token matches
tryType.
ID
public final static int ID
STRING
public final static int STRING
INTEGER
public final static int INTEGER
FLOAT
public final static int FLOAT
EOF
public final static int EOF
START
public final static int START
charno
public int charno
VRMLTokenizer
public VRMLTokenizer(InputStream s)
- Create a new VRMLTokenizer from an input stream.
abortReading
public void abortReading()
- Indicate that reading should terminate as soon as possible.
A ReadAbortedException will be thrown.
getTokenType
public int getTokenType()
- Return the current token type.
getIntegerValue
public int getIntegerValue() throws VRMLSyntaxException
- Return the value of a valid integer token.
getFloatValue
public float getFloatValue() throws VRMLSyntaxException
- Return the value of a valid floating point token
getDoubleValue
public double getDoubleValue() throws VRMLSyntaxException
- Return the value of a valid floating point token
getStringValue
public String getStringValue() throws VRMLSyntaxException
- Return the value of a valid string token
getIDValue
public String getIDValue() throws VRMLSyntaxException
- Return the value of a valid ID token
pushBack
public void pushBack()
- Push back the last token read; this class supports only one
token of pushback.
nextToken
public int nextToken() throws IOException, VRMLSyntaxException
- Read another token and return its type.
getLineno
public int getLineno()
- Return the line number of the token that is about to be read.
Note that doing a pushBack() will cause the value returned by
getLineno() to get bumped back, too.
getLinenoOfLastToken
public int getLinenoOfLastToken()
- Return the line number of the token most recently read.
Note that doing a pushBack() will cause the value returned by
getLinenoOfLastToken() to get bumped back, too.
tryType
public boolean tryType(int tryType) throws IOException, VRMLSyntaxException
- Check to see if the type of the next token matches
tryType. If it does, the function returns true; otherwise
it returns false and the current token is pushed back.
tryKeyword
public boolean tryKeyword(String word) throws IOException, VRMLSyntaxException
- Check to see if the type of the next token matches
tryType. If it does, the function returns true; otherwise
it returns false and the token just read is pushed back.
tryInteger
public boolean tryInteger() throws IOException, VRMLSyntaxException
- Check to see if the next token is an integer. If it is,
the function returns true; otherwise it returns false and
the token just read is pushed back.
tryFloat
public boolean tryFloat() throws IOException, VRMLSyntaxException
- Check to see if the next token is a float. If it is,
the function returns true; otherwise it returns false and
the token just read is pushed back.
tryID
public boolean tryID() throws IOException, VRMLSyntaxException
- Check to see if the next token is an identifier. If it is,
the function returns true; otherwise it returns false and
the token just read is pushed back.
tryString
public boolean tryString() throws IOException, VRMLSyntaxException
- Check to see if the next token is a string. If it is,
the function returns true; otherwise it returns false and
the token just read is pushed back.
expect
public void expect(int expectedType) throws IOException, VRMLSyntaxException
- Read the next token; if it not of the expected type, throw
a VRMLSyntaxException.
expectKeyword
public void expectKeyword(String word) throws IOException, VRMLSyntaxException
- Read the next token; if it is not a valid ID matching word,
throw a VRMLSyntaxException.
All Packages Class Hierarchy This Package Previous Next Index