2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 5e7a1add authored by eckhart's avatar eckhart
Browse files

- parser.py: error reporting of HistoryRecord changed

parent b00c3789
...@@ -161,7 +161,9 @@ class HistoryRecord: ...@@ -161,7 +161,9 @@ class HistoryRecord:
(self.line_col[0], self.line_col[1], self.stack, str(self.node)) (self.line_col[0], self.line_col[1], self.stack, str(self.node))
def err_msg(self) -> str: def err_msg(self) -> str:
return self.ERROR + ": " + "; ".join(str(e) for e in self.node._errors) # .replace('\n', '\\') return self.ERROR + ": " + "; ".join(
str(e) for e in (self.node._errors if self.node._errors else
self.node.collect_errors()[:1]))
@property @property
def stack(self) -> str: def stack(self) -> str:
...@@ -171,7 +173,7 @@ class HistoryRecord: ...@@ -171,7 +173,7 @@ class HistoryRecord:
@property @property
def status(self) -> str: def status(self) -> str:
return self.FAIL if self.node is None else \ return self.FAIL if self.node is None else \
self.err_msg() if has_errors(self.node._errors) else self.MATCH self.err_msg() if self.node.error_flag else self.MATCH # has_errors(self.node._errors)
@property @property
def extent(self) -> slice: def extent(self) -> slice:
...@@ -273,7 +275,7 @@ def add_parser_guard(parser_func): ...@@ -273,7 +275,7 @@ def add_parser_guard(parser_func):
if grammar.history_tracking__: if grammar.history_tracking__:
# don't track returning parsers except in case an error has occurred # don't track returning parsers except in case an error has occurred
remaining = len(rest) remaining = len(rest)
if grammar.moving_forward__ or (node and node._errors): if grammar.moving_forward__ or (node and node.error_flag): # node._errors
record = HistoryRecord(grammar.call_stack__, node, remaining) record = HistoryRecord(grammar.call_stack__, node, remaining)
grammar.history__.append(record) grammar.history__.append(record)
# print(record.stack, record.status, rest[:20].replace('\n', '|')) # print(record.stack, record.status, rest[:20].replace('\n', '|'))
...@@ -838,7 +840,7 @@ class Grammar: ...@@ -838,7 +840,7 @@ class Grammar:
record.node.pos = 0 record.node.pos = 0
record = HistoryRecord(self.call_stack__.copy(), stitches[-1], len(rest)) record = HistoryRecord(self.call_stack__.copy(), stitches[-1], len(rest))
self.history__.append(record) self.history__.append(record)
self.history_tracking__ = False self.history_tracking__ = False # TODO: add an explanation here
if stitches: if stitches:
if rest: if rest:
stitches.append(Node(None, rest)) stitches.append(Node(None, rest))
......
This diff is collapsed.
#cython: infer_types=True
#cython: language_level=3
#cython: c_string_type=unicode
#cython: c_string_encoding=utf-8
import cython import cython
# type hints for Cython python -> C compiler to speed up the most # type hints for Cython python -> C compiler to speed up the most
......
...@@ -246,9 +246,9 @@ class Node(collections.abc.Sized): ...@@ -246,9 +246,9 @@ class Node(collections.abc.Sized):
def __str__(self): def __str__(self):
if self.children: if self.children:
return "".join(str(child) for child in self.children) return "".join(str(child) for child in self.children)
elif isinstance(self.result, StringView): elif isinstance(self._result, StringView):
self.result = str(self.result) self.result = str(self._result)
return self.result return self._result
def __repr__(self): def __repr__(self):
......
#!/bin/sh #!/bin/sh
# CFLAGS="-O3 -march=native -mtune=native"
python3 setup.py build_ext --inplace python3 setup.py build_ext --inplace
...@@ -374,14 +374,9 @@ Match-test "2" ...@@ -374,14 +374,9 @@ Match-test "2"
% Comment % Comment
### AST ### AST
(LFF (NEW_LINE
(NEW_LINE ""
"" ""
""
)
(WSPC
"% Comment"
)
) )
Match-test "3" Match-test "3"
...@@ -393,20 +388,9 @@ Match-test "3" ...@@ -393,20 +388,9 @@ Match-test "3"
### AST ### AST
(LFF (NEW_LINE
(NEW_LINE ""
"" ""
""
)
(WSPC
(:RegExp
"% Comment"
)
(:RegExp
""
""
)
)
) )
Match-test "4" Match-test "4"
...@@ -419,16 +403,9 @@ Match-test "4" ...@@ -419,16 +403,9 @@ Match-test "4"
### AST ### AST
(LFF (NEW_LINE
(NEW_LINE ""
"" ""
""
)
(WSPC
""
""
""
)
) )
Fail-test "10" Fail-test "10"
......
...@@ -51,13 +51,9 @@ Match-test "1" ...@@ -51,13 +51,9 @@ Match-test "1"
\command \command
### AST ### AST
(text_element (generic_command
(command (CMDNAME
(generic_command "\command"
(CMDNAME
"\command"
)
)
) )
) )
...@@ -68,13 +64,9 @@ Match-test "2" ...@@ -68,13 +64,9 @@ Match-test "2"
\textbackslash \textbackslash
### AST ### AST
(text_element (text_command
(command (TXTCOMMAND
(text_command "\textbackslash"
(TXTCOMMAND
"\textbackslash"
)
)
) )
) )
...@@ -85,38 +77,24 @@ Match-test "3" ...@@ -85,38 +77,24 @@ Match-test "3"
\footnote{footnote} \footnote{footnote}
### AST ### AST
(text_element (footnote
(command (:Token
(known_command "\footnote"
(footnote )
(:Token (block_of_paragraphs
(:RegExp (:Token
"\footnote" "{"
) )
) (sequence
(block_of_paragraphs (paragraph
(:Token (text
(:RegExp "footnote"
"{"
)
)
(sequence
(paragraph
(text_element
(text
"footnote"
)
)
)
)
(:Token
(:RegExp
"}"
)
)
) )
) )
) )
(:Token
"}"
)
) )
) )
...@@ -127,13 +105,9 @@ Match-test "4" ...@@ -127,13 +105,9 @@ Match-test "4"
[ [
### AST ### AST
(text_element (text_command
(command (BRACKETS
(text_command "["
(BRACKETS
"["
)
)
) )
) )
...@@ -144,27 +118,23 @@ Match-test "5" ...@@ -144,27 +118,23 @@ Match-test "5"
\begin{generic} unknown inline environment \end{generic} \begin{generic} unknown inline environment \end{generic}
### AST ### AST
(text_element (generic_inline_env
(generic_inline_env (begin_environment
(begin_environment "generic"
"generic" )
(:Whitespace
" "
)
(paragraph
(text
"unknown inline environment"
) )
(:Whitespace (:Whitespace
" " " "
) )
(paragraph )
(text_element (end_environment
(text "generic"
"unknown inline environment"
)
)
(:Whitespace
" "
)
)
(end_environment
"generic"
)
) )
) )
...@@ -175,27 +145,23 @@ Match-test "6" ...@@ -175,27 +145,23 @@ Match-test "6"
\begin{small} known inline environment \end{small} \begin{small} known inline environment \end{small}
### AST ### AST
(text_element (generic_inline_env
(generic_inline_env (begin_environment
(begin_environment "small"
"small" )
(:Whitespace
" "
)
(paragraph
(text
"known inline environment"
) )
(:Whitespace (:Whitespace
" " " "
) )
(paragraph )
(text_element (end_environment
(text "small"
"known inline environment"
)
)
(:Whitespace
" "
)
)
(end_environment
"small"
)
) )
) )
...@@ -206,21 +172,13 @@ Match-test "7" ...@@ -206,21 +172,13 @@ Match-test "7"
{\em block} {\em block}
### AST ### AST
(text_element (block
(block (generic_command
(text_element (CMDNAME
(command "\em"
(generic_command
(CMDNAME
"\em"
)
)
)
)
(text_element
(text
"block"
)
) )
) )
(text
"block"
)
) )
\ No newline at end of file
...@@ -31,20 +31,16 @@ Match-test "1" ...@@ -31,20 +31,16 @@ Match-test "1"
) )
(sequence (sequence
(paragraph (paragraph
(text_element (text
(text "A generic block element is a block element"
"A generic block element is a block element" "that is unknown to DHParser."
"that is unknown to DHParser."
)
) )
) )
(paragraph (paragraph
(text_element (text
(text "Unknown begin-end-structures are always"
"Unknown begin-end-structures are always" "considered as block elements and not"
"considered as block elements and not" "as inline elements."
"as inline elements."
)
) )
(:Whitespace (:Whitespace
"" ""
...@@ -86,10 +82,8 @@ Match-test "2" ...@@ -86,10 +82,8 @@ Match-test "2"
) )
(sequence (sequence
(paragraph (paragraph
(text_element (text
(text "a single block paragraph"
"a single block paragraph"
)
) )
(:Whitespace (:Whitespace
"" ""
...@@ -101,27 +95,16 @@ Match-test "2" ...@@ -101,27 +95,16 @@ Match-test "2"
(end_environment (end_environment
"generic" "generic"
) )
(LFF (NEW_LINE
(NEW_LINE (:RegExp
(:RegExp " "
" "
)
(:RegExp
"% ending with"
)
(:RegExp
""
""
)
) )
(WSPC (:RegExp
(:RegExp "% ending with"
"% a comment" )
) (:RegExp
(:RegExp ""
"" ""
""
)
) )
) )
) )
...@@ -139,10 +122,8 @@ Match-test "3" ...@@ -139,10 +122,8 @@ Match-test "3"
(quotation (quotation
(sequence (sequence
(paragraph (paragraph
(text_element (text
(text "a known block element"
"a known block element"
)
) )
(:Whitespace (:Whitespace
"" ""
...@@ -192,10 +173,8 @@ Match-test "1" ...@@ -192,10 +173,8 @@ Match-test "1"
"generic" "generic"
) )
(paragraph (paragraph
(text_element (text
(text "inline environment"
"inline environment"
)
) )
) )
(end_environment (end_environment
...@@ -216,10 +195,8 @@ Match-test "2" ...@@ -216,10 +195,8 @@ Match-test "2"
"generic" "generic"
) )
(paragraph (paragraph
(text_element (text
(text "inline environment"
"inline environment"
)
) )
(:Whitespace (:Whitespace
"" ""
...@@ -269,10 +246,8 @@ Match-test "1" ...@@ -269,10 +246,8 @@ Match-test "1"
(item (item
(sequence (sequence
(paragraph (paragraph
(text_element (text
(text "Items doe not need to be"
"Items doe not need to be"
)
) )
(:Whitespace (:Whitespace
"" ""
...@@ -284,10 +259,8 @@ Match-test "1" ...@@ -284,10 +259,8 @@ Match-test "1"
(item (item
(sequence (sequence
(paragraph (paragraph
(text_element (text
(text "separated by empty lines."
"separated by empty lines."
)
) )
(:Whitespace (:Whitespace
"" ""
...@@ -316,18 +289,11 @@ Match-test "2" ...@@ -316,18 +289,11 @@ Match-test "2"
### AST ### AST
(itemize (itemize
(WSPC
""
""
""
)
(item (item
(sequence (sequence
(paragraph (paragraph
(text_element (text
(text "But items may be"
"But items may be"
)
) )
) )
) )
...@@ -335,26 +301,17 @@ Match-test "2" ...@@ -335,26 +301,17 @@ Match-test "2"
(item (item
(sequence (sequence
(paragraph (paragraph
(text_element (text