Python: module simpleparse.common.strings

simpleparse.common.strings | index s:\sp\simpleparse\common\strings.py

`Python string parsers with escape characters
Python-string-like operation as much as possible, this includes:
support for single and double-quoted strings
support for triple-quoted versions of the same
support for special character escapes as seen in 8-bit python strings
support for octal and hexidecimal character escapes
string_single_quote
string_double_quote
string_triple_single
string_triple_double
Individual string types with the above features
string
Any of the above string types, in a simple FirstOf group
with the triple-quoted types first, then the single quoted
i.e. generated with this grammar:
string_triple_double/string_triple_single/string_double_quote/string_single_quote
Interpreters:
StringInterpreter
Interprets any/all of the above as a normal (non-Raw) Python
regular (non-unicode) string. Hopefully the action is identical
to doing eval( matchedString, {},{}), without the negative security
implications of that approach. Note that you need to make the
interpreter available under each name you use directly in your
grammar, so if you use string_single_quote and string_double_quote
directly, then you need to add:
string_single_quote = myStringInterpreterInstance
string_double_quote = myStringInterpreterInstance
to your processor class.`

Modules
`` |  |
simpleparse.common.chartypes | simpleparse.common | simpleparse.objectgenerator | string

Classes
`` |  | simpleparse.dispatchprocessor.DispatchProcessor(simpleparse.processor.Processor) StringInterpreter
class StringInterpreter(simpleparse.dispatchprocessor.DispatchProcessor)
`` | `Processor for converting parsed string values to their "intended" value Basically this processor handles de-escaping and stripping the surrounding quotes, so that you get the string as a Python string value. You use the processor by creating an instance of StringInterpreter() as an item in another processor's methodSource object (often the Parser itself). For example: class MyProcessor( DispatchProcessor ): string = StringInterpreter() # following would be used if you have, for instance, # used string_single_quote in an area where double # or triple-quoted strings are not allowed, but have # used string in another area. string_single_quote = string`
| Method resolution order: StringInterpreter simpleparse.dispatchprocessor.DispatchProcessor simpleparse.processor.Processor simpleparse.processor.MethodSource Methods defined here: backslash_char(self, (tag, left, right, sublist), buffer) char_no_quote(self, (tag, left, right, sublist), buffer) escaped_char(self, (tag, left, right, sublist), buffer) hex_escaped_char(self, (tag, left, right, sublist), buffer) nondelimiter = char_no_quote(self, (tag, left, right, sublist), buffer) octal_escaped_char(self, (tag, left, right, sublist), buffer) string(self, (tag, left, right, sublist), buffer) `Dispatch any of the string types and return the result` string_double_quote = string_single_quote(self, (tag, left, right, sublist), buffer) string_single_quote(self, (tag, left, right, sublist), buffer) string_special_escapes(self, (tag, left, right, sublist), buffer) `Maps "special" escapes to the corresponding characters` string_triple_double = string_single_quote(self, (tag, left, right, sublist), buffer) string_triple_single = string_single_quote(self, (tag, left, right, sublist), buffer) Data and non-method functions defined here: __doc__ = 'Processor for converting parsed string values to...n another area.\n\t\t\tstring_single_quote = string\n\t' `str(object) -> string Return a nice string representation of the object. If the argument is a string, the return value is the same object.` __module__ = 'simpleparse.common.strings' `str(object) -> string Return a nice string representation of the object. If the argument is a string, the return value is the same object.` specialescapedmap = {'\n': '', '"': '"', "'": "'", r'\': r'\', 'a': '\x07', 'b': '\x08', 'f': '\x0c', 'n': '\n', 'r': '\r', 't': '\t', ...} `dict() -> new empty dictionary. dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs. dict(seq) -> new dictionary initialized as if via: d = {} for k, v in seq: d[k] = v` Methods inherited from simpleparse.dispatchprocessor.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 simpleparse.processor.Processor: __repr__(self) `Return a representation of the class`

Data
`` |  | __file__ = r'S:\sp\simpleparse\common\strings.pyc' __name__ = 'simpleparse.common.strings' _p = <simpleparse.parser.Parser instance at 0x007FBA10> _stringTypeData = [('string_double_quote', '\n<delimiter> := \'"\'\nnondelimiter...\\\\"]+\nstring_special_escapes := [\\\\abfnrtv"]\n'), ('string_single_quote', '\n<delimiter> := "\'"\nnondelimiter...\\\\\']+\nstring_special_escapes := [\\\\abfnrtv\']\n'), ('string_triple_single', '\nnondelimiter := -"\'\'\'"\n<delimite...\\\\\']+\nstring_special_escapes := [\\\\abfnrtv\']\n'), ('string_triple_double', '\nnondelimiter := -\'"""\'\n<delimite...\\\\"]+\nstring_special_escapes := [\\\\abfnrtv"]\n')] c = {'string': LibraryElement( production = 'string', g...se.generator.Generator instance at 0x007FABF0>, ), 'string_double_quote': LibraryElement( production = 'str', gene...se.generator.Generator instance at 0x007F41E8>, ), 'string_single_quote': LibraryElement( production = 'str', gene...se.generator.Generator instance at 0x00820CA8>, ), 'string_triple_double': LibraryElement( production = 'str', gene...se.generator.Generator instance at 0x007FB9D8>, ), 'string_triple_single': LibraryElement( production = 'str', gene...se.generator.Generator instance at 0x007F6CE0>, )} name = 'string_triple_double' partial = '\nnondelimiter := -\'"""\'\n<delimite...\\\\"]+\nstring_special_escapes := [\\\\abfnrtv"]\n' stringDeclaration = '\n# note that non-delimiter can never be hit by n...# i.e. a backslash preceding a non-special char\n\n'