Package libxyz :: Package parser :: Module block :: Class BlockParser |
[hide private]
[frames] | no frames]

# Class BlockParser

source code

    BaseParser --+
                 |
                BlockParser

    BaseParser is used to parse block structures.
    Format:

    name {
        var1 <assign> val1 <delimiter>
        var2 <assign> val2 [<list_separator>val3...] <delimiter>
        ...
        }

Instance Methods | [hide private]
__init__(self, opt=None) | source code
parse(self, source, default_data=None) Parse blocks of text and return a dict of ParsedData objects or raise libxyz.exceptions.ParseError exception | source code
_process_state_init(self, word) | source code
_process_state_block_open(self, word) | source code
_process_state_variable(self, word) | source code
_process_state_assign(self, word) | source code
_process_state_list_value(self, word) | source code
_process_state_value(self, word) | source code
_process_state_delim(self, word) | source code
_complete_block(self) | source code
_cleanup(self) Set all neccessary variables to initial state | source code
_check_complete(self) Check state after source reaches EOF for consistency | source code

Class Variables | [hide private]
| STATE_INIT = `0`
| STATE_BLOCK_OPEN = `1`
| STATE_VARIABLE = `2`
| STATE_ASSIGN = `3`
| STATE_VALUE = `4`
| STATE_DELIM = `5`
| STATE_LIST_VALUE = `6`
| DEFAULT_OPT = `{u"comment": u"#", u"varre": re.compile(r"^[\w-]`...``

Method Details | [hide private]

### __init__(self, opt=None) (Constructor) | source code
Parameters: `opt` (dict Available options: comment: Comment character. Everything else ignored until EOL. Type: string (single char) Default: # delimiter: Character to use as delimiter between statements. Type: string (single char) Default: \n varre: Valid variable name regular expression. Type: Compiled re object (`re.compile`) Default: ^[\w-]+$ assignchar: Variable-value split character. Type: string (single char) Default: = validvars: List of variables valid within block. Type: sequence Default: () value_validator: Value validator Type: A function that takes three args: current block name, var and value and validates them. In case value is invalid, XYZValueError must be raised. Otherwise function must return required value, possibly modified. Default: None count: How many blocks to parse. If count <= 0 - will parse all available. Type: integer Default: 0 list_separator: Character to separate elements in list Type: string (single char) Default: , macrochar: Macro character (None to disable macros) Type: string (single char) Default: & var_transform: A function which is called with variable name as single argument, and which returns new variable object or raises XYZValueError ) - Parser options.

### parse(self, source, default_data=None) | source code
Parse blocks of text and return a dict of ParsedData objects or raise libxyz.exceptions.ParseError exception Parameters: `source` - Source data `default_data` - Dictionary containing libxyz.parser.ParsedData objects with default values.

Class Variable Details | [hide private]

  ### DEFAULT_OPT Value:
      {u"comment": u"#", u"varre": re.compile(r"^[\w-]+$"), u"assignchar": u
      "=", u"delimiter": u"\n", u"validvars":(), u"value_validator": None, u
      "count": 0, u"list_separator": u",", u"macrochar": u"&", u"var_transfo
      rm": None,}