Make more types identify themselves with is, don't tolerate

incorrectly-cased functions.
This commit is contained in:
Tom MacWright 2012-08-13 17:37:51 -04:00
parent 5b024a1465
commit 26e690dc0d
9 changed files with 14 additions and 11 deletions

View File

@ -142,7 +142,7 @@ var image_filter_functors = [
'x-gradient', 'y-gradient', 'sharpen'];
for (var i = 0; i < image_filter_functors.length; i++) {
var f = image_filter_functors[i];
var f = image_filter_functors[i];
tree.functions[f] = (function(f) {
return function() {
return new tree.ImageFilter(f);

View File

@ -356,7 +356,6 @@ carto.Parser = function Parser(env) {
// first, before parsing, that's when we use `peek()`.
//
parsers: {
//
// The `primary` rule is the *entry* and *exit* point of the parser.
// The rules here can appear at any level of the parse tree.
//
@ -370,7 +369,6 @@ carto.Parser = function Parser(env) {
//
// Only at one point is the primary rule not called from the
// block rule: at the root level.
//
primary: function() {
var node, root = [];
@ -465,7 +463,7 @@ carto.Parser = function Parser(env) {
if (! (name = /^([\w\-]+|%)\(/.exec(chunks[j]))) return;
name = name[1].toLowerCase();
name = name[1];
if (name === 'url') {
return null;
@ -587,11 +585,9 @@ carto.Parser = function Parser(env) {
$(this.entities.keyword);
},
//
// A Rule terminator. Note that we use `peek()` to check for '}',
// because the `block` rule will be expecting it, but we still need to make sure
// it's there, if ';' was ommitted.
//
end: function() {
return $(';') || peek('}');
},
@ -675,10 +671,8 @@ carto.Parser = function Parser(env) {
}
},
//
// The `block` rule is used by `ruleset`
// It's a wrapper around the `primary` rule, with added `{}`.
//
block: function() {
var content;
@ -687,16 +681,14 @@ carto.Parser = function Parser(env) {
}
},
//
// div, .class, body > p {...}
//
ruleset: function() {
var selectors = [], s, f, l, rules, filters = [];
save();
while (s = $(this.selector)) {
selectors.push(s);
if (! $(',')) { break }
if (! $(',')) { break; }
}
if (s) $(this.comment);

View File

@ -2,6 +2,7 @@
tree.Anonymous = function Anonymous(string) {
this.value = string.value || string;
this.is = 'anonymous';
};
tree.Anonymous.prototype = {
toString: function() {

View File

@ -2,7 +2,9 @@
tree.Expression = function Expression(value) {
this.value = value;
this.is = 'expression';
};
tree.Expression.prototype = {
eval: function(env) {
if (this.value.length > 1) {
@ -13,6 +15,7 @@ tree.Expression.prototype = {
return this.value[0].eval(env);
}
},
toString: function(env) {
return this.value.map(function(e) {
return e.toString(env);

View File

@ -4,6 +4,7 @@ tree.Invalid = function Invalid(chunk, index, message) {
this.index = index;
this.type = 'syntax';
this.message = message || "Invalid code: " + this.chunk;
this.is = 'invalid';
};
tree.Invalid.prototype.eval = function(env) {

View File

@ -9,6 +9,8 @@ tree.Rule = function Rule(name, value, index, filename) {
this.symbolizer = tree.Reference.symbolizer(this.name);
this.filename = filename;
this.variable = (name.charAt(0) === '@');
this.is = 'rule';
};
tree.Rule.prototype.clone = function() {

View File

@ -5,6 +5,7 @@ tree.Ruleset = function Ruleset(selectors, rules) {
this.rules = rules;
// static cache of find() function
this._lookups = {};
this.is = 'ruleset';
};
tree.Ruleset.prototype = {
eval: function(env) {

View File

@ -4,6 +4,7 @@ tree.Value = function Value(value) {
this.value = value;
this.is = 'value';
};
tree.Value.prototype = {
eval: function(env) {
if (this.value.length === 1) {

View File

@ -4,7 +4,9 @@ tree.Variable = function Variable(name, index, filename) {
this.name = name;
this.index = index;
this.filename = filename;
this.is = 'variable';
};
tree.Variable.prototype = {
eval: function(env) {
var variable,