diff --git a/tools/lib/html_branches.py b/tools/lib/html_branches.py index 78f8205cc5..7dfd379dd5 100644 --- a/tools/lib/html_branches.py +++ b/tools/lib/html_branches.py @@ -5,6 +5,7 @@ from collections import defaultdict from .template_parser import ( tokenize, + FormattedException, Token, ) @@ -133,7 +134,7 @@ def split_for_id_and_class(element: str) -> List[str]: def html_branches(text: str, fn: Optional[str] = None) -> List[HtmlTreeBranch]: - tree = html_tag_tree(text) + tree = html_tag_tree(text, fn) branches: List[HtmlTreeBranch] = [] def walk(node: Node, tag_info_list: Optional[List[TagInfo]] = None) -> None: @@ -156,7 +157,7 @@ def html_branches(text: str, fn: Optional[str] = None) -> List[HtmlTreeBranch]: return branches -def html_tag_tree(text: str) -> Node: +def html_tag_tree(text: str, fn: Optional[str]=None) -> Node: tokens = tokenize(text) top_level = Node(token=None, parent=None) stack = [top_level] @@ -184,7 +185,13 @@ def build_id_dict(templates: List[str]) -> (Dict[str, List[str]]): for fn in templates: with open(fn) as f: text = f.read() - list_tags = tokenize(text) + + try: + list_tags = tokenize(text) + except FormattedException as e: + raise Exception(''' + fn: %s + %s''' % (fn, e)) for tag in list_tags: info = get_tag_info(tag) diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py index c9084def2d..58eea7e451 100644 --- a/tools/lib/template_parser.py +++ b/tools/lib/template_parser.py @@ -1,5 +1,8 @@ from typing import Callable, List, Optional, Text +class FormattedException(Exception): + pass + class TemplateParserException(Exception): def __init__(self, message: str) -> None: self.message = message @@ -148,9 +151,14 @@ def tokenize(text: str) -> List[Token]: advance(1) continue except TokenizationException as e: - raise TemplateParserException('''%s at Line %d Col %d:"%s"''' % - (e.message, state.line, state.col, - e.line_content)) + raise FormattedException( + '''%s at Line %d Col %d:"%s"''' % ( + e.message, + state.line, + state.col, + e.line_content + ) + ) line_span = len(s.split('\n')) token = Token( @@ -197,7 +205,12 @@ def validate(fn: Optional[str] = None, text: Optional[str] = None, check_indent: with open(fn) as f: text = f.read() - tokens = tokenize(text) + try: + tokens = tokenize(text) + except FormattedException as e: + raise TemplateParserException(''' + fn: %s + %s''' % (fn, e)) class State: def __init__(self, func: Callable[[Token], None]) -> None: