1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36:01 +02:00

Bug 480238 - Clean Up Acorn QML Parser

Fixed the AST elements so that they more closely match the format used
by acorn (i.e. using 'id' instead of 'identifier' and 'name' instead of
'raw' for the identifier name).  Resolved one of the ambiguities dealing
with using 'signal', 'property', and 'readonly' as identifiers for
properties and QML Objects.   Added a bunch of new tests and fixed the
old ones to match the new AST.

Change-Id: I5a8bbd14b3e6f8531268740dd9e57cb48a0e22b3
Signed-off-by: Matthew Bastien <mbastien@blackberry.com>
This commit is contained in:
Matthew Bastien 2015-11-03 16:07:42 -05:00
parent 5eaf1129a5
commit 19cd53ec10
6 changed files with 2528 additions and 1917 deletions

View file

@ -13,12 +13,12 @@
// This will only be visible globally if we are in a browser environment // This will only be visible globally if we are in a browser environment
var acornQML; var acornQML;
(function(mod) { (function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
return module.exports = mod(require("./inject.js"), require("acorn")); return module.exports = mod(require("./inject.js"), require("acorn"));
if (typeof define == "function" && define.amd) // AMD if (typeof define == "function" && define.amd) // AMD
return define(["./inject.js", "acorn/dist/acorn"], mod); return define(["./inject.js", "acorn/dist/acorn"], mod);
acornQML = mod(injectQML, acorn); // Plain browser env acornQML = mod(injectQML, acorn); // Plain browser env
})(function(injectQML, acorn) { })(function (injectQML, acorn) {
return injectQML(acorn); return injectQML(acorn);
}) })

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,6 @@
"test": "node test/run.js" "test": "node test/run.js"
}, },
"dependencies": { "dependencies": {
"acorn": "^2.4.0" "acorn": "^2.5.2"
} }
} }

View file

@ -75,7 +75,7 @@ outputStats("Total", total);
groupEnd(); groupEnd();
if (total.failed && typeof process === "object") { if (total.failed && typeof process === "object") {
process.stdout.write("", function() { process.stdout.write("", function () {
process.exit(1); process.exit(1);
}); });
} }

File diff suppressed because it is too large Load diff

View file

@ -10,67 +10,52 @@
*******************************************************************************/ *******************************************************************************/
'use strict'; 'use strict';
(function(mod) { (function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
return mod(require("acorn/walk")); return mod(require("acorn/walk"));
if (typeof define == "function" && define.amd) // AMD if (typeof define == "function" && define.amd) // AMD
return define([ "acorn/dist/walk" ], mod); return define(["acorn/dist/walk"], mod);
mod(acorn.walk); // Plain browser env mod(acorn.walk); // Plain browser env
})(function(walk) { })(function (walk) {
function skipThrough(node, st, c) { c(node, st) } function skipThrough(node, st, c) {
function ignore(node, st, c) {} c(node, st)
}
var base = walk.base; function ignore(node, st, c) {}
base["Program"] = function(node, st, c) {
for (var i = 0; i < node.body.length; i++) { var base = walk.base;
var nodeBody = node.body[i]; base["Program"] = function (node, st, c) {
if (node.body[i].type === "QMLObjectLiteral") { c(node.headerStatements, st);
c(node.body[i], st, "QMLRootObject"); c(node.rootObject, st, "QMLRootObject");
} else { };
c(node.body[i], st); base["QMLHeaderStatements"] = function (node, st, c) {
} for (var i = 0; i < node.statements.length; i++) {
} c(node.statements[i], st, "QMLHeaderStatement");
} }
base["QMLHeaderStatements"] = function(node, st, c) { };
for (var i = 0; i < node.statements.length; i++) { base["QMLHeaderStatement"] = skipThrough;
c(node.statements[i], st, "QMLHeaderStatement"); base["QMLImportStatement"] = ignore;
} base["QMLPragmaStatement"] = ignore;
} base["QMLRootObject"] = skipThrough;
base["QMLHeaderStatement"] = skipThrough; base["QMLObjectLiteral"] = function (node, st, c) {
base["QMLImportStatement"] = function(node, st, c) { c(node.block, st);
c(node.module, st); };
} base["QMLMemberBlock"] = function (node, st, c) {
base["QMLModule"] = ignore; for (var i = 0; i < node.members.length; i++) {
base["QMLPragmaStatement"] = ignore; c(node.members[i], st, "QMLMember");
base["QMLRootObject"] = skipThrough; }
base["QMLObjectLiteral"] = function(node, st, c) { };
c(node.block, st); base["QMLMember"] = skipThrough;
} base["QMLPropertyDeclaration"] = function (node, st, c) {
base["QMLMemberBlock"] = function(node, st, c) { c(node.binding, st);
for (var i = 0; i < node.members.length; i++) { };
c(node.members[i], st, "QMLMember"); base["QMLSignalDefinition"] = ignore;
} base["QMLPropertyBinding"] = function (node, st, c) {
} c(node.binding, st);
base["QMLMember"] = skipThrough; };
base["QMLPropertyDeclaration"] = function(node, st, c) { base["QMLStatementBlock"] = function (node, st, c) {
c(node.identifier, st, "Pattern"); for (var i = 0; i < node.statements.length; i++) {
c(node.binding, st); c(node.statements[i], st, "Statement");
} }
base["QMLSignalDefinition"] = ignore; };
base["QMLProperty"] = function(node, st, c) {
// c(node.qualifiedId, st)
c(node.binding, st);
}
base["QMLBinding"] = function(node, st, c) {
if (node.block) {
c(node.block, st);
} else {
c(node.expr, st, "Expression");
}
}
base["QMLStatementBlock"] = function(node, st, c) {
for (var i = 0; i < node.statements.length; i++) {
c(node.statements[i], st, "Statement");
}
}
}) })