simpleparse.parser
index
/home/mcfletch/pylive/simpleparse/parser.py

Real-world parsers using the SimpleParse EBNF

 
Modules
       
simpleparse.baseparser
simpleparse.common
simpleparse.simpleparsegrammar

 
Classes
       
BaseParser
Parser

 
class Parser(BaseParser)
    EBNF-generated Parsers with results-handling
 
The Parser is a two-stage object:
        Passed an EBNF definition during initialisation,
        it compiles the definition into a tagging table
        (which in turn requires creating a tagging table
        for parsing the EBNF).
 
        You then call the parser's parse method to
        perform the actual parsing of your data, with the
        parser passing the results to your processor object
        and then back to you.
 
  Methods defined here:
__init__(self, declaration, root='root', prebuilts=(), definitionSources=[{'EOF': Prebuilt( value = ((None, 101, 1),), ), 'ascii_letter': Range( value = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ), 'ascii_letters': Range( repeating = 1, value = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ), 'ascii_lowercase': Range( repeating = 1, value = 'abcdefghijklmnopqrstuvwxyz', ), 'ascii_lowercasechar': Range( value = 'abcdefghijklmnopqrstuvwxyz', ), 'ascii_uppercase': Range( repeating = 1, value = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', ), 'ascii_uppercasechar': Range( value = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', ), 'digit': Range( value = '0123456789', ), 'digits': Range( repeating = 1, value = '0123456789', ), 'hexdigit': Range( value = '0123456789abcdefABCDEF', ), ...}, {'locale_day_abbrs': FirstOfGroup( children = [ Literal( ...l( value = 'Fri', ), ], ), 'locale_day_abbrs_lc': FirstOfGroup( children = [ Literal( ...l( value = 'fri', ), ], ), 'locale_day_abbrs_uc': FirstOfGroup( children = [ Literal( ...l( value = 'FRI', ), ], ), 'locale_day_names': FirstOfGroup( children = [ Literal( ... value = 'Friday', ), ], ), 'locale_day_names_lc': FirstOfGroup( children = [ Literal( ... value = 'friday', ), ], ), 'locale_day_names_uc': FirstOfGroup( children = [ Literal( ... value = 'FRIDAY', ), ], ), 'locale_month_abbrs': FirstOfGroup( children = [ Literal( ...eral( value = '', ), ], ), 'locale_month_abbrs_lc': FirstOfGroup( children = [ Literal( ...eral( value = '', ), ], ), 'locale_month_abbrs_uc': FirstOfGroup( children = [ Literal( ...eral( value = '', ), ], ), 'locale_month_names': FirstOfGroup( children = [ Literal( ...eral( value = '', ), ], ), ...}, {'c_comment': LibraryElement( production = 'slashbang_comm...rse.generator.Generator instance at 0x65d0488>, ), 'c_nest_comment': LibraryElement( production = 'slashbang_nest...rse.generator.Generator instance at 0x63a4680>, ), 'hash_comment': LibraryElement( production = 'hash_comment',...rse.generator.Generator instance at 0x61c9ea8>, ), 'semicolon_comment': LibraryElement( production = 'semicolon_comm...rse.generator.Generator instance at 0x61c9ea8>, ), 'slashbang_comment': LibraryElement( production = 'slashbang_comm...rse.generator.Generator instance at 0x65d0488>, ), 'slashbang_nest_comment': LibraryElement( production = 'slashbang_nest...rse.generator.Generator instance at 0x63a4680>, ), 'slashslash_comment': LibraryElement( production = 'slashslash_com...rse.generator.Generator instance at 0x61c9ea8>, )}, {'binary_number': LibraryElement( production = 'binary_number'...rse.generator.Generator instance at 0x639a998>, ), 'float': LibraryElement( production = 'float', ge...rse.generator.Generator instance at 0x639a998>, ), 'float_floatexp': LibraryElement( production = 'float_floatexp...rse.generator.Generator instance at 0x639a998>, ), 'hex': LibraryElement( production = 'hex', gene...rse.generator.Generator instance at 0x639a998>, ), 'imaginary_number': LibraryElement( production = 'imaginary_numb...rse.generator.Generator instance at 0x639a998>, ), 'int': LibraryElement( production = 'int', gene...rse.generator.Generator instance at 0x639a998>, ), 'int_unsigned': LibraryElement( production = 'int_unsigned',...rse.generator.Generator instance at 0x639a998>, ), 'number': LibraryElement( production = 'number', g...rse.generator.Generator instance at 0x639a998>, ), 'number_full': LibraryElement( production = 'number_full', ...rse.generator.Generator instance at 0x639a998>, )}, {'ISO_date': LibraryElement( production = 'ISO_date', ...rse.generator.Generator instance at 0x65ca758>, ), 'ISO_date_time': LibraryElement( production = 'ISO_date_time'...rse.generator.Generator instance at 0x65ca758>, ), 'ISO_time': LibraryElement( production = 'ISO_time', ...rse.generator.Generator instance at 0x65ca758>, )}, {'ISO_date_loose': LibraryElement( production = 'ISO_date_loose...rse.generator.Generator instance at 0x63a0e60>, ), 'ISO_date_time_loose': LibraryElement( production = 'ISO_date_time_...rse.generator.Generator instance at 0x63a0e60>, ), 'ISO_time_loose': LibraryElement( production = 'ISO_time_loose...rse.generator.Generator instance at 0x63a0e60>, )}, {'military_alphabet_char': FirstOfGroup( children = [ Literal( ...( value = 'Zulu', ), ], ), 'military_alphabet_char_lower': FirstOfGroup( children = [ Literal( ...( value = 'zulu', ), ], )}, {'string': LibraryElement( production = 'string', g...rse.generator.Generator instance at 0x6372cb0>, ), 'string_double_quote': LibraryElement( production = 'str', gene...rse.generator.Generator instance at 0x65ce248>, ), 'string_single_quote': LibraryElement( production = 'str', gene...rse.generator.Generator instance at 0x63b0ef0>, ), 'string_triple_double': LibraryElement( production = 'str', gene...rse.generator.Generator instance at 0x6393c68>, ), 'string_triple_single': LibraryElement( production = 'str', gene...rse.generator.Generator instance at 0x63999e0>, )}, {'civilian_timezone_name': FirstOfGroup( children = [ Literal( ... value = 'ACSST', ), ], ), 'military_timezone_name': FirstOfGroup( children = [ Literal( ...ral( value = 'A', ), ], ), 'timezone_name': FirstOfGroup( children = [ Literal( ...ral( value = 'A', ), ], )}])
Initialise the parser, creating the tagging table for it
 
declaration -- simpleparse ebnf declaration of the language being parsed
root -- root production used for parsing if none explicitly specified
prebuilts -- sequence of (name,value) tuples with prebuilt tables, values
        can be either objectgenerator EventToken sub-classes or TextTools
        tables
definitionSources -- dictionaries of common constructs for use
        in building your grammar
buildTagger(self, production=None, processor=None)
Get a particular parsing table for a particular production

Methods inherited from BaseParser:
buildProcessor(self)
Build default processor object for this parser class
 
The default implementation returns None.  The processor
can either implement the "method source" API (just provides
information about Callouts and the like), or the processor
API and the method-source API.  The processor API merely
requires that the object be callable, and have the signature:
 
        object( (success, children, nextPosition), buffer)
 
(Note: your object can treat the first item as a single tuple
if it likes).
 
See: simpleparse.processor module for details.
parse(self, data, production=None, processor=None, start=0, stop=None)
Parse data with production "production" of this parser
 
data -- data to be parsed, a Python string, for now
production -- optional string specifying a non-default production to use
        for parsing data
processor -- optional pointer to a Processor or MethodSource object for
        use in determining reporting format and/or post-processing the results
        of the parsing pass.  Can be None if neither is desired (default)
start -- starting index for the parsing, default 0
stop -- stoping index for the parsing, default len(data)
resetBeforeParse(self)
Called just before the parser's parse method starts working,
 
Allows you to set up special-purpose structures, such as stacks
or local storage values.  There is no base implementation.  The
base implementation does nothing.

 
Data
        __file__ = '/home/mcfletch/pylive/simpleparse/parser.pyc'
__name__ = 'simpleparse.parser'
__package__ = 'simpleparse'