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