org.extex.ocpware.compiler.parser
Class ParserStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.PushbackInputStream
              extended by org.extex.ocpware.compiler.parser.ParserStream
All Implemented Interfaces:
java.io.Closeable

public class ParserStream
extends java.io.PushbackInputStream

This class provides a push-back input stream which can parse certain basic entities.

Version:
$Revision:6007 $
Author:
Gerd Neugebauer

Field Summary
 
Fields inherited from class java.io.PushbackInputStream
buf, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
ParserStream(java.io.InputStream in)
          Creates a new object.
 
Method Summary
 SyntaxException error(int c)
          Create an exception containing the context.
 void expect(char ex)
          Skip to the next non-white-space character and compare it to a given one.
 void expect(java.lang.String ex)
          Parse an id.
 java.lang.CharSequence getLine()
          Getter for line.
 int getLineno()
          Getter for lineno.
 java.lang.String parseId()
          Parse an id.
 int parseNumber(int cc)
          Parse a number.
 java.lang.String parseString()
          Parse a string specification.
 int read()
          
 int skipSpace()
          Skip whitespace and comments and advance to the next real character.
 java.lang.String toString()
          
 void unread(int b)
          
 
Methods inherited from class java.io.PushbackInputStream
available, close, mark, markSupported, read, reset, skip, unread, unread
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParserStream

public ParserStream(java.io.InputStream in)
Creates a new object.

Parameters:
in - the stream to acquire characters from
Method Detail

error

public SyntaxException error(int c)
Create an exception containing the context.

Parameters:
c - the character read
Returns:
the exception

expect

public void expect(char ex)
            throws java.io.IOException,
                   SyntaxException
Skip to the next non-white-space character and compare it to a given one. If the comparison fails then an exception is raised.

Parameters:
ex - the expected character
Throws:
java.io.IOException - in case of an I/O error
SyntaxException - in case of a syntax error

expect

public void expect(java.lang.String ex)
            throws java.io.IOException,
                   SyntaxException
Parse an id.

Parameters:
ex - the expected characters
Throws:
java.io.IOException - in case of an I/O error
SyntaxException - in case of a syntax error

getLine

public java.lang.CharSequence getLine()
Getter for line.

Returns:
the line

getLineno

public int getLineno()
Getter for lineno.

Returns:
the lineno

parseId

public java.lang.String parseId()
                         throws java.io.IOException,
                                SyntaxException
Parse an id. An id is a non empty sequence of characters made up of letters (a-z,A-Z), digits (0-9), the underscore character(_), and the colon (:) where the first character is not a digit or a colon.

Returns:
the identifier read
Throws:
java.io.IOException - in case of an I/O error
SyntaxException - in case of a syntax error

parseNumber

public int parseNumber(int cc)
                throws java.io.IOException,
                       SyntaxException
Parse a number.

Parameters:
cc - the character already scanned
Returns:
the number read
Throws:
java.io.IOException - in case of an I/O error
SyntaxException - in case of an parser error

parseString

public java.lang.String parseString()
                             throws java.io.IOException
Parse a string specification. It is assumed that the starting double quote (") has already been digested. The string reaches to the terminating double quote. This terminating character is absorbed but not included into the result.

If two double quotes occur in sequence then this is interpreted as one double quote character embedded in the string.

Returns:
the string value
Throws:
java.io.IOException - in case of an I/O error

read

public int read()
         throws java.io.IOException

Overrides:
read in class java.io.PushbackInputStream
Throws:
java.io.IOException
See Also:
PushbackInputStream.read()

skipSpace

public int skipSpace()
              throws java.io.IOException
Skip whitespace and comments and advance to the next real character. This character is returned. If end of file is reached -1 is returned.

Returns:
the character read or -1 upon EOF
Throws:
java.io.IOException - in case of an I/O error

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

unread

public void unread(int b)
            throws java.io.IOException

Overrides:
unread in class java.io.PushbackInputStream
Throws:
java.io.IOException
See Also:
PushbackInputStream.unread(int)