aboutsummaryrefslogtreecommitdiff
path: root/mammoth/style_reader
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-08-15 18:11:46 +0100
committerMichael Williamson <mike@zwobble.org>2015-08-15 18:11:46 +0100
commit2c9955f0590d93968b4959e3622d01610e398700 (patch)
tree886f42a3c647d8f0716a871685e925b95bd2bc6f /mammoth/style_reader
parent724f9f01d83865ae586e7a8f65545e1a11d2cdae (diff)
Continue with warning style mapping cannot be parsed
Diffstat (limited to 'mammoth/style_reader')
-rw-r--r--mammoth/style_reader/__init__.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/mammoth/style_reader/__init__.py b/mammoth/style_reader/__init__.py
index 28281a8..aca07df 100644
--- a/mammoth/style_reader/__init__.py
+++ b/mammoth/style_reader/__init__.py
@@ -1,16 +1,23 @@
from parsimonious.grammar import Grammar
+from parsimonious.exceptions import ParseError
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
+from .. import results
__all__ = ["read_style", "read_html_path", "read_document_matcher"]
def read_style(string):
- style_node = _grammar.parse(string)
- return _read_style_node(style_node)
+ try:
+ style_node = _grammar.parse(string)
+ except ParseError:
+ warning = "Did not understand this style mapping, so ignored it: " + string
+ return results.Result(None, [results.warning(warning)])
+
+ return results.success(_read_style_node(style_node))
def _read_style_node(style_node):