| java.lang.Object fri.patterns.interpreter.parsergenerator.builder.SerializedObject fri.patterns.interpreter.parsergenerator.builder.SerializedLexer
SerializedLexer | public class SerializedLexer extends SerializedObject (Code) | | Buffering Lexers. SerializedLexer will build the Lexer from scratch
only the first time. Every following call will load the serialized Lexer
from filesystem.
The time to build a lexer from scratch is equal to deserializing it
in most cases. So a standalone lexer can be built without this class.
When needed for a Parser, use the SerializedParser factory!
This factory will separate the passed syntax into parser and lexer syntax if
token and ignored symbol Lists are null. So take care to use "token" and "ignored"
rules within syntax to achieve the desired result!
Example (syntax input from a file):
File ebnfFile = ...;
Lexer lexer = new SerializedLexer().get(ebnfFile);
or (syntax input from a Reader, must pass a filename):
Reader ebnfReader = ...;
Lexer lexer = new SerializedLexer().get(ebnfReader, "MyLexer.ser");
author: (c) 2002, Fritz Ritzberger |
Constructor Summary | |
public | SerializedLexer() Create a Lexer factory that caches built Lexers. | public | SerializedLexer(boolean production) Create a Lexer factory that caches built Lexers. |
Method Summary | |
public Lexer | buildAndStoreLexer(Object syntaxInput, String baseName, List tokenSymbols, List ignoredSymbols) Builds a lexer from passed syntax and stores it to a File (when PRODUCTION is true, this is default). | public Lexer | get(Object syntaxInput) Builds the Lexer from scratch if not found in filesystem, else loads the serialized Lexer.
Parameters: syntaxInput - the Lexer syntax as File, InputStream, List of Lists, String [][] or Syntax. | public Lexer | get(Object syntaxInput, String baseName) Builds the Lexer from scratch if not found in filesystem, else loads the serialized Lexer. | public Lexer | get(Object syntaxInput, String baseName, List tokenSymbols, List ignoredSymbols) Builds the Lexer from scratch if not found in filesystem, else loads the serialized Lexer. | public SyntaxSeparation | getSyntaxSeparation() If the lexer was built from scratch, the SyntaxSeparation object returned
will not be null and can be used to retrieve the parser syntax, else
null is returned, as the separation is not available in serialized Lexer. | public static void | main(String[] args) Test main. | protected LexerBuilder | newLexerBuilder(Syntax syntax, List ignoredSymbols) To be overridden when a modified LexerBuilder is needed. | protected SyntaxSeparation | newSyntaxSeparation(Syntax syntax) To be overridden when a modified SyntaxSeparation is needed. | public Lexer | readLexer(Object syntaxInput, String baseName) Tries to read the lexer from a serialized file. |
PRODUCTION | protected boolean PRODUCTION(Code) | | |
SerializedLexer | public SerializedLexer()(Code) | | Create a Lexer factory that caches built Lexers.
|
SerializedLexer | public SerializedLexer(boolean production)(Code) | | Create a Lexer factory that caches built Lexers. @param production when false the Lexer will not be serialized.
|
buildAndStoreLexer | public Lexer buildAndStoreLexer(Object syntaxInput, String baseName, List tokenSymbols, List ignoredSymbols) throws Exception(Code) | | Builds a lexer from passed syntax and stores it to a File (when PRODUCTION is true, this is default).
Parameters: syntaxInput - the lexer syntax input Parameters: baseName - a file basename, if "Xml", the file "XmlLexer.ser" will be written |
get | public Lexer get(Object syntaxInput) throws Exception(Code) | | Builds the Lexer from scratch if not found in filesystem, else loads the serialized Lexer.
Parameters: syntaxInput - the Lexer syntax as File, InputStream, List of Lists, String [][] or Syntax. deserialized Lexer, or one built from scratch that gets written to filesystem. |
get | public Lexer get(Object syntaxInput, String baseName) throws Exception(Code) | | Builds the Lexer from scratch if not found in filesystem, else loads the serialized Lexer.
Parameters: syntaxInput - the Lexer syntax as File, InputStream, List of Lists, String [][] or Syntax. Parameters: baseName - name of serialization file, can be null when syntaxInput is a File deserialized Lexer, or one built from scratch that gets written to filesystem. |
get | public Lexer get(Object syntaxInput, String baseName, List tokenSymbols, List ignoredSymbols) throws Exception(Code) | | Builds the Lexer from scratch if not found in filesystem, else loads the serialized Lexer.
Parameters: syntaxInput - the Lexer syntax as File, InputStream, List of Lists, String [][] or Syntax. Parameters: baseName - name of serialization file, can be null when syntaxInput is a File Parameters: tokenSymbols - the token symbols when used by a prebuilt Parser Parameters: ignoredSymbols - the ignored symbols when used by a prebuilt Parser deserialized Lexer, or one built from scratch that gets written to filesystem. |
getSyntaxSeparation | public SyntaxSeparation getSyntaxSeparation()(Code) | | If the lexer was built from scratch, the SyntaxSeparation object returned
will not be null and can be used to retrieve the parser syntax, else
null is returned, as the separation is not available in serialized Lexer.
|
main | public static void main(String[] args)(Code) | | Test main. Building serialized Lexer takes 330, building from scratch takes 130 millis.
|
readLexer | public Lexer readLexer(Object syntaxInput, String baseName)(Code) | | Tries to read the lexer from a serialized file. One of the two arguments must be non-null.
Parameters: syntaxInput - the lexer syntax input to retrieve a default name when it is a File Parameters: baseName - if baseName is "Xml", the file "XmlLexer.ser" will be read, can be null |
|
|