blob: f72f03db8160f08ea30b6d8c06f587178b1a5550 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
from parsimonious.grammar import Grammar
from .. import document_matchers
def read_document_matcher(string):
paragraph_node = _grammar.parse(string)
return _read_paragraph_node(paragraph_node)
def _read_paragraph_node(paragraph_node):
style_name = _read_style_node(paragraph_node.children[1])
return document_matchers.paragraph(style_name=style_name)
def _read_style_node(style_node):
if style_node.children:
return style_node.children[0].children[1].text
else:
return None
_grammar = Grammar(r"""
paragraph = "p" style_name?
style_name = "." style_identifier
style_identifier = ~"[A-Z0-9]*"i
""")
|