|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--fri.patterns.interpreter.parsergenerator.builder.SerializedObject | +--fri.patterns.interpreter.parsergenerator.builder.SerializedLexer
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");
Field Summary | |
protected boolean |
PRODUCTION
|
Constructor Summary | |
SerializedLexer()
Create a Lexer factory that caches built Lexers. |
|
SerializedLexer(boolean production)
Create a Lexer factory that caches built Lexers. |
Method Summary | |
static java.lang.String |
baseNameFromSyntax(java.lang.Object syntaxInput)
When syntaxInput is a File, the name of the serialization file is created from its basename (without any extension), else "Unknown" is assumed as basename. |
Lexer |
buildAndStoreLexer(java.lang.Object syntaxInput,
java.lang.String baseName,
java.util.List tokenSymbols,
java.util.List ignoredSymbols)
Builds a lexer from passed syntax and stores it to a File (when PRODUCTION is true, this is default). |
protected java.lang.String |
ensureDirectory(java.lang.String fileName)
Creates the directory of passed filename if it does not exist. |
Lexer |
get(java.lang.Object syntaxInput)
Builds the Lexer from scratch if not found in filesystem, else loads the serialized Lexer. |
Lexer |
get(java.lang.Object syntaxInput,
java.lang.String baseName)
Builds the Lexer from scratch if not found in filesystem, else loads the serialized Lexer. |
Lexer |
get(java.lang.Object syntaxInput,
java.lang.String baseName,
java.util.List tokenSymbols,
java.util.List ignoredSymbols)
Builds the Lexer from scratch if not found in filesystem, else loads the serialized Lexer. |
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. |
static void |
main(java.lang.String[] args)
Test main. |
protected java.lang.String |
makeFilePath(java.lang.String fileName)
Puts the file into ".friware/parsers" directory in "user.home". |
protected LexerBuilder |
newLexerBuilder(Syntax syntax,
java.util.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. |
protected java.lang.Object |
read(java.lang.String fileName)
Deserializes an object from filesystem. |
Lexer |
readLexer(java.lang.Object syntaxInput,
java.lang.String baseName)
Tries to read the lexer from a serialized file. |
static Syntax |
toSyntax(java.lang.Object syntaxInput)
Converts a File, InputStream, Reader, String, StringBuffer, List of Lists or String[][] to a Syntax. |
protected boolean |
write(java.lang.String fileName,
java.lang.Object o)
Serializes an object to filesystem. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected boolean PRODUCTION
Constructor Detail |
public SerializedLexer()
public SerializedLexer(boolean production)
Method Detail |
public Lexer get(java.lang.Object syntaxInput) throws java.lang.Exception
syntaxInput
- the Lexer syntax as File, InputStream, List of Lists, String [][] or Syntax.
java.lang.Exception
public Lexer get(java.lang.Object syntaxInput, java.lang.String baseName) throws java.lang.Exception
syntaxInput
- the Lexer syntax as File, InputStream, List of Lists, String [][] or Syntax.baseName
- name of serialization file, can be null when syntaxInput is a File
java.lang.Exception
public Lexer get(java.lang.Object syntaxInput, java.lang.String baseName, java.util.List tokenSymbols, java.util.List ignoredSymbols) throws java.lang.Exception
syntaxInput
- the Lexer syntax as File, InputStream, List of Lists, String [][] or Syntax.baseName
- name of serialization file, can be null when syntaxInput is a FiletokenSymbols
- the token symbols when used by a prebuilt ParserignoredSymbols
- the ignored symbols when used by a prebuilt Parser
java.lang.Exception
public Lexer readLexer(java.lang.Object syntaxInput, java.lang.String baseName)
syntaxInput
- the lexer syntax input to retrieve a default name when it is a FilebaseName
- if baseName is "Xml", the file "XmlLexer.ser" will be read, can be nullpublic Lexer buildAndStoreLexer(java.lang.Object syntaxInput, java.lang.String baseName, java.util.List tokenSymbols, java.util.List ignoredSymbols) throws java.lang.Exception
syntaxInput
- the lexer syntax inputbaseName
- a file basename, if "Xml", the file "XmlLexer.ser" will be written
java.lang.Exception
protected SyntaxSeparation newSyntaxSeparation(Syntax syntax) throws SyntaxException
SyntaxException
protected LexerBuilder newLexerBuilder(Syntax syntax, java.util.List ignoredSymbols) throws LexerException, SyntaxException
LexerException
SyntaxException
public SyntaxSeparation getSyntaxSeparation()
public static void main(java.lang.String[] args)
protected java.lang.Object read(java.lang.String fileName)
protected boolean write(java.lang.String fileName, java.lang.Object o)
public static java.lang.String baseNameFromSyntax(java.lang.Object syntaxInput)
public static Syntax toSyntax(java.lang.Object syntaxInput) throws java.lang.Exception
java.lang.Exception
protected java.lang.String makeFilePath(java.lang.String fileName)
protected java.lang.String ensureDirectory(java.lang.String fileName)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |