satc
Class MultiStateLexer

satc.MultiStateLexer

public class MultiStateLexer

A Lexer using "states" to support multiple-line tokens. The use of states allows lines to be (re)scanned individually (provided that their start state is known, normally after a previous full document scan).

In this implementation, each state has its own lexer. This class is a wrapper around ANTLR TokenSteamSelector, with additional support for state switch and with different names.


Inner Class Summary
static interface MultiStateLexer.LexerCallback
          Interface for a callback lexer action.
 
Field Summary
 satc.LexerSharedInputState inputState
           
 java.io.InputStream inputStream
           
 satc.TokenStreamSelector selector
           
 
Constructor Summary
MultiStateLexer()
          Creates a new multiple state lexer.
MultiStateLexer(java.io.InputStream inputStream)
          Creates a new multiple state lexer.
 
Method Summary
 void addStateLexer(satc.CharScanner lexer, java.lang.String state)
          Adds a new state to the lexer.
 java.lang.String getCurrentState()
          Returns the name of the current state of the lexer.
 satc.Token nextToken()
          Fetches the next token.
 void reset()
          This method resets the lexer.
 void scan(MultiStateLexer.LexerCallback action)
          Scan the current range of the input executing action on each token.
 void setRange(int p0, int p1, java.lang.String state)
          Restricts the lexer scan range to start at index p0 and end at p1.
 void setState(java.lang.String state)
          Sets the current state of the lexer.
 void setSwitch(int tokenType, java.lang.String state)
          Makes the lexer switch to state state when a token of type tokenType is encontered.
 

Field Detail

inputStream

public java.io.InputStream inputStream

selector

public satc.TokenStreamSelector selector

inputState

public satc.LexerSharedInputState inputState
Constructor Detail

MultiStateLexer

public MultiStateLexer()
Creates a new multiple state lexer.

MultiStateLexer

public MultiStateLexer(java.io.InputStream inputStream)
Creates a new multiple state lexer.
Method Detail

reset

public void reset()
This method resets the lexer. The document stream is positioned at the begining and the state is set to mainLexer.

setRange

public void setRange(int p0,
                     int p1,
                     java.lang.String state)
Restricts the lexer scan range to start at index p0 and end at p1. The starting state is state.

addStateLexer

public void addStateLexer(satc.CharScanner lexer,
                          java.lang.String state)
Adds a new state to the lexer. The new state is called state and its associated lexer is lexer.

getCurrentState

public java.lang.String getCurrentState()
Returns the name of the current state of the lexer.

setState

public void setState(java.lang.String state)
Sets the current state of the lexer.

setSwitch

public void setSwitch(int tokenType,
                      java.lang.String state)
Makes the lexer switch to state state when a token of type tokenType is encontered.

nextToken

public satc.Token nextToken()
Fetches the next token. If necessary switches to a new lexer state.

scan

public void scan(MultiStateLexer.LexerCallback action)
Scan the current range of the input executing action on each token.