Package libxyz :: Package parser :: Module flat :: Class FlatParser

[hide private]
[frames] | no frames]

# Class FlatParser

source code

    BaseParser --+
                 |
                FlatParser

FlatParser is simple linear parser.

Format:

var1 <assign> val1 <delimiter> var2 <assign> val2 <delimiter> ...

Instance Methods | [hide private]

__init__(self, opt=None) | source code

parse(self, source, default_data=None) Begin parsing | source code

_process_state_variable(self, word) | source code

_process_state_assign(self, word) | source code

_process_state_value(self, word) | source code

_process_state_list_value(self, word) | source code

_process_state_delim(self, word) | source code

_cleanup(self) | source code

_check_complete(self) | source code

Class Variables | [hide private]

| STATE_VARIABLE = `0`
| STATE_ASSIGN = `1`
| STATE_VALUE = `2`
| STATE_LIST_VALUE = `3`
| STATE_DELIM = `4`
| DEFAULT_OPT = `{u"comment": u"#", u"assignchar": u":", u"delimi`...``

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)
    - assignchar: Variable-value split character. Type: string (single char)
    - delimiter: Character to use as delimiter between statements. Type: string (single char)
    - validvars: List of variables valid within block. Type: sequence
    - value_validator: Value validator Type: A function that takes two args: variable and value and validates them. In case value is invalid, XYZValueError must be raised. Otherwise function must return required value, possibly modified.
    - count: How many blocks to parse. If count <= 0 - will parse all available. Type: integer
    - list_separator: Character to separate elements in list Type: string (single char) Default: ,
    ) - Options

### parse(self, source, default_data=None)

source code

Begin parsing

Parameters:
  - `default_data` - Dictionary with default values.

Class Variable Details | [hide private]

### DEFAULT_OPT

Value:

      {u"comment": u"#", u"assignchar": u":", u"delimiter": u"\n", u"validva
      rs":(), u"value_validator": None, u"count": 0, u"list_separator": u","
      ,}