diff --git a/lslopt/lslparse.py b/lslopt/lslparse.py index b3303ff..39139c0 100644 --- a/lslopt/lslparse.py +++ b/lslopt/lslparse.py @@ -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 != '': - 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 != '': + 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. diff --git a/main.py b/main.py index d9fdd3c..f27252d 100755 --- a/main.py +++ b/main.py @@ -236,6 +236,8 @@ Usage: {progname} [--shortname=] * 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: