Commit e8b56892 authored by di68kap's avatar di68kap
Browse files

- debugging-Ausgabe verbessert

parent 8143415b
......@@ -62,7 +62,7 @@ from DHParser.configuration import access_presets, finalize_presets, get_config_
from DHParser.error import Error
from DHParser.stringview import StringView
from DHParser.syntaxtree import Node, ZOMBIE_TAG, EMPTY_PTYPE
from DHParser.toolkit import escape_control_characters
from DHParser.toolkit import escape_control_characters, abbreviate_middle
__all__ = ('start_logging',
'suspend_logging',
......@@ -332,7 +332,7 @@ class HistoryRecord:
excerpt = html.escape(self.excerpt)
classes = list(HistoryRecord.Snapshot_Fields)
idx = {field_name: i for i, field_name in enumerate(classes)}
classes[idx['status']] = status.lower()
classes[idx['status']] = 'error' if status.startswith('ERROR') else status.lower()
if status in (self.MATCH, self.DROP):
n = max(40 - len(excerpt), 0)
dots = '...' if len(self.text) > n else ''
......@@ -393,13 +393,10 @@ class HistoryRecord:
@property
def excerpt(self):
if self.node:
l = len(self.node)
s = str(self.node)
excerpt = s[:18] + ' ... ' + s[-17:] if l > 40 else s[:40]
excerpt = abbreviate_middle(str(self.node), 40)
else:
l = len(self.text)
s = str(self.text[:40])
excerpt = s[:36] + ' ...' if l > 36 else s
s = self.text
excerpt = s[:36] + ' ...' if len(s) > 36 else s
excerpt = escape_control_characters(excerpt)
return excerpt
......
......@@ -43,7 +43,7 @@ from DHParser.stringview import StringView, EMPTY_STRING_VIEW
from DHParser.syntaxtree import Node, FrozenNode, RootNode, WHITESPACE_PTYPE, \
TOKEN_PTYPE, ZOMBIE_TAG, EMPTY_NODE, ResultType
from DHParser.toolkit import sane_parser_name, escape_control_characters, re, cython, \
RX_NEVER_MATCH, RxPatternType
abbreviate_middle, RX_NEVER_MATCH, RxPatternType
__all__ = ('ParserError',
......@@ -1463,7 +1463,7 @@ class Token(Parser):
return None, text
def __repr__(self):
return ("'%s'" if self.text.find("'") <= 0 else '"%s"') % self.text
return ("'%s'" if self.text.find("'") <= 0 else '"%s"') % abbreviate_middle(self.text, 80)
class RegExp(Parser):
......@@ -1513,7 +1513,7 @@ class RegExp(Parser):
return None, text
def __repr__(self):
return escape_control_characters('/%s/' % self.regexp.pattern)
return escape_control_characters('/%s/' % abbreviate_middle(self.regexp.pattern, 120))
def DropToken(text: str) -> Token:
......
......@@ -61,6 +61,7 @@ __all__ = ('typing',
'is_filename',
'concurrent_ident',
'unrepr',
'abbreviate_middle',
'lstrip_docstring',
'issubtype',
'isgenerictype',
......@@ -227,6 +228,18 @@ class unrepr:
return self.s
def abbreviate_middle(s: str, max_length: int) -> str:
"""Shortens string `s` by replacing the middle part with an ellipsis
sign ` ... ` if the size of the string exceeds `max_length`."""
assert max_length > 6
l = len(s) # type: int
if l > max_length:
a = max_length // 2 - 2 # type: int
b = max_length // 2 - 3 # type: int
s = s[:a] + ' ... ' + s[-b:] if l > 40 else s
return s
#######################################################################
#
# type system support
......
Supports Markdown
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