Various usability improvements
This commit is contained in:
parent
0ac3c1a0a3
commit
503fae9e18
21
CHANGES
21
CHANGES
@ -1,5 +1,26 @@
|
||||
Version 0.4
|
||||
-----------
|
||||
11/18/2018 Various usability fixes observed from last compilers course.
|
||||
|
||||
- Errors encountered during grammar construction are now
|
||||
reported as part of the raised GrammarError exception
|
||||
instead of via logging. This places them in the same
|
||||
visual position as normal Python errors (at the end
|
||||
of the traceback)
|
||||
|
||||
- Repeated warning messages about unused tokens have
|
||||
been consolidated in a single warning message to make
|
||||
the output less verbose.
|
||||
|
||||
- Grammar attributes (e.g., p.TOKEN) used during parsing
|
||||
are now read-only.
|
||||
|
||||
- The error about "infinite recursion" is only checked
|
||||
if there are no undefined grammar symbols. Sometimes
|
||||
you'd get this message and be confused when the only
|
||||
mistake was a bad token name or similar.
|
||||
|
||||
|
||||
9/8/2018 Fixed Issue #14. YaccProduction index property causes
|
||||
AttributeError if index is 0
|
||||
|
||||
|
13
sly/yacc.py
13
sly/yacc.py
@ -152,10 +152,10 @@ class YaccProduction:
|
||||
raise AttributeError(f'No symbol {name}. Must be one of {nameset}.')
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name[0:1] == '_' or name not in self._namemap:
|
||||
if name[:1] == '_':
|
||||
super().__setattr__(name, value)
|
||||
else:
|
||||
self._slice[self._namemap[name]].value = value
|
||||
raise AttributeError(f"Can't reassign the value of attribute {name!r}")
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# === Grammar Representation ===
|
||||
@ -1719,6 +1719,7 @@ class Parser(metaclass=ParserMeta):
|
||||
for u in unreachable:
|
||||
cls.log.warning('Symbol %r is unreachable', u)
|
||||
|
||||
if len(undefined_symbols) == 0:
|
||||
infinite = grammar.infinite_cycles()
|
||||
for inf in infinite:
|
||||
errors += 'Infinite recursion detected for symbol %r\n' % inf
|
||||
@ -1806,11 +1807,11 @@ class Parser(metaclass=ParserMeta):
|
||||
if token:
|
||||
lineno = getattr(token, 'lineno', 0)
|
||||
if lineno:
|
||||
sys.stderr.write(f'yacc: Syntax error at line {lineno}, token={token.type}\n')
|
||||
sys.stderr.write(f'sly: Syntax error at line {lineno}, token={token.type}\n')
|
||||
else:
|
||||
sys.stderr.write(f'yacc: Syntax error, token={token.type}')
|
||||
sys.stderr.write(f'sly: Syntax error, token={token.type}')
|
||||
else:
|
||||
sys.stderr.write('yacc: Parse error in input. EOF\n')
|
||||
sys.stderr.write('sly: Parse error in input. EOF\n')
|
||||
|
||||
def errok(self):
|
||||
'''
|
||||
@ -1995,4 +1996,4 @@ class Parser(metaclass=ParserMeta):
|
||||
continue
|
||||
|
||||
# Call an error function here
|
||||
raise RuntimeError('yacc: internal parser error!!!\n')
|
||||
raise RuntimeError('sly: internal parser error!!!\n')
|
||||
|
Loading…
Reference in New Issue
Block a user