From 204ed1f2579ef191793d1489bddbdc1a07c8e6ca Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Mon, 25 May 2015 11:20:55 -0700 Subject: [PATCH] New: added the option --xml-output-format for the command objj Previously, it was not possible to specify the desired output format of the command objj. Now we can have either the default format or a xml format if --xml-output-format is added. --- Objective-J/CommonJS/lib/objective-j.js | 7 +++ Objective-J/ObjJAcornCompiler.js | 58 ++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 9dbf5ebd9..9ff487184 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -94,6 +94,7 @@ exports.run = function(args) print(" -I, --objj-include-paths include a specific framework paths") print(" -h, --help print this help"); print(" -m, --multifiles launch objj on several files") + print(" --xml-output-format specify the output format in xml.") return; } @@ -110,6 +111,11 @@ exports.run = function(args) argv.shift(); multipleFiles = true; break + + case "--xml-output-format": + argv.shift(); + exports.outputFormatInXML = true; + break; } } } @@ -229,6 +235,7 @@ function getPackage() { exports.version = function() { return getPackage()["version"]; } exports.revision = function() { return getPackage()["cappuccino-revision"]; } exports.timestamp = function() { return new Date(getPackage()["cappuccino-timestamp"]); } +exports.outputFormatInXML = false; exports.fullVersionString = function() { return sprintf("objective-j %s (%04d-%02d-%02d %s)", diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index d5561fb47..b1e819d21 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -394,9 +394,22 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* #ifdef BROWSER console.log(message); #else - print(message); + if (exports.outputFormatInXML) + { + var dict = new CFMutableDictionary(); + dict.addValueForKey('line', e.line); + dict.addValueForKey('path', this.URL.absoluteString()); + dict.addValueForKey('message', message); + + print(CFPropertyListCreateXMLData([dict], kCFPropertyListXMLFormat_v1_0).rawString()); + } + else + { + print(message); + } #endif } + throw e; } @@ -434,6 +447,8 @@ exports.ObjJAcornCompiler.compileFileDependencies = function(/*String*/ aString, ObjJAcornCompiler.prototype.compilePass2 = function() { + var warnings = []; + ObjJAcornCompiler.currentCompileFile = this.URL; this.pass = 2; this.jsBuffer = new StringBuffer(); @@ -442,14 +457,32 @@ ObjJAcornCompiler.prototype.compilePass2 = function() compile(this.tokens, new Scope(null ,{ compiler: this }), pass2); for (var i = 0; i < this.warnings.length; i++) { - var message = this.prettifyMessage(this.warnings[i], "WARNING"); + var warning = this.warnings[i], + type = "WARNING"; + + var message = this.prettifyMessage(warning, type); #ifdef BROWSER console.log(message); #else - print(message); + if (exports.outputFormatInXML) + { + var dict = new CFMutableDictionary(); + dict.addValueForKey('line', warning.line) + dict.addValueForKey('path', this.URL.absoluteString()) + dict.addValueForKey('message', message) + + warnings.push(dict); + } + else + { + print(message); + } #endif } + if (warnings.length && exports.outputFormatInXML) + print(CFPropertyListCreateXMLData(warnings, kCFPropertyListXMLFormat_v1_0).rawString()); + //print(this.URL + ": " + this.jsBuffer.toString()); return this.jsBuffer.toString(); } @@ -659,10 +692,23 @@ ObjJAcornCompiler.prototype.prettifyMessage = function(/* Message */ aMessage, / ObjJAcornCompiler.prototype.error_message = function(errorMessage, node) { - var pos = exports.acorn.getLineInfo(this.source, node.start), - syntaxError = {message: errorMessage, line: pos.line, column: pos.column, lineStart: pos.lineStart, lineEnd: pos.lineEnd}; + var pos = exports.acorn.getLineInfo(this.source, node.start); - return new SyntaxError(this.prettifyMessage(syntaxError, "ERROR")); + if (exports.outputFormatInXML) + { + var dict = new CFMutableDictionary(); + dict.addValueForKey('line', pos.line); + dict.addValueForKey('path', this.URL.absoluteString()); + dict.addValueForKey('message', errorMessage); + + return CFPropertyListCreateXMLData([dict], kCFPropertyListXMLFormat_v1_0).rawString(); + } + else + { + var syntaxError = {message: errorMessage, line: pos.line, column: pos.column, lineStart: pos.lineStart, lineEnd: pos.lineEnd}; + + return new SyntaxError(this.prettifyMessage(syntaxError, "ERROR")); + } } ObjJAcornCompiler.prototype.pushImport = function(url)