mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-06-30 23:28:20 +00:00
Implement accurate error reporting through #line directives.
Also simplify and fix the matching expression for #line (gcc inserts numeric flags at the end). It still has many problems. It's O(n^2). It's calculated at every EParse, and EParse can be triggered and ignored while scanning vectors or globals. UniConvScript doesn't read #line at all, thus failing to report a meaningful input line. But at least it's a start.
This commit is contained in:
parent
4ba0518353
commit
1071941301
2 changed files with 65 additions and 17 deletions
16
main.py
16
main.py
|
@ -59,7 +59,15 @@ class UniConvScript(object):
|
|||
"""Converts the script to Unicode, setting the properties required by
|
||||
EParse to report a meaningful error position.
|
||||
"""
|
||||
def __init__(self, script):
|
||||
def __init__(self, script, options = (), filename = '<stdin>'):
|
||||
self.linedir = []
|
||||
self.filename = filename
|
||||
# We don't interpret #line here. In case of an encode error,
|
||||
# we're in the dark about which file it comes from. User needs
|
||||
# --preshow to view the #line directives and find the correspondence
|
||||
# themselves.
|
||||
#self.processpre = 'processpre' in options
|
||||
self.processpre = False
|
||||
self.script = script
|
||||
|
||||
def to_unicode(self):
|
||||
|
@ -596,7 +604,8 @@ def main(argv):
|
|||
# Try converting the script to Unicode, to report any encoding
|
||||
# errors with accurate line information. At this point we don't
|
||||
# need the result.
|
||||
UniConvScript(script).to_unicode()
|
||||
UniConvScript(script, options,
|
||||
fname if fname != '-' else '<stdin>').to_unicode()
|
||||
except EParse as e:
|
||||
# We don't call ReportError to prevent problems due to
|
||||
# displaying invalid UTF-8
|
||||
|
@ -644,7 +653,8 @@ def main(argv):
|
|||
|
||||
p = parser(builtins, seftable)
|
||||
try:
|
||||
ts = p.parse(script, options)
|
||||
ts = p.parse(script, options,
|
||||
fname if fname != '-' else '<stdin>')
|
||||
except EParse as e:
|
||||
ReportError(script, e)
|
||||
return 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue