Refine parse error message a bit.
This commit is contained in:
parent
8cfbc2f80e
commit
59f408dcf4
|
@ -22,7 +22,7 @@ class ParseException(Exception):
|
|||
return "%s\n%s"%(self.s, " "*(self.col-1) + "^")
|
||||
|
||||
def __str__(self):
|
||||
return "%s at offset %s of %s"%(self.msg, self.col, repr(self.s))
|
||||
return "%s at char %s"%(self.msg, self.col)
|
||||
|
||||
|
||||
def actions_log(lst):
|
||||
|
|
|
@ -45,10 +45,24 @@ def xrepr(s):
|
|||
return repr(s)[1:-1]
|
||||
|
||||
|
||||
def inner_repr(s):
|
||||
"""
|
||||
Returns the inner portion of a string or unicode repr (i.e. without the
|
||||
quotes)
|
||||
"""
|
||||
if isinstance(s, unicode):
|
||||
return repr(s)[2:-1]
|
||||
else:
|
||||
return repr(s)[1:-1]
|
||||
|
||||
|
||||
def escape_unprintables(s):
|
||||
"""
|
||||
Like inner_repr, but preserves line breaks.
|
||||
"""
|
||||
s = s.replace("\r\n", "PATHOD_MARKER_RN")
|
||||
s = s.replace("\n", "PATHOD_MARKER_N")
|
||||
s = repr(s)[1:-1]
|
||||
s = inner_repr(s)
|
||||
s = s.replace("PATHOD_MARKER_RN", "\n")
|
||||
s = s.replace("PATHOD_MARKER_N", "\n")
|
||||
return s
|
||||
|
|
|
@ -17,6 +17,11 @@ def test_data_path():
|
|||
tutils.raises(ValueError, utils.data.path, "nonexistent")
|
||||
|
||||
|
||||
def test_inner_repr():
|
||||
assert utils.inner_repr("\x66") == "\x66"
|
||||
assert utils.inner_repr(u"foo") == "foo"
|
||||
|
||||
|
||||
def test_escape_unprintables():
|
||||
s = "".join([chr(i) for i in range(255)])
|
||||
e = utils.escape_unprintables(s)
|
||||
|
|
Loading…
Reference in New Issue