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=[{'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 = '', ), ], ), ...}, {'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', ), ...}, {'c_comment': LibraryElement( production = 'slashbang_comm...enerator.Generator instance at 0x2aaaad5dedd0>, ), 'c_nest_comment': LibraryElement( production = 'slashbang_nest...enerator.Generator instance at 0x2aaaad5e7170>, ), 'hash_comment': LibraryElement( production = 'hash_comment',...enerator.Generator instance at 0x2aaaad5d9128>, ), 'semicolon_comment': LibraryElement( production = 'semicolon_comm...enerator.Generator instance at 0x2aaaad5d9128>, ), 'slashbang_comment': LibraryElement( production = 'slashbang_comm...enerator.Generator instance at 0x2aaaad5dedd0>, ), 'slashbang_nest_comment': LibraryElement( production = 'slashbang_nest...enerator.Generator instance at 0x2aaaad5e7170>, ), 'slashslash_comment': LibraryElement( production = 'slashslash_com...enerator.Generator instance at 0x2aaaad5d9128>, )}, {'binary_number': LibraryElement( production = 'binary_number'...enerator.Generator instance at 0x2aaaad5f69e0>, ), 'float': LibraryElement( production = 'float', ge...enerator.Generator instance at 0x2aaaad5f69e0>, ), 'float_floatexp': LibraryElement( production = 'float_floatexp...enerator.Generator instance at 0x2aaaad5f69e0>, ), 'hex': LibraryElement( production = 'hex', gene...enerator.Generator instance at 0x2aaaad5f69e0>, ), 'imaginary_number': LibraryElement( production = 'imaginary_numb...enerator.Generator instance at 0x2aaaad5f69e0>, ), 'int': LibraryElement( production = 'int', gene...enerator.Generator instance at 0x2aaaad5f69e0>, ), 'int_unsigned': LibraryElement( production = 'int_unsigned',...enerator.Generator instance at 0x2aaaad5f69e0>, ), 'number': LibraryElement( production = 'number', g...enerator.Generator instance at 0x2aaaad5f69e0>, ), 'number_full': LibraryElement( production = 'number_full', ...enerator.Generator instance at 0x2aaaad5f69e0>, )}, {'ISO_date': LibraryElement( production = 'ISO_date', ...enerator.Generator instance at 0x2aaaad5dca28>, ), 'ISO_date_time': LibraryElement( production = 'ISO_date_time'...enerator.Generator instance at 0x2aaaad5dca28>, ), 'ISO_time': LibraryElement( production = 'ISO_time', ...enerator.Generator instance at 0x2aaaad5dca28>, )}, {'ISO_date_loose': LibraryElement( production = 'ISO_date_loose...enerator.Generator instance at 0x2aaaad6009e0>, ), 'ISO_date_time_loose': LibraryElement( production = 'ISO_date_time_...enerator.Generator instance at 0x2aaaad6009e0>, ), 'ISO_time_loose': LibraryElement( production = 'ISO_time_loose...enerator.Generator instance at 0x2aaaad6009e0>, )}, {'military_alphabet_char': FirstOfGroup( children = [ Literal( ...( value = 'Zulu', ), ], ), 'military_alphabet_char_lower': FirstOfGroup( children = [ Literal( ...( value = 'zulu', ), ], )}, {'string': LibraryElement( production = 'string', g...enerator.Generator instance at 0x2aaaad608d88>, ), 'string_double_quote': LibraryElement( production = 'str', gene...enerator.Generator instance at 0x2aaaad82b200>, ), 'string_single_quote': LibraryElement( production = 'str', gene...enerator.Generator instance at 0x2aaaad602680>, ), 'string_triple_double': LibraryElement( production = 'str', gene...enerator.Generator instance at 0x2aaaad5d95a8>, ), 'string_triple_single': LibraryElement( production = 'str', gene...enerator.Generator instance at 0x2aaaad827710>, )}, {'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.