2 # Author: David Goodger <goodger@python.org>
3 # Copyright: This module has been placed in the public domain.
6 This package contains Docutils parser modules.
9 __docformat__
= 'reStructuredText'
11 from docutils
import Component
14 class Parser(Component
):
16 component_type
= 'parser'
17 config_section
= 'parsers'
19 def parse(self
, inputstring
, document
):
20 """Override to parse `inputstring` into document tree `document`."""
21 raise NotImplementedError('subclass must override this method')
23 def setup_parse(self
, inputstring
, document
):
24 """Initial parse setup. Call at start of `self.parse()`."""
25 self
.inputstring
= inputstring
26 self
.document
= document
27 document
.reporter
.attach_observer(document
.note_parse_message
)
29 def finish_parse(self
):
30 """Finalize parse details. Call at end of `self.parse()`."""
31 self
.document
.reporter
.detach_observer(
32 self
.document
.note_parse_message
)
36 'restructuredtext': 'rst',
41 def get_parser_class(parser_name
):
42 """Return the Parser class from the `parser_name` module."""
43 parser_name
= parser_name
.lower()
44 if parser_name
in _parser_aliases
:
45 parser_name
= _parser_aliases
[parser_name
]
46 module
= __import__(parser_name
, globals(), locals())