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,15 +374,10 @@ Match-test "2" ...@@ -374,15 +374,10 @@ Match-test "2"
% Comment % Comment
### AST ### AST
(LFF
(NEW_LINE (NEW_LINE
"" ""
"" ""
) )
(WSPC
"% Comment"
)
)
Match-test "3" Match-test "3"
-------------- --------------
...@@ -393,21 +388,10 @@ Match-test "3" ...@@ -393,21 +388,10 @@ Match-test "3"
### AST ### AST
(LFF
(NEW_LINE (NEW_LINE
"" ""
"" ""
) )
(WSPC
(:RegExp
"% Comment"
)
(:RegExp
""
""
)
)
)
Match-test "4" Match-test "4"
-------------- --------------
...@@ -419,17 +403,10 @@ Match-test "4" ...@@ -419,17 +403,10 @@ Match-test "4"
### AST ### AST
(LFF
(NEW_LINE (NEW_LINE
"" ""
"" ""
) )
(WSPC
""
""
""
)
)
Fail-test "10" Fail-test "10"
-------------- --------------
......
...@@ -51,15 +51,11 @@ Match-test "1" ...@@ -51,15 +51,11 @@ Match-test "1"
\command \command
### AST ### AST
(text_element
(command
(generic_command (generic_command
(CMDNAME (CMDNAME
"\command" "\command"
) )
) )
)
)
Match-test "2" Match-test "2"
-------------- --------------
...@@ -68,15 +64,11 @@ Match-test "2" ...@@ -68,15 +64,11 @@ Match-test "2"
\textbackslash \textbackslash
### AST ### AST
(text_element
(command
(text_command (text_command
(TXTCOMMAND (TXTCOMMAND
"\textbackslash" "\textbackslash"
) )
) )
)
)
Match-test "3" Match-test "3"
-------------- --------------
...@@ -85,40 +77,26 @@ Match-test "3" ...@@ -85,40 +77,26 @@ Match-test "3"
\footnote{footnote} \footnote{footnote}
### AST ### AST
(text_element
(command
(known_command
(footnote (footnote
(:Token (:Token
(:RegExp
"\footnote" "\footnote"
) )
)
(block_of_paragraphs (block_of_paragraphs
(:Token (:Token
(:RegExp
"{" "{"
) )
)
(sequence (sequence
(paragraph (paragraph
(text_element
(text (text
"footnote" "footnote"
) )
) )
) )
)
(:Token (:Token
(:RegExp
"}" "}"
) )
) )
) )
)
)
)
)
Match-test "4" Match-test "4"
-------------- --------------
...@@ -127,15 +105,11 @@ Match-test "4" ...@@ -127,15 +105,11 @@ Match-test "4"
[ [
### AST ### AST
(text_element
(command
(text_command (text_command
(BRACKETS (BRACKETS
"[" "["
) )
) )
)
)
Match-test "5" Match-test "5"
-------------- --------------
...@@ -144,7 +118,6 @@ Match-test "5" ...@@ -144,7 +118,6 @@ 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"
...@@ -153,11 +126,9 @@ Match-test "5" ...@@ -153,11 +126,9 @@ Match-test "5"
" " " "
) )
(paragraph (paragraph
(text_element
(text (text
"unknown inline environment" "unknown inline environment"
) )
)
(:Whitespace (:Whitespace
" " " "
) )
...@@ -166,7 +137,6 @@ Match-test "5" ...@@ -166,7 +137,6 @@ Match-test "5"
"generic" "generic"
) )
) )
)
Match-test "6" Match-test "6"
-------------- --------------
...@@ -175,7 +145,6 @@ Match-test "6" ...@@ -175,7 +145,6 @@ 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"
...@@ -184,11 +153,9 @@ Match-test "6" ...@@ -184,11 +153,9 @@ Match-test "6"
" " " "
) )
(paragraph (paragraph
(text_element
(text (text
"known inline environment" "known inline environment"
) )
)
(:Whitespace (:Whitespace
" " " "
) )
...@@ -197,7 +164,6 @@ Match-test "6" ...@@ -197,7 +164,6 @@ Match-test "6"
"small" "small"
) )
) )
)
Match-test "7" Match-test "7"
-------------- --------------
...@@ -206,21 +172,13 @@ Match-test "7" ...@@ -206,21 +172,13 @@ Match-test "7"
{\em block} {\em block}
### AST ### AST
(text_element
(block (block
(text_element
(command
(generic_command (generic_command
(CMDNAME (CMDNAME
"\em" "\em"
) )
) )
)
)
(text_element
(text (text
"block" "block"
) )
) )
\ No newline at end of file
)
)
\ No newline at end of file
...@@ -14,14 +14,12 @@ Match-test "1" ...@@ -14,14 +14,12 @@ Match-test "1"
### AST ### AST
(paragraph (paragraph
(text_element
(text (text
"Im allgemeinen werden die Bewohner Göttingens eingeteilt in Studenten," "Im allgemeinen werden die Bewohner Göttingens eingeteilt in Studenten,"
"Professoren, Philister und Vieh; welche vier Stände doch nichts weniger" "Professoren, Philister und Vieh; welche vier Stände doch nichts weniger"
"als streng geschieden sind. Der Viehstand ist der bedeutendste." "als streng geschieden sind. Der Viehstand ist der bedeutendste."
) )
) )
)
Match-test "2" Match-test "2"
-------------- --------------
...@@ -32,89 +30,63 @@ Match-test "2" ...@@ -32,89 +30,63 @@ Match-test "2"
### AST ### AST
(paragraph (paragraph
(text_element
(text (text
"Paragraphs may contain" "Paragraphs may contain"
) )
)
(:Whitespace (:Whitespace
" " " "
) )
(text_element
(block (block
(text_element
(command
(generic_command (generic_command
(CMDNAME (CMDNAME
"\em" "\em"
) )
) )
)
)
(text_element
(text (text
"inline blocks" "inline blocks"
) )
) )
)
)
(:Whitespace (:Whitespace
" " " "
) )
(text_element
(text (text
"as well as" "as well as"
) )
)
(:Whitespace (:Whitespace
" " " "
) )
(text_element
(command
(generic_command (generic_command
(CMDNAME (CMDNAME
"\emph" "\emph"
) )
(block (block
(text_element
(text (text
"inline commands" "inline commands"
) )
) )
) )
)
)
)
(:Whitespace (:Whitespace
"" ""
"" ""
) )
(text_element
(text (text
"and also special" "and also special"
) )
)
(:Whitespace (:Whitespace
" " " "
) )
(text_element
(command
(text_command (text_command
(ESCAPED (ESCAPED
"&" "&"
) )
) )
)
)
(:Whitespace (:Whitespace
" " " "
) )
(text_element
(text (text
"characters." "characters."
) )
) )
)
Match-test "3" Match-test "3"
-------------- --------------
...@@ -126,14 +98,12 @@ Match-test "3" ...@@ -126,14 +98,12 @@ Match-test "3"
### AST ### AST
(paragraph (paragraph
(text_element
(text (text
"Paragraphs are separated only by at least one blank line." "Paragraphs are separated only by at least one blank line."
"Therefore," "Therefore,"
"this line still belongs to the same paragraph." "this line still belongs to the same paragraph."
) )
) )
)
Match-test "4" Match-test "4"
-------------- --------------
...@@ -149,7 +119,6 @@ Match-test "4" ...@@ -149,7 +119,6 @@ Match-test "4"
### AST ### AST
(paragraph (paragraph
(text_element
(text (text
"Paragraphs" "Paragraphs"
"like the comment above" "like the comment above"
...@@ -157,7 +126,6 @@ Match-test "4" ...@@ -157,7 +126,6 @@ Match-test "4"
"in sequence."