Commit 8e4dc4c5 authored by eckhart's avatar eckhart

- parse.py: Token, Regexp: Return EMPTY_NODE if content is empty string

parent 66c0d7a9
......@@ -88,7 +88,6 @@ class Error:
MALFORMED_ERROR_STRING = ErrorCode(1060)
AMBIGUOUS_ERROR_HANDLING = ErrorCode(1070)
REDEFINED_DIRECTIVE = ErrorCode(1080)
# INFINITE_LOOP = ErrorCode(1090)
def __init__(self, message: str, pos, code: ErrorCode = ERROR,
orig_pos: int = -1, line: int = -1, column: int = -1) -> None:
......
......@@ -1198,7 +1198,9 @@ class Token(Parser):
def _parse(self, text: StringView) -> Tuple[Optional[Node], StringView]:
if text.startswith(self.text):
return Node(self.tag_name, self.text, True), text[self.len:]
if self.text or self.pname:
return Node(self.tag_name, self.text, True), text[self.len:]
return EMPTY_NODE, text[0:]
return None, text
def __repr__(self):
......@@ -1257,8 +1259,11 @@ class RegExp(Parser):
match = text.match(self.regexp)
if match:
capture = match.group(0)
end = text.index(match.end())
return Node(self.tag_name, capture, True), text[end:]
if capture or self.pname:
end = text.index(match.end())
return Node(self.tag_name, capture, True), text[end:]
assert text.index(match.end()) == 0
return EMPTY_NODE, text[0:]
return None, text
def __repr__(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment