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:
(self.line_col[0], self.line_col[1], self.stack, str(self.node))
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
def stack(self) -> str:
......@@ -171,7 +173,7 @@ class HistoryRecord:
@property
def status(self) -> str:
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
def extent(self) -> slice:
......@@ -273,7 +275,7 @@ def add_parser_guard(parser_func):
if grammar.history_tracking__:
# don't track returning parsers except in case an error has occurred
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)
grammar.history__.append(record)
# print(record.stack, record.status, rest[:20].replace('\n', '|'))
......@@ -838,7 +840,7 @@ class Grammar:
record.node.pos = 0
record = HistoryRecord(self.call_stack__.copy(), stitches[-1], len(rest))
self.history__.append(record)
self.history_tracking__ = False
self.history_tracking__ = False # TODO: add an explanation here
if stitches:
if 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
# type hints for Cython python -> C compiler to speed up the most
......
......@@ -246,9 +246,9 @@ class Node(collections.abc.Sized):
def __str__(self):
if self.children:
return "".join(str(child) for child in self.children)
elif isinstance(self.result, StringView):
self.result = str(self.result)
return self.result
elif isinstance(self._result, StringView):
self.result = str(self._result)
return self._result
def __repr__(self):
......
#!/bin/sh
# CFLAGS="-O3 -march=native -mtune=native"
python3 setup.py build_ext --inplace
......@@ -374,15 +374,10 @@ Match-test "2"
% Comment
### AST
(LFF
(NEW_LINE
""
""
)
(WSPC
"% Comment"
)
)
Match-test "3"
--------------
......@@ -393,21 +388,10 @@ Match-test "3"
### AST
(LFF
(NEW_LINE
""
""
)
(WSPC
(:RegExp
"% Comment"
)
(:RegExp
""
""
)
)
)
Match-test "4"
--------------
......@@ -419,17 +403,10 @@ Match-test "4"
### AST
(LFF
(NEW_LINE
""
""
)
(WSPC
""
""
""
)
)
Fail-test "10"
--------------
......
......@@ -51,15 +51,11 @@ Match-test "1"
\command
### AST
(text_element
(command
(generic_command
(CMDNAME
"\command"
)
)
)
)
Match-test "2"
--------------
......@@ -68,15 +64,11 @@ Match-test "2"
\textbackslash
### AST
(text_element
(command
(text_command
(TXTCOMMAND
"\textbackslash"
)
)
)
)
Match-test "3"
--------------
......@@ -85,40 +77,26 @@ Match-test "3"
\footnote{footnote}
### AST
(text_element
(command
(known_command
(footnote
(:Token
(:RegExp
"\footnote"
)
)
(block_of_paragraphs
(:Token
(:RegExp
"{"
)
)
(sequence
(paragraph
(text_element
(text
"footnote"
)
)
)
)
(:Token
(:RegExp
"}"
)
)
)
)
)
)
)
Match-test "4"
--------------
......@@ -127,15 +105,11 @@ Match-test "4"
[
### AST
(text_element
(command
(text_command
(BRACKETS
"["
)
)
)
)
Match-test "5"
--------------
......@@ -144,7 +118,6 @@ Match-test "5"
\begin{generic} unknown inline environment \end{generic}
### AST
(text_element
(generic_inline_env
(begin_environment
"generic"
......@@ -153,11 +126,9 @@ Match-test "5"
" "
)
(paragraph
(text_element
(text
"unknown inline environment"
)
)
(:Whitespace
" "
)
......@@ -166,7 +137,6 @@ Match-test "5"
"generic"
)
)
)
Match-test "6"
--------------
......@@ -175,7 +145,6 @@ Match-test "6"
\begin{small} known inline environment \end{small}
### AST
(text_element
(generic_inline_env
(begin_environment
"small"
......@@ -184,11 +153,9 @@ Match-test "6"
" "
)
(paragraph
(text_element
(text
"known inline environment"
)
)
(:Whitespace
" "
)
......@@ -197,7 +164,6 @@ Match-test "6"
"small"
)
)
)
Match-test "7"
--------------
......@@ -206,21 +172,13 @@ Match-test "7"
{\em block}
### AST
(text_element
(block
(text_element
(command
(generic_command
(CMDNAME
"\em"
)
)
)
)
(text_element
(text
"block"
)
)
\ No newline at end of file
)
)
\ No newline at end of file
......@@ -14,14 +14,12 @@ Match-test "1"
### AST
(paragraph
(text_element
(text
"Im allgemeinen werden die Bewohner Göttingens eingeteilt in Studenten,"
"Professoren, Philister und Vieh; welche vier Stände doch nichts weniger"
"als streng geschieden sind. Der Viehstand ist der bedeutendste."
)
)
)
Match-test "2"
--------------
......@@ -32,89 +30,63 @@ Match-test "2"
### AST
(paragraph
(text_element
(text
"Paragraphs may contain"
)
)
(:Whitespace
" "
)
(text_element
(block
(text_element
(command
(generic_command
(CMDNAME
"\em"
)
)
)
)
(text_element
(text
"inline blocks"
)
)
)
)
(:Whitespace
" "
)
(text_element
(text
"as well as"
)
)
(:Whitespace
" "
)
(text_element
(command
(generic_command
(CMDNAME
"\emph"
)
(block
(text_element
(text
"inline commands"
)
)
)
)
)
)
(:Whitespace
""
""
)
(text_element
(text
"and also special"
)
)
(:Whitespace
" "
)
(text_element
(command
(text_command
(ESCAPED
"&"
)
)
)
)
(:Whitespace
" "
)
(text_element
(text
"characters."
)
)
)
Match-test "3"
--------------
......@@ -126,14 +98,12 @@ Match-test "3"
### AST
(paragraph
(text_element
(text
"Paragraphs are separated only by at least one blank line."
"Therefore,"
"this line still belongs to the same paragraph."
)
)
)
Match-test "4"
--------------
......@@ -149,7 +119,6 @@ Match-test "4"
### AST
(paragraph
(text_element
(text
"Paragraphs"
"like the comment above"
......@@ -157,7 +126,6 @@ Match-test "4"
"in sequence."
)
)
)
Match-test "5"
--------------
......@@ -169,75 +137,52 @@ Match-test "5"
### AST
(paragraph
(text_element
(text
"Paragraphs may contain"
)
)
(:Whitespace
" "
)
(text_element
(block
(text_element
(command
(generic_command
(CMDNAME
"\em"
)
)
)
)
(text_element
(text
"emphasized"
)
)
)
)
(:Whitespace
" "
)
(text_element
(text
"or"
)
)
(:Whitespace
" "
)
(text_element
(block
(text_element
(command
(generic_command
(CMDNAME
"\bf"
)
)
)
)
(text_element
(text
"bold"
)
)
)
)
(:Whitespace
" "
)
(text_element
(text
"text."
"Most of these commands can have different forms as, for example:"
)
)
(:Whitespace
""
""
)
(text_element
(generic_inline_env
(begin_environment
"small"
......@@ -246,11 +191,9 @@ Match-test "5"
" "
)
(paragraph
(text_element
(text
"small"
)
)
(:Whitespace
" "
)
......@@ -259,42 +202,29 @@ Match-test "5"
"small"
)
)
)
(:Whitespace
" "
)
(text_element
(text
"or"
)
)
(:Whitespace
" "
)
(text_element
(block
(text_element
(command
(generic_command
(CMDNAME
"\large"
)
)
)
)
(text_element
(text
"large"
)
)
)
)
(text_element
(text
"."
)
)
)
Match-test "6"
--------------
......@@ -304,41 +234,29 @@ Match-test "6"
### AST
(paragraph
(text_element
(text
"Paragraphs may also contain"
)
)
(:Whitespace
" "
)
(text_element
(block
(text_element
(command
(generic_command
(CMDNAME
"\xy"
)
)
)
)
(text_element
(text
"unknown blocks"
)
)
(:Whitespace
" "
)
)
)
(text_element
(text
"."
)
)
)
Match-test "7"
--------------
......@@ -348,16 +266,12 @@ Match-test "7"
### AST
(paragraph
(text_element
(text
"Paragraphs may contain"
)
)
(:Whitespace
" "
)
(text_element
(command
(generic_command
(CMDNAME
"\xy"
......@@ -368,45 +282,31 @@ Match-test "7"
)
)
(block
(text_element
(text
"some"
)
)
(:Whitespace
" "
)
(text_element
(block
(text_element
(command
(generic_command
(CMDNAME
"\em"
)
)
)
)
(text_element
(text
"unbknown"
)
)
)
)
)
)
)
)
(:Whitespace
" "
)