http://www.jpicedt.org

jpicedt.format.input
Class DefaultParser

java.lang.Object
  extended by jpicedt.format.input.util.AbstractRegularExpression
      extended by jpicedt.format.input.util.SequenceExpression
          extended by jpicedt.format.input.DefaultParser
All Implemented Interfaces:
ExtractionParsing, Parser

public class DefaultParser
extends SequenceExpression
implements ExtractionParsing

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 :

[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 the addGrammar method.

Since:
jpicedt 1.2
Version:
$Id: DefaultParser.java,v 1.15 2013/03/31 07:00:15 vincentb1 Exp $
Author:
Sylvain Reynal

Field Summary
protected  Context context
          holds information about the current parser state
protected  AlternateExpression headExp
          holds a reference to each supported grammar
protected  Pool pool
          a pool of primitive types and objects that may be shared by sub-expressions
 
Constructor Summary
DefaultParser()
          Creates a new DefaultParser, and attach some grammar rules to it.
 
Method Summary
 void addGrammar(RootExpression root)
          Add a new sub-tree to this parser
 ParsedDrawing extractAndParse(Reader reader)
          Extraction d'un dessin codé à partir d'un fichier, et analyse syntaxique de ce dessin codé.
 Pool getPool()
          Return the pool containing variables shared across the grammar tree
static void main(String[] arg)
          parser standalone test
 Drawing parse(Reader reader)
          pour compatibilité ascendante.
 void parse(Reader reader, ParsedDrawing parsedDrawing)
          kicks off the parsing process
 String toString()
           
 
Methods inherited from class jpicedt.format.input.util.SequenceExpression
add, interpret
 
Methods inherited from class jpicedt.format.input.util.AbstractRegularExpression
action
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 void parse(Reader reader,
                  ParsedDrawing parsedDrawing)
           throws REParserException
kicks off the parsing process

Specified by:
parse in interface Parser
Throws:
REParserException

parse

public Drawing parse(Reader reader)
              throws REParserException
pour compatibilité ascendante.

Specified by:
parse in interface Parser
Returns:
Un nouvel expample d'un Drawing peuplé des objets graphiques résultant des l'analyse des données lues par le reader passé en argument.
Throws:
REParserException
Since:
JPicEdt 1.6

toString

public String toString()
Overrides:
toString in class SequenceExpression
Returns:
a String representation of this Parser, i.e. global variables contents

main

public static void main(String[] arg)
parser standalone test

Parameters:
arg - arg[0] is the name of file to parse.

extractAndParse

public ParsedDrawing extractAndParse(Reader reader)
                              throws ParserException
Extraction d'un dessin codé à partir d'un fichier, et analyse syntaxique de ce dessin codé.

Specified by:
extractAndParse in interface ExtractionParsing
Parameters:
reader - lecteur du fichier d'où extraire le dessin codé à analyser
Throws:
ParserException
Since:
jPicEdt 1.6

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org