mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 07:38:21 +00:00
Option to output error messages suitable for automated processing
Enables use of the optimizer as an editor plug-in.
This commit is contained in:
parent
f0068dd3bc
commit
68c8726a64
2 changed files with 27 additions and 6 deletions
|
@ -71,14 +71,22 @@ class EParse(Exception):
|
|||
def __init__(self, parser, msg):
|
||||
self.errorpos = parser.errorpos
|
||||
self.lno, self.cno, self.fname = GetErrLineCol(parser)
|
||||
filename = (self.fname.decode('utf8', 'replace')
|
||||
if parser.emap:
|
||||
filename = parser.filename
|
||||
else:
|
||||
filename = self.fname
|
||||
|
||||
filename = (filename.decode('utf8', 'replace')
|
||||
.replace(u'\\', u'\\\\')
|
||||
.replace(u'"', u'\\"')
|
||||
)
|
||||
|
||||
if parser.processpre and filename != '<stdin>':
|
||||
msg = u"(Line %d char %d): ERROR in \"%s\": %s" % (self.lno,
|
||||
self.cno, filename, msg)
|
||||
if parser.emap:
|
||||
msg = u'::ERROR::"%s":%d:%d: %s' % (
|
||||
any2u(filename.lstrip('u')), self.lno, self.cno, msg)
|
||||
elif parser.processpre and filename != '<stdin>':
|
||||
msg = u"(Line %d char %d): ERROR in \"%s\": %s" % (
|
||||
self.lno, self.cno, filename, msg)
|
||||
else:
|
||||
msg = u"(Line %d char %d): ERROR: %s" % (self.lno, self.cno, msg)
|
||||
super(EParse, self).__init__(msg)
|
||||
|
@ -2862,6 +2870,9 @@ list lazy_list_set(list L, integer i, list v)
|
|||
# Inline keyword
|
||||
self.enable_inline = 'inline' in options
|
||||
|
||||
# Automated Processing friendly error messages
|
||||
self.emap = 'emap' in options
|
||||
|
||||
# Symbol table:
|
||||
# This is a list of all local and global symbol tables.
|
||||
# The first element (0) is the global scope. Each symbol table is a
|
||||
|
@ -2983,7 +2994,7 @@ list lazy_list_set(list L, integer i, list v)
|
|||
finally:
|
||||
f.close()
|
||||
|
||||
return self.parse(script, options, lib = lib)
|
||||
return self.parse(script, options, filename, lib)
|
||||
|
||||
def __init__(self, lib = None):
|
||||
"""Initialization of library and lazy compilation.
|
||||
|
|
12
main.py
12
main.py
|
@ -236,6 +236,8 @@ Usage: {progname}
|
|||
[--shortname=<name>] * specify the script's short file name
|
||||
[--prettify] Prettify source file. Disables all -O options.
|
||||
[--bom] Prefix script with a UTF-8 byte-order mark
|
||||
[--emap] Output error messages in a format suitable for
|
||||
automated processing
|
||||
filename input file
|
||||
|
||||
Options marked with * are used to define the preprocessor macros __AGENTID__,
|
||||
|
@ -403,7 +405,7 @@ def main(argv):
|
|||
try:
|
||||
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HTyb:L:A:',
|
||||
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
||||
'timestamp', 'python-exceptions', 'prettify', 'bom',
|
||||
'timestamp', 'python-exceptions', 'prettify', 'bom', 'emap',
|
||||
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
|
||||
'avid=', 'avname=', 'assetid=', 'shortname=', 'builtins='
|
||||
'libdata=', 'postarg='))
|
||||
|
@ -428,6 +430,7 @@ def main(argv):
|
|||
raise_exception = False
|
||||
prettify = False
|
||||
bom = False
|
||||
emap = False
|
||||
builtins = None
|
||||
libdata = None
|
||||
|
||||
|
@ -528,6 +531,10 @@ def main(argv):
|
|||
|
||||
elif opt == '--bom':
|
||||
bom = True
|
||||
|
||||
elif opt == '--emap':
|
||||
emap = True
|
||||
|
||||
del opts
|
||||
|
||||
if prettify:
|
||||
|
@ -686,6 +693,9 @@ def main(argv):
|
|||
|
||||
if not preshow:
|
||||
|
||||
if emap:
|
||||
options.add('emap')
|
||||
|
||||
lib = lslopt.lslloadlib.LoadLibrary(builtins, libdata)
|
||||
p = parser(lib)
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue