Class SimpleCharStream
-
Field Summary
Modifier and TypeFieldDescriptionint
Position in the buffer.static final boolean
Whether the parser is static. -
Constructor Summary
ConstructorDescriptionSimpleCharStream
(InputStream dstream) Constructs a new `SimpleCharStream` using the specified input stream, starting at the first line and column, with a default buffer size.SimpleCharStream
(InputStream dstream, int startline, int startcolumn) Constructs a new `SimpleCharStream` using the specified input stream, starting line, and starting column.SimpleCharStream
(InputStream dstream, int startline, int startcolumn, int buffersize) Constructs a new `SimpleCharStream` using the specified input stream, starting line, starting column, and buffer size.SimpleCharStream
(InputStream dstream, String encoding) Constructs a new `SimpleCharStream` using the specified input stream and character encoding, starting at the first line and column.SimpleCharStream
(InputStream dstream, String encoding, int startline, int startcolumn) Constructs a new `SimpleCharStream` using the specified input stream, character encoding, starting line, and starting column.SimpleCharStream
(InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) Constructs a new `SimpleCharStream` using the specified input stream, character encoding, starting line, starting column, and buffer size.SimpleCharStream
(Reader dstream) Constructor for `SimpleCharStream` with a specified `Reader`, using default starting line, column, and buffer size.SimpleCharStream
(Reader dstream, int startline, int startcolumn) Constructor for `SimpleCharStream` with a specified `Reader`, starting line, and starting column.SimpleCharStream
(Reader dstream, int startline, int startcolumn, int buffersize) Constructor for `SimpleCharStream` with a specified `Reader`, starting line, starting column, and buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
adjustBeginLineColumn
(int newLine, int newCol) Adjusts the line and column numbers for the start of a token.void
backup
(int amount) Backups the character buffer by a specified amount.char
Begins the token processing by reading the next character from the input stream.void
Done()
Reset buffer when finished.int
Gets the beginning column number of the current token.int
Gets the beginning line number of the current token.int
Deprecated.int
Gets the end column number of the current token.int
Gets the end line number of the current token.GetImage()
Retrieves the literal value of the current token from the internal buffer.int
getLine()
Deprecated.char[]
GetSuffix
(int len) Retrieves a suffix of the internal buffer.char
readChar()
Reads a single character from the input stream.void
ReInit
(InputStream dstream) Reinitializes the lexer with a new input stream, starting at line 1 and column 1, with a default buffer size.void
ReInit
(InputStream dstream, int startline, int startcolumn) Reinitializes the lexer with a new input stream and specified starting line and column.void
ReInit
(InputStream dstream, int startline, int startcolumn, int buffersize) Reinitializes the lexer with a new input stream, starting at the given line and column, with a specified buffer size.void
ReInit
(InputStream dstream, String encoding) Reinitializes the lexer with a new input stream, specified encoding, starting at the first line and column, and using a default buffer size.void
ReInit
(InputStream dstream, String encoding, int startline, int startcolumn) Reinitializes the lexer with a new input stream, specified encoding, and starting line and column.void
ReInit
(InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) Reinitializes the lexer with a new input stream, specified encoding, starting at the given line and column, with a specified buffer size.void
Reinitialises the `SimpleCharStream` with a new `Reader`, starting at the first line and column.void
Reinitialises the `SimpleCharStream` with a new `Reader`, starting at the specified line and column.void
Reinitialises the `SimpleCharStream` with a new `Reader`, starting line, starting column, and buffer size.
-
Field Details
-
staticFlag
public static final boolean staticFlagWhether the parser is static.This flag indicates whether the parser is intended to use a static character stream class or not. This value is `false` in this implementation.
- See Also:
-
bufpos
public int bufposPosition in the buffer.This field indicates the current position within the buffer where characters are read or written.
-
-
Constructor Details
-
SimpleCharStream
Constructor for `SimpleCharStream` with a specified `Reader`, starting line, starting column, and buffer size.This constructor initializes the character stream with the given reader and sets the initial line and column numbers for reading. It also sets the buffer size for reading characters from the stream.
- Parameters:
dstream
- The `Reader` to be used by the character stream. This reader provides the source of characters.startline
- The line number from which to start reading characters. Line numbers are 1-based.startcolumn
- The column number from which to start reading characters. Column numbers are 1-based.buffersize
- The size of the buffer to be used for reading characters. This determines the number of characters that can be buffered before reading from the underlying stream again.
-
SimpleCharStream
Constructor for `SimpleCharStream` with a specified `Reader`, starting line, and starting column.This constructor initializes the character stream with the given reader, and sets the initial line and column numbers for reading. It uses a default buffer size of 4096 characters.
- Parameters:
dstream
- The `Reader` to be used by the character stream. This reader provides the source of characters.startline
- The line number from which to start reading characters. Line numbers are 1-based.startcolumn
- The column number from which to start reading characters. Column numbers are 1-based.
-
SimpleCharStream
Constructor for `SimpleCharStream` with a specified `Reader`, using default starting line, column, and buffer size.This constructor initializes the character stream with the given reader, setting the initial line and column numbers to 1, and uses a default buffer size of 4096 characters.
- Parameters:
dstream
- The `Reader` to be used by the character stream. This reader provides the source of characters.
-
SimpleCharStream
public SimpleCharStream(InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws UnsupportedEncodingException Constructs a new `SimpleCharStream` using the specified input stream, character encoding, starting line, starting column, and buffer size.This constructor sets up the character stream with the provided input stream and character encoding, starting at the given line and column numbers, and uses the specified buffer size for reading characters.
- Parameters:
dstream
- The input stream to be used by the character stream. This stream provides the source of characters.encoding
- The character encoding to be used for interpreting bytes from the input stream.startline
- The line number from which to start reading characters. Line numbers are 1-based.startcolumn
- The column number from which to start reading characters. Column numbers are 1-based.buffersize
- The size of the buffer used for reading the input stream.- Throws:
UnsupportedEncodingException
- if the specified encoding is not supported.
-
SimpleCharStream
Constructs a new `SimpleCharStream` using the specified input stream, starting line, starting column, and buffer size.This constructor sets up the character stream with the provided input stream, starting at the given line and column numbers, and uses the specified buffer size for reading characters.
- Parameters:
dstream
- The input stream to be used by the character stream. This stream provides the source of characters.startline
- The line number from which to start reading characters. Line numbers are 1-based.startcolumn
- The column number from which to start reading characters. Column numbers are 1-based.buffersize
- The size of the buffer used for reading the input stream.
-
SimpleCharStream
public SimpleCharStream(InputStream dstream, String encoding, int startline, int startcolumn) throws UnsupportedEncodingException Constructs a new `SimpleCharStream` using the specified input stream, character encoding, starting line, and starting column.This constructor sets up the character stream with the provided input stream and character encoding, starting at the given line and column numbers. The default buffer size of 4096 characters is used.
- Parameters:
dstream
- The input stream to be used by the character stream. This stream provides the source of characters.encoding
- The character encoding to be used for interpreting bytes from the input stream.startline
- The line number from which to start reading characters. Line numbers are 1-based.startcolumn
- The column number from which to start reading characters. Column numbers are 1-based.- Throws:
UnsupportedEncodingException
- if the specified encoding is not supported.
-
SimpleCharStream
Constructs a new `SimpleCharStream` using the specified input stream, starting line, and starting column.This constructor sets up the character stream with the provided input stream, starting at the given line and column numbers, and uses the default buffer size of 4096 characters.
- Parameters:
dstream
- The input stream to be used by the character stream. This stream provides the source of characters.startline
- The line number from which to start reading characters. Line numbers are 1-based.startcolumn
- The column number from which to start reading characters. Column numbers are 1-based.
-
SimpleCharStream
Constructs a new `SimpleCharStream` using the specified input stream and character encoding, starting at the first line and column.This constructor sets up the character stream with the provided input stream and character encoding, starting from line 1 and column 1, and uses the default buffer size of 4096 characters.
- Parameters:
dstream
- The input stream to be used by the character stream. This stream provides the source of characters.encoding
- The character encoding to be used for interpreting bytes from the input stream.- Throws:
UnsupportedEncodingException
- if the specified encoding is not supported.
-
SimpleCharStream
Constructs a new `SimpleCharStream` using the specified input stream, starting at the first line and column, with a default buffer size.This constructor sets up the character stream with the provided input stream, starting from line 1 and column 1, and uses the default buffer size of 4096 characters.
- Parameters:
dstream
- The input stream to be used by the character stream. This stream provides the source of characters.
-
-
Method Details
-
BeginToken
Begins the token processing by reading the next character from the input stream.This method initializes the starting position for the token by setting the `tokenBegin` to the current buffer position. It then reads the first character of the new token.
The `tokenBegin` field is updated to mark the start of the new token, and the character read is returned. This method is typically called at the beginning of tokenization to ensure that the lexer is ready to process a new token from the correct position in the input stream.
- Returns:
- The first character of the new token.
- Throws:
IOException
- If an I/O error occurs while reading from the input stream.
-
readChar
Reads a single character from the input stream.This method attempts to read a character from the buffer if available. If the buffer is empty or if the end of the buffer has been reached, it will fill the buffer with more characters from the input stream before returning the character. It also updates the line and column numbers based on the character read.
- Returns:
- The character read from the input stream.
- Throws:
IOException
- If an I/O error occurs while reading from the stream.
-
getColumn
-
getLine
-
getEndColumn
public int getEndColumn()Gets the end column number of the current token.This method retrieves the column number where the current token ends. The column number is 1-based.
- Returns:
- The end column number of the current token.
-
getEndLine
public int getEndLine()Gets the end line number of the current token.This method retrieves the line number where the current token ends. The line number is 1-based.
- Returns:
- The end line number of the current token.
-
getBeginColumn
public int getBeginColumn()Gets the beginning column number of the current token.This method retrieves the column number where the current token begins. The column number is 1-based.
- Returns:
- The beginning column number of the current token.
-
getBeginLine
public int getBeginLine()Gets the beginning line number of the current token.This method retrieves the line number where the current token begins. The line number is 1-based.
- Returns:
- The beginning line number of the current token.
-
backup
public void backup(int amount) Backups the character buffer by a specified amount.This method moves the current position in the buffer backwards by the given amount. The buffer position is adjusted accordingly to handle wrapping around the buffer.
- Parameters:
amount
- The number of characters to backup in the buffer.
-
ReInit
Reinitialises the `SimpleCharStream` with a new `Reader`, starting line, starting column, and buffer size.This method resets the character stream with a new input reader and sets the initial line and column numbers. It also adjusts the internal buffer size and resets the stream's state.
- Parameters:
dstream
- The `Reader` to be used by the character stream. This reader provides the source of characters.startline
- The line number from which to start reading characters. Line numbers are 1-based.startcolumn
- The column number from which to start reading characters. Column numbers are 1-based.buffersize
- The size of the buffer used for reading the input stream. This determines how many characters can be held in memory for efficient reading.
-
ReInit
Reinitialises the `SimpleCharStream` with a new `Reader`, starting at the specified line and column.This method allows you to reset the character stream with a new input reader, and start reading from the specified line and column. The default buffer size of 4096 characters is used.
- Parameters:
dstream
- The `Reader` to be used by the character stream. This reader provides the source of characters.startline
- The line number from which to start reading characters. Line numbers are 1-based.startcolumn
- The column number from which to start reading characters. Column numbers are 1-based.
-
ReInit
Reinitialises the `SimpleCharStream` with a new `Reader`, starting at the first line and column.This method allows you to reset the character stream with a new input reader, starting from line 1 and column 1. The default buffer size of 4096 characters is used.
- Parameters:
dstream
- The `Reader` to be used by the character stream. This reader provides the source of characters.
-
ReInit
public void ReInit(InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws UnsupportedEncodingException Reinitializes the lexer with a new input stream, specified encoding, starting at the given line and column, with a specified buffer size.This method sets up the lexer to read from a new input stream, using the specified character encoding. The lexer will start tokenizing from the specified line and column, and will use the provided buffer size for reading the input.
- Parameters:
dstream
- The new input stream to be used by the lexer. This stream provides the source of characters to be tokenized.encoding
- The character encoding to be used for interpreting the bytes from the input stream. If this isnull
, the default encoding will be used.startline
- The line number at which to start tokenizing. Line numbers are 1-based.startcolumn
- The column number at which to start tokenizing. Column numbers are 1-based.buffersize
- The size of the buffer to be used for reading the input stream.- Throws:
UnsupportedEncodingException
- if the specified encoding is not supported.
-
ReInit
Reinitializes the lexer with a new input stream, starting at the given line and column, with a specified buffer size.This method sets up the lexer to read from a new input stream. The lexer will start tokenizing from the specified line and column, and will use the provided buffer size for reading the input.
- Parameters:
dstream
- The new input stream to be used by the lexer. This stream provides the source of characters to be tokenized.startline
- The line number at which to start tokenizing. Line numbers are 1-based.startcolumn
- The column number at which to start tokenizing. Column numbers are 1-based.buffersize
- The size of the buffer to be used for reading the input stream.
-
ReInit
Reinitializes the lexer with a new input stream, specified encoding, starting at the first line and column, and using a default buffer size.This method sets up the lexer to read from a new input stream, using the specified character encoding, starting from line 1 and column 1, and using a default buffer size of 4096 characters.
- Parameters:
dstream
- The new input stream to be used by the lexer. This stream provides the source of characters to be tokenized.encoding
- The character encoding to be used for interpreting the bytes from the input stream. If this isnull
, the default encoding will be used.- Throws:
UnsupportedEncodingException
- if the specified encoding is not supported.
-
ReInit
Reinitializes the lexer with a new input stream, starting at line 1 and column 1, with a default buffer size.This method resets the lexer to start reading from the provided input stream. The tokenization process will begin at line 1 and column 1 of the new input. The buffer size used for reading the input is set to the default value of 4096 characters.
- Parameters:
dstream
- The new input stream to be used by the lexer. This stream provides the source of characters to be tokenized.
-
ReInit
public void ReInit(InputStream dstream, String encoding, int startline, int startcolumn) throws UnsupportedEncodingException Reinitializes the lexer with a new input stream, specified encoding, and starting line and column.This method allows the lexer to be reset with a new input stream, including the option to specify the character encoding. Additionally, it sets the starting line and column numbers for tokenization. This is useful for handling different input sources or encoding formats while ensuring accurate line and column tracking.
- Parameters:
dstream
- The new input stream to be used by the lexer. This stream provides the source of characters to be tokenized.encoding
- The name of the character encoding to be used for reading the input stream. If the encoding is not supported, an `UnsupportedEncodingException` will be thrown.startline
- The line number at which tokenization should begin. This helps in aligning the lexer with the correct line number in the input.startcolumn
- The column number at which tokenization should begin. This assists in aligning the lexer with the correct column position within the line.- Throws:
UnsupportedEncodingException
- If the specified encoding is not supported by the Java runtime.
-
ReInit
Reinitializes the lexer with a new input stream and specified starting line and column.This method allows for resetting the lexer with a new input stream, and optionally specifying the starting line and column numbers for tokenization. This is useful for cases where the lexer needs to be reused for different input streams or to start tokenization from a specific position.
- Parameters:
dstream
- The new input stream to be used by the lexer.startline
- The line number at which tokenization should begin. This is typically used to set the starting line for the lexer to match the input stream's context.startcolumn
- The column number at which tokenization should begin. This helps in aligning the lexer with the input stream's context starting from a specific column.
-
GetImage
Retrieves the literal value of the current token from the internal buffer.This method returns a
String
representing the sequence of characters in the buffer that corresponds to the current token. The literal value is the substring of the buffer from the start of the token to the current buffer position.- Returns:
- A
String
containing the literal value of the current token.
-
GetSuffix
public char[] GetSuffix(int len) Retrieves a suffix of the internal buffer.This method returns a character array that represents the suffix of the buffer, starting from the current buffer position and extending back by the specified length.
- Parameters:
len
- The length of the suffix to retrieve.- Returns:
- A character array containing the suffix of the buffer.
- Throws:
IllegalArgumentException
- if the length specified is greater than the size of the buffer.
-
Done
public void Done()Reset buffer when finished. -
adjustBeginLineColumn
public void adjustBeginLineColumn(int newLine, int newCol) Adjusts the line and column numbers for the start of a token.This method updates the line and column numbers in the internal buffer to reflect changes in the position of the start of a token. It recalculates the line and column numbers based on the new starting position of the token.
- Parameters:
newLine
- The new line number where the token begins.newCol
- The new column number where the token begins.
-