mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
check-templates: Show filename for tokenize errors.
This commit is contained in:
@@ -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()
|
||||
|
||||
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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user