A fast parser for reStructuredText
Project description
rst_fast_parse
A fast parser for reStructuredText.
This parser is NOT (at least for now) intended to be a full replacement for the docutils/sphinx rST parser. The initial goal is to parse the "outline" of a reStructuredText document, without knowing any information about the roles / directives that are available, into a structure that can be used for things like Language Servers, to provide quick information (as opposed to having to wait for a full sphinx build).
Features:
- Fault tolerant parsing, designed to never raise an exception
- Concrete syntax tokens with full source mapping
- Diagnostics for common issues
- Functional design, with separate functions for each block element
- Fully typed with "strict" mypy settings
Incremental parsing and formatting is also planned.
Usage
To parse a string, use the parse_string
function.
from rst_fast_parse import parse_string
elements, diagnostics = parse_string("""
Hello
-----
world!
""")
assert elements.debug_repr() == """\
<title_underline> 1-2
<paragraph> 3-3
"""
Diagnostics are returned for any issues found during parsing.
from rst_fast_parse import parse_string
elements, diagnostics = parse_string("""
- list
no blank line
""")
assert elements.debug_repr() == """\
<bullet_list> 1-1
<list_item> 1-1
<paragraph> 1-1
<paragraph> 2-2
"""
assert [d.as_dict() for d in diagnostics] == [{
'code': 'block.blank_line',
'message': 'Blank line expected after Bullet list',
'line_start': 1,
}]
Design decisions
The parse does not automatically nest sections, based on title underline styles, like docutils. This allows for incremental parsing, as well as a simpler design.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for rst_fast_parse-0.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c5e5a212e830453676314d7183f0c6ae7f349ae2922ad3f25d645a8bc0c7e6c |
|
MD5 | ca74ef058793397614c719233f59776f |
|
BLAKE2b-256 | 88859ad74a0d1ad8520c0dc966347db2609d5c06d4ff007db58f797ebd6fa660 |