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

Default SimpleParse EBNF grammar as a generator with productions
 
This module defines the original SimpleParse
grammar.  It uses the generator objects directly
as this is the first grammar being written.

 
Modules
       
simpleparse.baseparser
copy
simpleparse.generator
simpleparse.stt.TextTools.mxTextTools.mxTextTools
string
time
types

 
Classes
       
BaseParser
Parser
DispatchProcessor(Processor)
SPGrammarProcessor

 
class Parser(BaseParser)
    Parser which generates new parsers from EBNF grammars
 
This parser class allows you to pass in an EBNF grammar as
the initialisation parameter.  The EBNF is processed, and a
SimpleParse generator object is created as self.generator.
 
Unlike most Parsers, this object is intended to be re-created
for each bit of data it parses (i.e. each EBNF), so it warps
the standard API a lot.
 
  Methods defined here:
__init__(self, ebnf, prebuilts=(), methodSource=None, definitionSources=())
Create a new generator based on the EBNF in simpleparse format
buildTagger(self, name=None, processor=None)
Build the tag-table for parsing the EBNF for this parser

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.

 
class SPGrammarProcessor(DispatchProcessor)
    Processing object for post-processing an EBNF into a new generator
 
 
Method resolution order:
SPGrammarProcessor
DispatchProcessor
Processor
MethodSource

Methods defined here:
CHAR = CHARNODBLQUOTE(self, tup, buffer)
CHARBRACE(self, tup, buffer)
CHARDASH(self, tup, buffer)
CHARNOBRACE(self, (tag, left, right, sublist), buffer)
CHARNODBLQUOTE(self, tup, buffer)
CHARNOSNGLQUOTE = CHARNODBLQUOTE(self, tup, buffer)
CHARRANGE(self, (tag, left, right, sublist), buffer)
Create a string from first to second item
ESCAPEDCHAR(self, (tag, left, right, sublist), buffer)
HEXESCAPEDCHAR(self, tup, buffer)
OCTALESCAPEDCHAR(self, tup, buffer)
SPECIALESCAPEDCHAR(self, tup, buffer)
UNICODEESCAPEDCHAR_16(self, (tag, left, right, sublist), buffer)
Only available in unicode-aware Python versions
UNICODEESCAPEDCHAR_32 = UNICODEESCAPEDCHAR_16(self, (tag, left, right, sublist), buffer)
__init__(self, prebuilts=(), definitionSources=())
Create a new generator based on the EBNF in simpleparse format
declaration(self, (tag, left, right, sublist), buffer)
Base declaration from the grammar, a "production" or "rule"
element_token(self, (tag, left, right, sublist), buffer)
get the children, then configure
error_on_fail(self, (tag, left, right, children), buffer)
If present, we are going to make the current object an errorOnFail type,
 
If there's a string literal child, then we use it to create the
"message" attribute of the errorOnFail object.
fo_group(self, (tag, left, right, sublist), buffer)
Process a first-of-group into a FirstOf element token
literal(self, (tag, left, right, sublist), buffer)
Turn a literal result into a literal generator
lookahead_indicator(self, tup, buffer)
If present, the lookahead indictor just says "yes", so just return 1
name(self, tup, buffer)
negpos_indicator(self, tup, buffer)
return whether indicates negative
occurence_indicator(self, tup, buffer)
Return optional, repeating as a tuple of true/false values
range(self, (tag, left, right, sublist), buffer)
seq_group(self, (tag, left, right, sublist), buffer)
Process a sequential-group into a SequentialGroup element token

Data and other attributes defined here:
negposIndicatorMap = {'+': 0, '-': 1}
occurenceIndicatorMap = {'*': (1, 1), '+': (0, 1), '?': (1, 0)}
specialescapedmap = {'"': '"', "'": "'", r'\': r'\', 'a': '\x07', 'b': '\x08', 'f': '\x0c', 'n': '\n', 'r': '\r', 't': '\t', 'v': '\x0b'}

Methods inherited from DispatchProcessor:
__call__(self, value, buffer)
Process the results of the parsing run over buffer
 
Value can either be: (success, tags, next) for a top-level
production, or (tag, left, right, children) for a non-top
production.

Methods inherited from Processor:
__repr__(self)
Return a representation of the class

 
Functions
       
BMS = TextSearch(...)
TextSearch(match[,translate=None,algorithm=default_algorithm])
 
Create a substring search object for the string match;
translate is an optional translate-string like the one used
in the module re.
CharSet(...)
CharSet(definition)
 
Create a character set matching object from the string
FS = TextSearch(...)
TextSearch(match[,translate=None,algorithm=default_algorithm])
 
Create a substring search object for the string match;
translate is an optional translate-string like the one used
in the module re.
FSType = TextSearch(...)
TextSearch(match[,translate=None,algorithm=default_algorithm])
 
Create a substring search object for the string match;
translate is an optional translate-string like the one used
in the module re.
TagTable(...)
TagTable(definition[,cachable=1])
TextSearch(...)
TextSearch(match[,translate=None,algorithm=default_algorithm])
 
Create a substring search object for the string match;
translate is an optional translate-string like the one used
in the module re.
UnicodeTagTable(...)
TagTable(definition[,cachable=1])
charsplit(...)
charsplit(text,char,start=0,stop=len(text))
 
Split text[start:stop] into substrings at char and
return the result as list of strings.
cmp(...)
cmp(a,b)
 
Compare two valid taglist tuples w/r to their slice
position; this is useful for sorting joinlists.
hex2str(...)
hex2str(text)
 
Return text interpreted as two byte HEX values converted
to a string.
isascii(...)
isascii(text,start=0,stop=len(text))
 
Return 1/0 depending on whether text only contains ASCII
characters.
join(...)
join(joinlist,sep='',start=0,stop=len(joinlist))
 
Copy snippets from different strings together producing a
new string
The first argument must be a list of tuples or strings;
tuples must be of the form (string,l,r[,...]) and turn out
as string[l:r]
NOTE: the syntax used for negative slices is different
than the Python standard: -1 corresponds to the first
character *after* the string, e.g. ('Example',0,-1) gives
'Example' and not 'Exampl', like in Python
sep is an optional separator string, start and stop
define the slice of joinlist that is taken into accont.
joinlist(...)
joinlist(text,list,start=0,stop=len(text))
 
Takes a list of tuples (replacement,l,r,...) and produces
a taglist suitable for join() which creates a copy
of text where every slice [l:r] is replaced by the
given replacement
- the list must be sorted using cmp() as compare function
- it may not contain overlapping slices
- the slices may not contain negative indices
- if the taglist cannot contain overlapping slices, you can
  give this function the taglist produced by tag() directly
  (sorting is not needed, as the list will already be sorted)
- start and stop set the slice to work in, i.e. text[start:stop]
lower(...)
lower(text)
 
Return text converted to lower case.
prefix(...)
prefix(text,prefixes,start=0,stop=len(text)[,translate])
 
Looks at text[start:stop] and returns the first matching
prefix out of the tuple of strings given in prefixes.
If no prefix is found to be matching, None is returned.
The optional 256 char translate string is used to translate
the text prior to comparing it with the given suffixes.
set(...)
set(string,logic=1)
 
Returns a character set for string: a bit encoded version
of the characters occurring in string.
- logic can be set to 0 if all characters *not* in string
  should go into the set
setfind(...)
setfind(text,set,start=0,stop=len(text))
 
Find the first occurence of any character from set in
text[start:stop]
 set must be a string obtained with set()
DEPRECATED: use CharSet().search() instead.
setsplit(...)
setsplit(text,set,start=0,stop=len(text))
 
Split text[start:stop] into substrings using set,
omitting the splitting parts and empty substrings.
set must be a string obtained from set()
DEPRECATED: use CharSet().split() instead.
setsplitx(...)
setsplitx(text,set,start=0,stop=len(text))
 
Split text[start:stop] into substrings using set, so
that every second entry consists only of characters in set.
set must be a string obtained with set()
DEPRECATED: use CharSet().splitx() instead.
setstrip(...)
setstrip(text,set,start=0,stop=len(text),mode=0)
 
Strip all characters in text[start:stop] appearing in set.
mode indicates where to strip (<0: left; =0: left and right;
>0: right). set must be a string obtained with set()
DEPRECATED: use CharSet().strip() instead.
splitat(...)
splitat(text,char,nth=1,start=0,stop=len(text))
 
Split text[start:stop] into two substrings at the nth
occurance of char and return the result as 2-tuple. If the
character is not found, the second string is empty. nth may
be negative: the search is then done from the right and the
first string is empty in case the character is not found.
str2hex(...)
str2hex(text)
 
Return text converted to a string consisting of two byte
HEX values.
suffix(...)
suffix(text,suffixes,start=0,stop=len(text)[,translate])
 
Looks at text[start:stop] and returns the first matching
suffix out of the tuple of strings given in suffixes.
If no suffix is found to be matching, None is returned.
The optional 256 char translate string is used to translate
the text prior to comparing it with the given suffixes.
tag(...)
tag(text,tagtable,sliceleft=0,sliceright=len(text),taglist=[],context=None) 
Produce a tag list for a string, given a tag-table
- returns a tuple (success, taglist, nextindex)
- if taglist == None, then no taglist is created
upper(...)
upper(text)
 
Return text converted to upper case.

 
Data
        A2Z = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
A2Z_charset = <Character Set object for 'A-Z' at 0x4a5a238>
A2Z_set = '\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
AllIn = 11
AllInCharSet = 41
AllInSet = 31
AllNotIn = 12
AppendMatch = 2048
AppendTagobj = 1024
AppendToTagobj = 512
BOYERMOORE = 0
Break = 0
Call = 201
CallArg = 202
CallTag = 256
EOF = 101
FASTSEARCH = 1
Fail = 100
HAVE_UNICODE = 1
Here = 1
Is = 13
IsIn = 14
IsInCharSet = 42
IsInSet = 32
IsNot = 15
IsNotIn = 15
Jump = 100
JumpTarget = 104
LookAhead = 4096
Loop = 205
LoopControl = 206
MatchFail = -1000000
MatchOk = 1000000
Move = 103
NoWord = 211
Reset = -1
SPGenerator = <simpleparse.generator.Generator instance at 0x4b95b00>
Skip = 102
SubTable = 207
SubTableInList = 208
TRIVIAL = 2
Table = 203
TableInList = 204
ThisTable = 999
To = 0
ToBOF = 0
ToEOF = -1
Umlaute = '\xc4\xd6\xdc'
Umlaute_charset = <Character Set object for '\xc4\xd6\xdc' at 0x4a5a288>
Word = 21
WordEnd = 23
WordStart = 22
__file__ = '/home/mcfletch/pylive/simpleparse/simpleparsegrammar.pyc'
__name__ = 'simpleparse.simpleparsegrammar'
__package__ = 'simpleparse'
_seq_children = FirstOfGroup( children = [ Name( ...oken', ), ], terminalValue = 0, )
a2z = 'abcdefghijklmnopqrstuvwxyz'
a2z_charset = <Character Set object for 'a-z' at 0x4a5a210>
a2z_set = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
alpha_charset = <Character Set object for 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' at 0x4a5a2b0>
alpha_set = '\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\x07\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
alphanumeric = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
alphanumeric_charset = <Character Set object for 'ABCDEFGHIJKLMNOPQRSTU...cdefghijklmnopqrstuvwxyz0123456789' at 0x4a5a328>
alphanumeric_set = '\x00\x00\x00\x00\x00\x00\xff\x03\xfe\xff\xff\x07\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
any = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./...\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'
any_charset = <Character Set object for '\x00-\xff' at 0x4a5a418>
any_set = '\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'
characterrange = Name( terminalValue = 1, value = 'range', )
declaration = 'declarationset := declaration+\ndeclaration...,[0-9a-fA-F],[0-9a-fA-F],[0-9a-fA-F],[0-9a-fA-F]\n'
element_token = Name( terminalValue = 0, value = 'element_token', )
formfeed = '\x0c'
formfeed_charset = <Character Set object for '\x0c' at 0x4a5a3a0>
german_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\xe4\xf6\xfc\xdf\xc4\xd6\xdc'
german_alpha_charset = <Character Set object for 'ABCDEFGHIJKLMNOPQRSTU...uvwxyz\xe4\xf6\xfc\xdf\xc4\xd6\xdc' at 0x4a5a2d8>
german_alpha_set = '\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\x07\xfe\xff\xff\x07\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00@\x90\x10\x00@\x10'
group = Name( terminalValue = 0, value = 'group', )
id2cmd = {-1000000: 'MatchFail', -1: 'ToEOF', 0: 'Fail/Jump', 1: 'Here', 11: 'AllIn', 12: 'AllNotIn', 13: 'Is', 14: 'IsIn', 15: 'IsNotIn', 21: 'Word', ...}
literal = Name( terminalValue = 1, value = 'literal', )
name = Name( terminalValue = 1, value = 'name', )
newline = '\r\n'
newline_charset = <Character Set object for '\r\n' at 0x4a5a378>
newline_set = '\x00$\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
nonwhitespace_charset = <Character Set object for '^ \t\x0b\r\n\x0c' at 0x4a5a3f0>
nonwhitespace_set = '\xff\xc1\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'
number = '0123456789'
number_charset = <Character Set object for '0-9' at 0x4a5a300>
number_set = '\x00\x00\x00\x00\x00\x00\xff\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
sFindWord = 213
sWordEnd = 212
sWordStart = 211
tagtable_cache = {(103136504, 0): <String Tag Table object at 0x612fe88>, (103846256, 0): <String Tag Table object at 0x622de88>, (103846832, 0): <String Tag Table object at 0x622d718>, (103847840, 0): <String Tag Table object at 0x65188b0>, (103847984, 0): <String Tag Table object at 0x6267a48>, (103848056, 0): <String Tag Table object at 0x61a1e00>, (103849064, 0): <String Tag Table object at 0x622dcf0>, (104413592, 0): <String Tag Table object at 0x622dbe0>, (104413808, 0): <String Tag Table object at 0x622d828>, (104971800, 0): <String Tag Table object at 0x622dd78>, ...}
to_lower = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./...\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'
to_upper = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./...\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'
umlaute = '\xe4\xf6\xfc\xdf'
umlaute_charset = <Character Set object for '\xe4\xf6\xfc\xdf' at 0x4a5a260>
white = ' \t\x0b'
white_charset = <Character Set object for ' \t\x0b' at 0x4a5a350>
white_set = '\x00\x02\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
whitespace = Name( report = 0, terminalValue = 1, value = 'ts', )
whitespace_charset = <Character Set object for ' \t\x0b\r\n\x0c' at 0x4a5a3c8>
whitespace_set = '\x00&\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'