public abstract class AbstractFSMParser<I> extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractFSMParser.Part
An enumeration for the three parts in the FSM file.
|
Modifier and Type | Field and Description |
---|---|
static String |
EXPECT_CHAR |
static String |
EXPECT_IDENTIFIER |
static String |
EXPECT_NUMBER |
static String |
EXPECT_STRING |
static String |
NO_SUCH_STATE |
static String |
NON_DETERMINISM_DETECTED |
protected @Nullable Collection<? extends I> |
targetInputs
The set that contains all inputs that end up in the input alphabet (provided by the user, may be
null ). |
Modifier | Constructor and Description |
---|---|
protected |
AbstractFSMParser(@Nullable Collection<? extends I> targetInputs,
Function<String,I> inputParser)
Constructs a new AbstractFSMParser and defines all possible tokens.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
checkDataDefinitions(StreamTokenizer streamTokenizer)
Perform some actions after all data definitions have been parsed.
|
protected abstract void |
checkStateVectors(StreamTokenizer streamTokenizer)
Perform some actions after all state vectors have been parsed.
|
protected abstract void |
checkTransitions(StreamTokenizer streamTokenizer)
Perform some actions after all transitions have been parsed.
|
protected Function<String,I> |
getInputParser()
Gets the function that transforms strings in the FSM file to input.
|
protected Set<I> |
getInputs()
Gets the set that contains all inputs that end up in the input alphabet.
|
protected int |
getPartLineNumber()
Returns the line number that is being parsed in the current part.
|
protected StreamTokenizer |
getStreamTokenizer(Reader reader)
Gets the StreamTokenizer, that tokenizes tokens in the FSM file.
|
protected void |
parse(Reader reader)
Parsed the FSM file line-by-line.
|
protected abstract void |
parseDataDefinition(StreamTokenizer streamTokenizer)
Parse a data definition.
|
protected abstract void |
parseStateVector(StreamTokenizer streamTokenizer)
Parse a state vector.
|
protected abstract void |
parseTransition(StreamTokenizer streamTokenizer)
Parse a transition.
|
public static final String NO_SUCH_STATE
public static final String NON_DETERMINISM_DETECTED
public static final String EXPECT_CHAR
public static final String EXPECT_NUMBER
public static final String EXPECT_IDENTIFIER
public static final String EXPECT_STRING
protected final @Nullable Collection<? extends I> targetInputs
null
).protected AbstractFSMParser(@Nullable Collection<? extends I> targetInputs, Function<String,I> inputParser)
targetInputs
- An collection containing the inputs which should constitute the input alphabet of the parsed automaton.
If null
, the inputs will be automatically gathered from the read FSM file.inputParser
- the Function that parses strings in the FSM file to input.protected Function<String,I> getInputParser()
protected int getPartLineNumber()
protected StreamTokenizer getStreamTokenizer(Reader reader)
reader
- the source of the FSM fileprotected Set<I> getInputs()
protected abstract void parseDataDefinition(StreamTokenizer streamTokenizer) throws IOException
streamTokenizer
- tokenizer containing the inputFSMFormatException
- when the FSM source is invalid.IOException
- when FSM source could not be read.protected abstract void checkDataDefinitions(StreamTokenizer streamTokenizer) throws IOException
streamTokenizer
- tokenizer containing the inputFSMFormatException
- when the FSM source is invalid.IOException
- when FSM source could not be read.protected abstract void parseStateVector(StreamTokenizer streamTokenizer) throws IOException
streamTokenizer
- tokenizer containing the inputFSMFormatException
- when the FSM source is invalid.IOException
- when FSM source could not be read.protected abstract void checkStateVectors(StreamTokenizer streamTokenizer) throws IOException
streamTokenizer
- tokenizer containing the inputFSMFormatException
- when the FSM source is invalid.IOException
- when FSM source could not be read.protected abstract void parseTransition(StreamTokenizer streamTokenizer) throws IOException
streamTokenizer
- tokenizer containing the inputFSMFormatException
- when the FSM source is invalid.IOException
- when FSM source could not be read.protected abstract void checkTransitions(StreamTokenizer streamTokenizer) throws IOException
streamTokenizer
- tokenizer containing the inputFSMFormatException
- when the FSM source is invalid.IOException
- when FSM source could not be read.protected void parse(Reader reader) throws IOException
parseDataDefinition(StreamTokenizer)
for each data definition. After "---" is encountered checkDataDefinitions(StreamTokenizer)
is called,
and this method expects to parse state vectors. The behavior is similar for state vectors and transitions.
For each line this method will increment partLineNumber
, and reset it when a new part in the FSM file
begins.
Note that StreamTokenizer
allows one to push back tokens. This is used whenever we have checked type
type of token we are going to read.reader
- the source of the FSM fileFSMFormatException
- when the FSM source is invalid.IOException
- when FSM source could not be read.Copyright © 2020. All rights reserved.