Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[ALOY-525] added support for If and cond attribute

add filename for XML parsing errors so we know which file the error is in
  • Loading branch information...
commit 62b70981ba11cf985a31b9133117f9ebc8d0e56b 1 parent 2bdef3d
@jhaynie authored
View
41 Alloy/commands/compile/parsers/Alloy.If.js
@@ -0,0 +1,41 @@
+var _ = require('../../../lib/alloy/underscore')._,
+ CU = require('../compilerUtils'),
+ U = require('../../../utils');
+
+exports.parse = function(node, state) {
+ return require('./base').parse(node, state, parse);
+};
+
+function parse(node, state, args) {
+ var code = '';
+
+ var cond = node.getAttribute('cond');
+
+ if (cond)
+ {
+ code+='if (' + cond + '){\n';
+ }
+
+ // the platform,formFactor,etc checks comes for free since the base handles it
+
+ _.each(U.XML.getElementsFromNodes(node.childNodes), function(child) {
+ var childArgs = CU.getParserArgs(child, state);
+ code += CU.generateNodeExtended(child, state, {
+ parent: {
+ node: state.parent,
+ symbol: state.parent.symbol
+ }
+ });
+ });
+
+ if (cond)
+ {
+ code+='}\n';
+ }
+
+ return {
+ parent: {},
+ styles: state.styles,
+ code: code
+ }
+};
View
1  Alloy/common/constants.js
@@ -90,6 +90,7 @@ exports.IMPLICIT_NAMESPACES = {
Model: NS_ALLOY,
Require: NS_ALLOY,
Widget: NS_ALLOY,
+ If: NS_ALLOY,
// Alloy.Abstract
ButtonNames: NS_ALLOY_ABSTRACT,
View
8 Alloy/utils.js
@@ -40,7 +40,7 @@ exports.XML = {
}
return elems;
},
- parseFromString: function(string) {
+ parseFromString: function(string,filename) {
// TODO: https://jira.appcelerator.org/browse/ALOY-267
// var warn = console.warn;
// console.warn = function(msg) {
@@ -51,14 +51,14 @@ exports.XML = {
try {
var errorHandler = {};
errorHandler.error = errorHandler.fatalError = function(m) {
- exports.die(['Error parsing XML file.'].concat((m || '').split(/[\r\n]/)));
+ exports.die(['Error parsing XML file '+filename].concat((m || '').split(/[\r\n]/)));
};
errorHandler.warn = errorHandler.warning = function(m) {
logger.warn((m || '').split(/[\r\n]/));
};
var doc = new DOMParser({errorHandler:errorHandler,locator:{}}).parseFromString(string);
} catch (e) {
- exports.die('Error parsing XML file.', e);
+ exports.die('Error parsing XML file '+filename, e);
}
//console.warn = warn;
@@ -66,7 +66,7 @@ exports.XML = {
},
parseFromFile: function(filename) {
var xml = fs.readFileSync(filename,'utf8');
- return exports.XML.parseFromString(xml);
+ return exports.XML.parseFromString(xml,filename);
},
createEmptyNode: function(name, ns) {
var str = '<' + name + (ns ? ' ns="' + ns + '"' : '') + '></' + name + '>';
Please sign in to comment.
Something went wrong with that request. Please try again.