Module bison :: Class BisonParser
[show private | hide private]
[frames | no frames]

Class BisonParser

object --+
         |
        BisonParser


Base parser class

You should subclass this, and provide a bunch of methods called 'on_TargetName', where 'TargetName' is the name of each target in your grammar (.y) file.
Method Summary
  __init__(self, **kw)
Abstract representation of parser
  __getitem__(self, idx)
  error(self, value)
Return the result of this method from a handler to notify a syntax error
  loadxml(self, raw, namespace)
Loads a parse tree from raw xml text
  loadxmldoc(self, xmldoc, namespace)
Returns a reconstituted parse tree, loaded from an xml.dom.minidom.Document instance
  loadxmlobj(self, xmlobj, namespace)
Returns a node object, being a parse tree, reconstituted from an xml.dom.minidom.Element object
  read(self, nbytes)
Override this in your subclass, if you desire.
  run(self, **kw)
Runs the parser, and returns the top-most parse target.
  toprettyxml(self)
Returns a human-readable xml representation of the parse tree
  toxml(self)
Serialises the parse tree and returns it as a raw xml string
  toxmldoc(self)
Returns an xml.dom.minidom.Document object containing the parse tree
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)
    Inherited from type
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T

Class Variable Summary
str bisonCFile = 'tmp.tab.c'
str bisonCFile1 = 'tmp.bison.c'
list bisonCmd = ['bison', '-d', '-v', '-t']
NoneType bisonEngineLibName = None                                                                  
str bisonFile = 'tmp.y'
str bisonHFile = 'tmp.tab.h'
str bisonHFile1 = 'tokens.h'
classobj defaultNodeClass = bison.BisonNode
NoneType file = None                                                                  
str flexCFile = 'lex.yy.c'
str flexCFile1 = 'tmp.lex.c'
list flexCmd = ['flex']
str flexFile = 'tmp.l'
int keepfiles = 0                                                                     
NoneType last = None                                                                  
NoneType lasterror = None                                                                  
int verbose = 0                                                                     

Method Details

__init__(self, **kw)
(Constructor)

Abstract representation of parser

Keyword arguments:
  • read - a callable accepting an int arg (nbytes) and returning a string, default is this class' read() method
  • file - a file object, or string of a pathname to open as a file, defaults to sys.stdin. Note that you can leave this blank, and pass a file keyword argument to the .run() method.
  • verbose - set to 1 to enable verbose output messages, default 0
  • keepfiles - if non-zero, keeps any files generated in the course of building the parser engine; by default, all these files get deleted upon a successful engine build
  • defaultNodeClass - the class to use for creating parse nodes, default is self.defaultNodeClass (in this base class, BisonNode)
Overrides:
__builtin__.object.__init__

error(self, value)

Return the result of this method from a handler to notify a syntax error

loadxml(self, raw, namespace=None)

Loads a parse tree from raw xml text

Stores it in the '.last' attribute, which is where the root node of parsed text gets stored

Arguments:
  • raw - string containing the raw xml
  • namespace - a dict or module object, where the node classes required for reconstituting the parse tree, can be found
Returns:
  • root node object of reconstituted parse tree

loadxmldoc(self, xmldoc, namespace=None)

Returns a reconstituted parse tree, loaded from an xml.dom.minidom.Document instance

Arguments:
  • xmldoc - an xml.dom.minidom.Document instance
  • namespace - a dict from which to find the classes needed to translate the document into a tree of parse nodes

loadxmlobj(self, xmlobj, namespace=None)

Returns a node object, being a parse tree, reconstituted from an xml.dom.minidom.Element object

Arguments:
  • xmlobj - an xml.dom.minidom.Element instance
  • namespace - a namespace from which the node classes needed for reconstituting the tree, can be found

read(self, nbytes)

Override this in your subclass, if you desire.

Arguments:
  • nbytes - the maximum length of the string which you may return. DO NOT return a string longer than this, or else Bad Things will happen.

run(self, **kw)

Runs the parser, and returns the top-most parse target.

Keywords:
  • file - either a string, comprising a file to open and read input from, or a Python file object
  • debug - enables garrulous parser debugging output, default 0

toprettyxml(self)

Returns a human-readable xml representation of the parse tree

toxml(self)

Serialises the parse tree and returns it as a raw xml string

toxmldoc(self)

Returns an xml.dom.minidom.Document object containing the parse tree

Class Variable Details

bisonCFile

Type:
str
Value:
'tmp.tab.c'                                                            

bisonCFile1

Type:
str
Value:
'tmp.bison.c'                                                          

bisonCmd

Type:
list
Value:
['bison', '-d', '-v', '-t']                                            

bisonEngineLibName

Type:
NoneType
Value:
None                                                                  

bisonFile

Type:
str
Value:
'tmp.y'                                                                

bisonHFile

Type:
str
Value:
'tmp.tab.h'                                                            

bisonHFile1

Type:
str
Value:
'tokens.h'                                                             

file

Type:
NoneType
Value:
None                                                                  

flexCFile

Type:
str
Value:
'lex.yy.c'                                                             

flexCFile1

Type:
str
Value:
'tmp.lex.c'                                                            

flexCmd

Type:
list
Value:
['flex']                                                               

flexFile

Type:
str
Value:
'tmp.l'                                                                

keepfiles

Type:
int
Value:
0                                                                     

last

Type:
NoneType
Value:
None                                                                  

lasterror

Type:
NoneType
Value:
None                                                                  

verbose

Type:
int
Value:
0                                                                     

Generated by Epydoc 2.0 on Sun Jun 27 12:36:56 2004 http://epydoc.sf.net