Package jpicedt.format.input
Class DefaultParser
- java.lang.Object
-
- jpicedt.format.input.util.AbstractRegularExpression
-
- jpicedt.format.input.util.SequenceExpression
-
- jpicedt.format.input.DefaultParser
-
- All Implemented Interfaces:
ExpressionConstants,Parser
public class DefaultParser extends SequenceExpression implements ExpressionConstants, Parser
Default implementation of the Parser interface.This expression doesn't contains rules in itself. On the contrary, it simply lumps sub-trees together, each sub-tree containing grammar rules for a particular format, e.g. PsTricks, eepic,...
Basically, this parser hold data using three objects :
- an instance of util.Pool : this stores persistent data, and allow them to be shared by AbstractRegularExpression's across the whole parser tree.
- an instance of util.Context : this holds the current state of the lexicographic analyser (line number, caret position, block boundaries, etc...)
- an instance of AlternateExpression : this holds a reference to the various supported grammars by mixing them into a single tree.
[Developpers] for those willing to add their own parser to the tree, simply write a new parser-tree whose root expression inherits from
RootExpression, then add it to this parser by using theaddGrammarmethod.- Since:
- jpicedt 1.2
- Version:
- $Id: DefaultParser.java,v 1.8.2.1 2007/09/02 11:56:00 reynal Exp $
- Author:
- Sylvain Reynal
-
-
Field Summary
Fields Modifier and Type Field Description protected Contextcontextholds information about the current parser stateprotected AlternateExpressionheadExpholds a reference to each supported grammarprotected Poolpoola pool of primitive types and objects that may be shared by sub-expressions-
Fields inherited from interface jpicedt.format.input.util.ExpressionConstants
ANY_CHAR, ANY_CHAR_EOL, ANY_SIGN, AT_LEAST, AT_MOST, DEBUG, DOUBLE, EOL, EXACTLY, INTEGER, NEGATIVE, NON_NULL, POSITIVE, STRICTLY_NEGATIVE, STRICTLY_POSITIVE, WHITE_SPACES, WHITE_SPACES_OR_EOL
-
-
Constructor Summary
Constructors Constructor Description DefaultParser()Creates a new DefaultParser, and attach some grammar rules to it.
Tree structure = (WhiteSpaceOrEOL & (headExp | notParsable))*
where : headExp = Root1 | Root2 | Root3 ...
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGrammar(RootExpression root)Add a new sub-tree to this parserPoolgetPool()Return the pool containing variables shared across the grammar treestatic voidmain(java.lang.String[] arg)parser standalone testDrawingparse(java.io.Reader reader)kicks off the parsing processjava.lang.StringtoString()-
Methods inherited from class jpicedt.format.input.util.SequenceExpression
add, interpret
-
Methods inherited from class jpicedt.format.input.util.AbstractRegularExpression
action
-
-
-
-
Field Detail
-
pool
protected Pool pool
a pool of primitive types and objects that may be shared by sub-expressions
-
context
protected Context context
holds information about the current parser state
-
headExp
protected AlternateExpression headExp
holds a reference to each supported grammar
-
-
Constructor Detail
-
DefaultParser
public DefaultParser()
Creates a new DefaultParser, and attach some grammar rules to it.
Tree structure = (WhiteSpaceOrEOL & (headExp | notParsable))*
where : headExp = Root1 | Root2 | Root3 ... (each RootX sub-tree representing a particular format).Note that with this current structure, sub-trees must NOT be mutually exclusive, ie it's ok with eepic and pstricks for instance (it wouldn't work with PDF and LaTeX, since once we've started with PDF, it wouldn't make sense trying to parse LaTeX commands...) ->
-
-
Method Detail
-
addGrammar
public void addGrammar(RootExpression root)
Add a new sub-tree to this parser
-
getPool
public Pool getPool()
Return the pool containing variables shared across the grammar tree
-
parse
public Drawing parse(java.io.Reader reader) throws REParserException
kicks off the parsing process- Specified by:
parsein interfaceParser- Returns:
- a new instance of a Drawing populated from the content of the given reader
- Throws:
REParserException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classSequenceExpression- Returns:
- a String representation of this Parser, i.e. global variables contents
-
main
public static void main(java.lang.String[] arg)
parser standalone test- Parameters:
arg- [0] name of file to parse.
-
-