Support operations between strings and fields, support concatenating
strings.
This commit is contained in:
parent
ea89af6ae2
commit
28ab872e72
@ -763,6 +763,7 @@ carto.Parser = function Parser(env) {
|
||||
return new tree.Value(expressions);
|
||||
}
|
||||
},
|
||||
// A sub-expression, contained by parenthensis
|
||||
sub: function() {
|
||||
var e;
|
||||
|
||||
@ -770,12 +771,15 @@ carto.Parser = function Parser(env) {
|
||||
return e;
|
||||
}
|
||||
},
|
||||
// This is a misnomer because it actually handles multiplication
|
||||
// and division.
|
||||
multiplication: function() {
|
||||
var m, a, op, operation;
|
||||
if (m = $(this.operand)) {
|
||||
while ((op = ($('/') || $('*'))) && (a = $(this.operand))) {
|
||||
operation = new tree.Operation(op, [operation || m, a], memo);
|
||||
}
|
||||
console.log(m);
|
||||
return operation || m;
|
||||
}
|
||||
},
|
||||
@ -793,9 +797,7 @@ carto.Parser = function Parser(env) {
|
||||
// An operand is anything that can be part of an operation,
|
||||
// such as a Color, or a Variable
|
||||
operand: function() {
|
||||
return $(this.sub) || $(this.entities.dimension) ||
|
||||
$(this.entities.color) || $(this.entities.variable) ||
|
||||
$(this.entities.call);
|
||||
return $(this.sub) || $(this.entity);
|
||||
},
|
||||
|
||||
// Expressions either represent mathematical operations,
|
||||
|
@ -4,8 +4,9 @@ tree.Field = function Field(content) {
|
||||
this.value = content || '';
|
||||
this.is = 'field';
|
||||
};
|
||||
|
||||
tree.Field.prototype = {
|
||||
toString: function(quotes) {
|
||||
toString: function() {
|
||||
return '[' + this.value + ']';
|
||||
},
|
||||
'eval': function() {
|
||||
|
@ -31,16 +31,18 @@ tree.Operation.prototype.eval = function(env) {
|
||||
}
|
||||
|
||||
if (a instanceof tree.Quoted || b instanceof tree.Quoted) {
|
||||
env.error({
|
||||
message: 'One cannot add, subtract, divide, or multiply strings.',
|
||||
index: this.index,
|
||||
type: 'runtime',
|
||||
filename: this.filename
|
||||
});
|
||||
return {
|
||||
is: 'undefined',
|
||||
value: 'undefined'
|
||||
};
|
||||
if (this.op === '*' || this.op === '/') {
|
||||
env.error({
|
||||
message: 'One cannot add, subtract, divide, or multiply strings.',
|
||||
index: this.index,
|
||||
type: 'runtime',
|
||||
filename: this.filename
|
||||
});
|
||||
return {
|
||||
is: 'undefined',
|
||||
value: 'undefined'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return a.operate(this.op, b);
|
||||
|
@ -10,8 +10,14 @@ tree.Quoted.prototype = {
|
||||
var xmlvalue = this.value.replace(/\'/g, ''');
|
||||
return (quotes === true) ? "'" + xmlvalue + "'" : this.value;
|
||||
},
|
||||
|
||||
'eval': function() {
|
||||
return this;
|
||||
},
|
||||
|
||||
operate: function(op, other) {
|
||||
return new tree.Quoted(this.quote,
|
||||
tree.operate(op, this.toString(), other.toString()));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -166,6 +166,8 @@ tree.Reference.validValue = function(env, selector, value) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if (tree.Reference.selector(selector).type == 'expression') {
|
||||
return true;
|
||||
} else {
|
||||
if (tree.Reference.selector(selector).validate) {
|
||||
var valid = false;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#world {
|
||||
text-name: [NAME];
|
||||
text-name: "hello " + [NAME];
|
||||
text-size: 11;
|
||||
text-face-name: "Georgia Regular", "Arial Italic";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user