Package libxyz :: Package parser :: Module multi :: Class MultiParser

[hide private]
[frames] | no frames]

# Class MultiParser

source code

    BaseParser --+
                 |
                MultiParser

MultiParser is a simple container for any other parsers Usually parsers, such as BlockParser designed to parse homogeneous blocks in single source: file or string. But still it might be useful sometimes to parse multiple blocks of different syntax in single source. Thus, one can register some necessary parsers into MultiParser and go on.

Instance Methods | [hide private]

__init__(self, parsers, opt=None) @param parsers: dictionary containing string, list or compiled regexp of keywords as key and *Parser objects as values. | source code

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

register(self, keyword, parser) Register new parser. | source code

unregister(self, keyword) Unregister parser. | source code

Class Variables | [hide private]

| DEFAULT_OPT = `{u"comment": u"#", u"tokens":(),}`

Method Details | [hide private]

### __init__(self, parsers, opt=None)
(Constructor)

source code

    @param parsers: dictionary containing string, list or
                    compiled regexp of keywords as key
                    and *Parser objects as values.
    @type parsers: dictionary with string or sequence keys

    @param opt: Options

    Available options:
    - comment: Comment character.
      Everything else ignored until EOL.
      Type: I{string (single char)}

    - tokens: List of tokens.
      Type: I{sequence}

### register(self, keyword, parser)

source code

Register new parser. If parser for keyword given already registered replace it with new one.

Parameters:
  - `keyword` (string, sequence or compiled regular expression) - Keyword that will trigger the parser.
  - `param` - Any *Parser instance. Must be subclassed from BaseParser.

### unregister(self, keyword)

source code

Unregister parser. Ignore if was not registered.