aboutsummaryrefslogtreecommitdiff
path: root/mammoth/style_reader/__init__.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-13 18:02:12 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-13 18:02:12 +0000
commit4d09c8116dbf01487368c16a66ea13f07b3349a3 (patch)
tree5d842b3aec7ca18a7a7903a82bd0abafc31ab302 /mammoth/style_reader/__init__.py
parent49d046acf05be128d404a419ecde05091efa30c1 (diff)
Parse styles
Diffstat (limited to 'mammoth/style_reader/__init__.py')
-rw-r--r--mammoth/style_reader/__init__.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/mammoth/style_reader/__init__.py b/mammoth/style_reader/__init__.py
index 705abff..41dcffa 100644
--- a/mammoth/style_reader/__init__.py
+++ b/mammoth/style_reader/__init__.py
@@ -1,2 +1,27 @@
-from .html_path_reader import read_html_path
-from .document_matcher_reader import read_document_matcher
+from parsimonious.grammar import Grammar
+
+from .html_path_reader import read_html_path, grammar_text as html_path_grammar, read_html_path_node
+from .document_matcher_reader import read_document_matcher, grammar_text as document_matcher_grammar, read_document_matcher_node
+from ..styles import Style
+
+
+def read_style(string):
+ style_node = _grammar.parse(string)
+ return _read_style_node(style_node)
+
+
+def _read_style_node(style_node):
+ document_matcher_node = style_node.children[0]
+ html_path_node = style_node.children[4]
+
+ document_matcher = read_document_matcher_node(document_matcher_node)
+ html_path = read_html_path_node(html_path_node)
+
+ return Style(document_matcher, html_path)
+
+
+
+_grammar = Grammar("""
+style = document_matcher whitespace "=>" whitespace html_path
+""" + html_path_grammar + document_matcher_grammar
+)