Comparing version 1.0.8 to 1.1.0
@@ -114,3 +114,3 @@ 'use strict'; | ||
requires.push(node.name.toLowerCase() === 'if' ? 'branch' : node.name.toLowerCase()); | ||
switch (node.name) { | ||
switch (node.name.toLowerCase()) { | ||
case 'if': | ||
@@ -152,2 +152,10 @@ return namespace + 'branch( ' + printFuncs(node.args) + ' )'; | ||
case 'variable': | ||
if (precedents && !suppress) { | ||
precedents.push(node); | ||
} | ||
if (node.scope) { | ||
return 'context.get(\"' + node.scope + '\", \"' + node.name + '\")'; | ||
} | ||
return 'context.get(\"' + node.name + '\")'; | ||
case 'value': | ||
@@ -159,10 +167,3 @@ switch (node.subtype) { | ||
return "'" + node.value.replace(/'/g, "''") + "'"; | ||
case 'variable': | ||
if (precedents && !suppress) { | ||
precedents.push(node); | ||
} | ||
return 'context.get(\"' + node.value + '\")'; | ||
default: | ||
@@ -206,4 +207,5 @@ return node.value; | ||
if (locals.get !== 'function') { | ||
locals.get = function (propName) { | ||
return locals[propName]; | ||
locals.get = function (scope, name) { | ||
if (!name) return locals[scope]; | ||
return locals[scope] ? locals[scope][name] : undefined; | ||
}; | ||
@@ -210,0 +212,0 @@ } |
@@ -75,8 +75,8 @@ /* parser generated by jison 0.4.17 */ | ||
var parser = (function(){ | ||
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,4],$V1=[1,5],$V2=[1,6],$V3=[1,7],$V4=[1,10],$V5=[1,11],$V6=[1,12],$V7=[1,13],$V8=[1,14],$V9=[1,15],$Va=[1,23],$Vb=[1,17],$Vc=[1,18],$Vd=[1,19],$Ve=[1,20],$Vf=[1,21],$Vg=[1,22],$Vh=[1,24],$Vi=[1,25],$Vj=[1,26],$Vk=[1,27],$Vl=[1,28],$Vm=[1,29],$Vn=[5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,31,32,35],$Vo=[5,6,7,8,12,13,14,15,16,17,19,31,32,35],$Vp=[1,56],$Vq=[1,57],$Vr=[19,31,32,35],$Vs=[5,6,7,8,9,10,12,13,14,15,16,17,19,31,32,35],$Vt=[5,6,12,13,14,15,16,19,31,32,35]; | ||
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,4],$V1=[1,5],$V2=[1,6],$V3=[1,7],$V4=[1,8],$V5=[1,11],$V6=[1,12],$V7=[1,13],$V8=[1,14],$V9=[1,15],$Va=[1,16],$Vb=[1,24],$Vc=[1,18],$Vd=[1,19],$Ve=[1,20],$Vf=[1,21],$Vg=[1,22],$Vh=[1,23],$Vi=[1,25],$Vj=[1,26],$Vk=[1,27],$Vl=[1,28],$Vm=[1,29],$Vn=[1,30],$Vo=[5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,32,33,36],$Vp=[5,6,7,8,12,13,14,15,16,17,19,32,33,36],$Vq=[1,58],$Vr=[1,59],$Vs=[19,32,33,36],$Vt=[5,6,7,8,9,10,12,13,14,15,16,17,19,32,33,36],$Vu=[5,6,12,13,14,15,16,19,32,33,36]; | ||
var parser = {trace: function trace() { }, | ||
yy: {}, | ||
symbols_: {"error":2,"expressions":3,"e":4,"EOF":5,"=":6,"+":7,"-":8,"*":9,"/":10,"^":11,"<>":12,">":13,"<":14,">=":15,"<=":16,"&":17,"(":18,")":19,":":20,"IDENT":21,"func":22,"array_literal":23,"TRUE":24,"FALSE":25,"STRING":26,"NUMBER":27,"%":28,"range":29,"param_list":30,",":31,";":32,"FUNC":33,"{":34,"}":35,"$accept":0,"$end":1}, | ||
terminals_: {2:"error",5:"EOF",6:"=",7:"+",8:"-",9:"*",10:"/",11:"^",12:"<>",13:">",14:"<",15:">=",16:"<=",17:"&",18:"(",19:")",20:":",21:"IDENT",24:"TRUE",25:"FALSE",26:"STRING",27:"NUMBER",28:"%",31:",",32:";",33:"FUNC",34:"{",35:"}"}, | ||
productions_: [0,[3,2],[3,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,2],[4,3],[4,2],[4,3],[4,3],[4,1],[4,1],[4,1],[4,1],[4,1],[4,1],[4,2],[4,1],[29,3],[30,1],[30,3],[30,3],[22,4],[22,3],[23,3]], | ||
symbols_: {"error":2,"expressions":3,"e":4,"EOF":5,"=":6,"+":7,"-":8,"*":9,"/":10,"^":11,"<>":12,">":13,"<":14,">=":15,"<=":16,"&":17,"(":18,")":19,":":20,"IDENT":21,"SCOPE":22,"func":23,"array_literal":24,"TRUE":25,"FALSE":26,"STRING":27,"NUMBER":28,"%":29,"range":30,"param_list":31,",":32,";":33,"FUNC":34,"{":35,"}":36,"$accept":0,"$end":1}, | ||
terminals_: {2:"error",5:"EOF",6:"=",7:"+",8:"-",9:"*",10:"/",11:"^",12:"<>",13:">",14:"<",15:">=",16:"<=",17:"&",18:"(",19:")",20:":",21:"IDENT",22:"SCOPE",25:"TRUE",26:"FALSE",27:"STRING",28:"NUMBER",29:"%",32:",",33:";",34:"FUNC",35:"{",36:"}"}, | ||
productions_: [0,[3,2],[3,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,2],[4,3],[4,2],[4,3],[4,3],[4,1],[4,2],[4,1],[4,1],[4,1],[4,1],[4,1],[4,2],[4,1],[30,3],[31,1],[31,3],[31,3],[23,4],[23,3],[24,3]], | ||
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) { | ||
@@ -139,38 +139,41 @@ /* this == yyval */ | ||
case 19: | ||
this.$ = { type: 'value', subtype: 'variable', value:$$[$0] }; | ||
this.$ = { type: 'variable', name:$$[$0] }; | ||
break; | ||
case 20: case 21: | ||
case 20: | ||
this.$ = { type: 'variable', scope: $$[$0-1], name: $$[$0] }; | ||
break; | ||
case 21: case 22: | ||
this.$ = $$[$0]; | ||
break; | ||
case 22: | ||
case 23: | ||
this.$ = { type: 'value', subtype: 'boolean', value: true }; | ||
break; | ||
case 23: | ||
case 24: | ||
this.$ = { type: 'value', subtype: 'boolean', value: false }; | ||
break; | ||
case 24: | ||
case 25: | ||
this.$ = { type: 'value', subtype: 'string', value:String(yytext)}; | ||
break; | ||
case 25: | ||
case 26: | ||
this.$ = { type: 'value', subtype: 'number', value:$$[$0-1]/100 }; | ||
break; | ||
case 26: | ||
case 27: | ||
this.$ = { type: 'value', subtype: 'number', value:Number(yytext) }; | ||
break; | ||
case 28: | ||
case 29: | ||
this.$ = [$$[$0]]; | ||
break; | ||
case 29: | ||
case 30: | ||
this.$ = $$[$0-2].concat([$$[$0]]); | ||
break; | ||
case 30: | ||
case 31: | ||
this.$ = ($$[$0][0].subtype !== 'array') ? [{ type: 'value', subtype: 'array', items:$$[$0-2] }, { type: 'value', subtype: 'array', items:$$[$0] }] : [{ type: 'value', subtype: 'array', items:$$[$0-2] }].concat($$[$0]); | ||
break; | ||
case 31: | ||
case 32: | ||
this.$ = { type: 'function', name: $$[$0-3], args:$$[$0-1] }; | ||
break; | ||
case 32: | ||
case 33: | ||
this.$ = { type: 'function', name: $$[$0-2], args:[] }; | ||
break; | ||
case 33: | ||
case 34: | ||
this.$ = { type: 'value', subtype: 'array', items:$$[$0-1] }; | ||
@@ -180,4 +183,4 @@ break; | ||
}, | ||
table: [{3:1,4:2,6:[1,3],7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{1:[3]},{5:[1,16],6:$Va,7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,12:$Vg,13:$Vh,14:$Vi,15:$Vj,16:$Vk,17:$Vl,20:$Vm},{4:30,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:31,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:32,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:33,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},o($Vn,[2,19]),o($Vn,[2,20]),o($Vn,[2,21]),o($Vn,[2,22]),o($Vn,[2,23]),o($Vn,[2,24]),o($Vn,[2,26],{28:[1,34]}),{18:[1,35]},{4:37,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,30:36,33:$V8,34:$V9},{1:[2,1]},{4:38,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:39,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:40,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:41,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:42,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:43,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:44,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:45,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:46,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:47,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:48,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:49,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:50,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{5:[1,51],6:$Va,7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,12:$Vg,13:$Vh,14:$Vi,15:$Vj,16:$Vk,17:$Vl,20:$Vm},o($Vo,[2,14],{9:$Vd,10:$Ve,11:$Vf,20:$Vm}),o($Vo,[2,16],{9:$Vd,10:$Ve,11:$Vf,20:$Vm}),{6:$Va,7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,12:$Vg,13:$Vh,14:$Vi,15:$Vj,16:$Vk,17:$Vl,19:[1,52],20:$Vm},o($Vn,[2,25]),{4:37,7:$V0,8:$V1,18:$V2,19:[1,54],21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,30:53,33:$V8,34:$V9},{31:$Vp,32:$Vq,35:[1,55]},o($Vr,[2,28],{6:$Va,7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,12:$Vg,13:$Vh,14:$Vi,15:$Vj,16:$Vk,17:$Vl,20:$Vm}),o($Vo,[2,3],{9:$Vd,10:$Ve,11:$Vf,20:$Vm}),o($Vo,[2,4],{9:$Vd,10:$Ve,11:$Vf,20:$Vm}),o($Vs,[2,5],{11:$Vf,20:$Vm}),o($Vs,[2,6],{11:$Vf,20:$Vm}),o([5,6,7,8,9,10,11,12,13,14,15,16,17,19,31,32,35],[2,7],{20:$Vm}),o($Vt,[2,8],{7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,17:$Vl,20:$Vm}),o($Vt,[2,9],{7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,17:$Vl,20:$Vm}),o($Vt,[2,10],{7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,17:$Vl,20:$Vm}),o($Vt,[2,11],{7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,17:$Vl,20:$Vm}),o($Vt,[2,12],{7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,17:$Vl,20:$Vm}),o($Vt,[2,13],{7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,17:$Vl,20:$Vm}),o([5,6,12,13,14,15,16,17,19,31,32,35],[2,15],{7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,20:$Vm}),o($Vn,[2,18]),{1:[2,2]},o($Vn,[2,17]),{19:[1,58],31:$Vp,32:$Vq},o($Vn,[2,32]),o($Vn,[2,33]),{4:59,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,33:$V8,34:$V9},{4:37,7:$V0,8:$V1,18:$V2,21:$V3,22:8,23:9,24:$V4,25:$V5,26:$V6,27:$V7,30:60,33:$V8,34:$V9},o($Vn,[2,31]),o($Vr,[2,29],{6:$Va,7:$Vb,8:$Vc,9:$Vd,10:$Ve,11:$Vf,12:$Vg,13:$Vh,14:$Vi,15:$Vj,16:$Vk,17:$Vl,20:$Vm}),o([19,35],[2,30],{31:$Vp,32:$Vq})], | ||
defaultActions: {16:[2,1],51:[2,2]}, | ||
table: [{3:1,4:2,6:[1,3],7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{1:[3]},{5:[1,17],6:$Vb,7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,12:$Vh,13:$Vi,14:$Vj,15:$Vk,16:$Vl,17:$Vm,20:$Vn},{4:31,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:32,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:33,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:34,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},o($Vo,[2,19]),{21:[1,35]},o($Vo,[2,21]),o($Vo,[2,22]),o($Vo,[2,23]),o($Vo,[2,24]),o($Vo,[2,25]),o($Vo,[2,27],{29:[1,36]}),{18:[1,37]},{4:39,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,31:38,34:$V9,35:$Va},{1:[2,1]},{4:40,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:41,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:42,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:43,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:44,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:45,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:46,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:47,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:48,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:49,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:50,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:51,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:52,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{5:[1,53],6:$Vb,7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,12:$Vh,13:$Vi,14:$Vj,15:$Vk,16:$Vl,17:$Vm,20:$Vn},o($Vp,[2,14],{9:$Ve,10:$Vf,11:$Vg,20:$Vn}),o($Vp,[2,16],{9:$Ve,10:$Vf,11:$Vg,20:$Vn}),{6:$Vb,7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,12:$Vh,13:$Vi,14:$Vj,15:$Vk,16:$Vl,17:$Vm,19:[1,54],20:$Vn},o($Vo,[2,20]),o($Vo,[2,26]),{4:39,7:$V0,8:$V1,18:$V2,19:[1,56],21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,31:55,34:$V9,35:$Va},{32:$Vq,33:$Vr,36:[1,57]},o($Vs,[2,29],{6:$Vb,7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,12:$Vh,13:$Vi,14:$Vj,15:$Vk,16:$Vl,17:$Vm,20:$Vn}),o($Vp,[2,3],{9:$Ve,10:$Vf,11:$Vg,20:$Vn}),o($Vp,[2,4],{9:$Ve,10:$Vf,11:$Vg,20:$Vn}),o($Vt,[2,5],{11:$Vg,20:$Vn}),o($Vt,[2,6],{11:$Vg,20:$Vn}),o([5,6,7,8,9,10,11,12,13,14,15,16,17,19,32,33,36],[2,7],{20:$Vn}),o($Vu,[2,8],{7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,17:$Vm,20:$Vn}),o($Vu,[2,9],{7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,17:$Vm,20:$Vn}),o($Vu,[2,10],{7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,17:$Vm,20:$Vn}),o($Vu,[2,11],{7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,17:$Vm,20:$Vn}),o($Vu,[2,12],{7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,17:$Vm,20:$Vn}),o($Vu,[2,13],{7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,17:$Vm,20:$Vn}),o([5,6,12,13,14,15,16,17,19,32,33,36],[2,15],{7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,20:$Vn}),o($Vo,[2,18]),{1:[2,2]},o($Vo,[2,17]),{19:[1,60],32:$Vq,33:$Vr},o($Vo,[2,33]),o($Vo,[2,34]),{4:61,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,34:$V9,35:$Va},{4:39,7:$V0,8:$V1,18:$V2,21:$V3,22:$V4,23:9,24:10,25:$V5,26:$V6,27:$V7,28:$V8,31:62,34:$V9,35:$Va},o($Vo,[2,32]),o($Vs,[2,30],{6:$Vb,7:$Vc,8:$Vd,9:$Ve,10:$Vf,11:$Vg,12:$Vh,13:$Vi,14:$Vj,15:$Vk,16:$Vl,17:$Vm,20:$Vn}),o([19,36],[2,31],{32:$Vq,33:$Vr})], | ||
defaultActions: {17:[2,1],53:[2,2]}, | ||
parseError: function parseError(str, hash) { | ||
@@ -663,15 +666,15 @@ if (hash.recoverable) { | ||
break; | ||
case 1:return 27 | ||
case 1:return 28 | ||
break; | ||
case 2:return 24 | ||
case 2:return 25 | ||
break; | ||
case 3:return 25 | ||
case 3:return 26 | ||
break; | ||
case 4:return 24 | ||
case 4:return 25 | ||
break; | ||
case 5:return 25 | ||
case 5:return 26 | ||
break; | ||
case 6:return 24 | ||
case 6:return 25 | ||
break; | ||
case 7:return 25 | ||
case 7:return 26 | ||
break; | ||
@@ -720,18 +723,26 @@ case 8:return 9 | ||
break; | ||
case 29:return 33; | ||
case 29:return 34; | ||
break; | ||
case 30:return 33; | ||
case 30:return 34; | ||
break; | ||
case 31:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\"\"/g, "\""); return "STRING"; | ||
break; | ||
case 32:return 21 | ||
case 32:yy_.yytext = yy_.yytext.substr(2,yy_.yyleng-3).replace(/\"\"/g, "\""); return "SCOPE"; | ||
break; | ||
case 33:return 5 | ||
case 33:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-3).replace(/\"\"/g, "\""); return "SCOPE"; | ||
break; | ||
case 34:return 'INVALID' | ||
case 34:yy_.yytext = yy_.yytext.slice(0, -1); return "SCOPE" | ||
break; | ||
case 35:yy_.yytext = yy_.yytext.slice(1, -1); return "SCOPE" | ||
break; | ||
case 36:return 21 | ||
break; | ||
case 37:return 5 | ||
break; | ||
case 38:return 'INVALID' | ||
break; | ||
} | ||
}, | ||
rules: [/^(?:\s+)/,/^(?:[0-9]+(\.[0-9]+)?\b)/,/^(?:TRUE\b)/,/^(?:FALSE\b)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:True\b)/,/^(?:False\b)/,/^(?:\*)/,/^(?:\/)/,/^(?:-)/,/^(?:\+)/,/^(?:&)/,/^(?:\^)/,/^(?:\()/,/^(?:\))/,/^(?:>=)/,/^(?:<=)/,/^(?:<>)/,/^(?:=)/,/^(?:>)/,/^(?:<)/,/^(?:\{)/,/^(?:\})/,/^(?:!)/,/^(?:,)/,/^(?::)/,/^(?:;)/,/^(?:%)/,/^(?:[A-Za-z](?=[(]))/,/^(?:[A-Za-z][A-Za-z0-9\.]+(?=[(]))/,/^(?:"(?:""|[^"])*")/,/^(?:([\[\]a-zA-Z0-9.$^\!@\(]+))/,/^(?:$)/,/^(?:.)/], | ||
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],"inclusive":true}} | ||
rules: [/^(?:\s+)/,/^(?:[0-9]+(\.[0-9]+)?\b)/,/^(?:TRUE\b)/,/^(?:FALSE\b)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:True\b)/,/^(?:False\b)/,/^(?:\*)/,/^(?:\/)/,/^(?:-)/,/^(?:\+)/,/^(?:&)/,/^(?:\^)/,/^(?:\()/,/^(?:\))/,/^(?:>=)/,/^(?:<=)/,/^(?:<>)/,/^(?:=)/,/^(?:>)/,/^(?:<)/,/^(?:\{)/,/^(?:\})/,/^(?:!)/,/^(?:,)/,/^(?::)/,/^(?:;)/,/^(?:%)/,/^(?:[A-Za-z](?=[(]))/,/^(?:[A-Za-z][A-Za-z0-9\.]+(?=[(]))/,/^(?:"(?:""|[^"])*")/,/^(?:\$'(?:''|[^'])*'!)/,/^(?:'(?:''|[^'])*'!)/,/^(?:[a-zA-Z]([a-zA-Z0-9_.$]+)?!)/,/^(?:\$([a-zA-Z])([a-zA-Z0-9_.$]+)?!)/,/^(?:([\[\]a-zA-Z0-9_.$^@\(]+))/,/^(?:$)/,/^(?:.)/], | ||
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"inclusive":true}} | ||
}); | ||
@@ -738,0 +749,0 @@ return lexer; |
{ | ||
"name": "formula", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"description": "Formula runtime for JavaScript.", | ||
@@ -28,3 +28,3 @@ "main": "lib/compiler.js", | ||
"dependencies": { | ||
"functionfoundry": "^0.11.0" | ||
"functionfoundry": "^0.12.1" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
@@ -5,3 +5,3 @@ # formula | ||
Formula language for Node.js and Browser. See [docs](./Formulas.org) for language syntax. | ||
Formula language for Node.js and Browser, modeled after spreadsheets. | ||
@@ -8,0 +8,0 @@ ## Install |
@@ -99,3 +99,3 @@ // Copyright 2015 Peter W Moresi | ||
requires.push(node.name.toLowerCase() === 'if' ? 'branch' : node.name.toLowerCase()); | ||
switch(node.name) { | ||
switch(node.name.toLowerCase()) { | ||
case 'if': | ||
@@ -133,2 +133,8 @@ return (namespace + 'branch( ' + printFuncs(node.args) + ' )'); | ||
case 'variable': | ||
if (precedents && !suppress) { precedents.push(node); } | ||
if (node.scope) { | ||
return 'context.get(\"' + node.scope + '\", \"' + node.name + '\")'; | ||
} | ||
return 'context.get(\"' + node.name + '\")'; | ||
case 'value': | ||
@@ -140,8 +146,3 @@ switch (node.subtype) { | ||
return "'" + node.value.replace(/'/g, "''") + "'"; | ||
case 'variable': | ||
if (precedents && !suppress) { precedents.push(node); } | ||
return 'context.get(\"' + node.value + '\")'; | ||
default: | ||
@@ -189,3 +190,6 @@ return node.value; | ||
if (locals.get !== 'function') { | ||
locals.get = (propName) => locals[propName] | ||
locals.get = (scope, name) => { | ||
if (!name) return locals[scope] | ||
return locals[scope] ? locals[scope][name] : undefined | ||
} | ||
} | ||
@@ -192,0 +196,0 @@ |
@@ -5,3 +5,3 @@ var test = require('tape') | ||
test('run should pass basic tests', function(t) { | ||
test('basic tests', function(t) { | ||
@@ -14,3 +14,3 @@ t.plan(8) | ||
t.equal( run('a<>b', { a: 1, b: 1 }), false ) | ||
t.equal( run('a!1<>b', { 'a!1': 1, b: 1 }), false ) | ||
t.equal( run('a!b1<>b', { 'a': { b1: 1 }, b: 1 }), false ) | ||
t.equal( run('Tran55Fee<>b', { 'Tran55Fee': 1, b: 1 }), false ) | ||
@@ -21,11 +21,16 @@ t.equal( run('@Tran55Fee<>b', { '@Tran55Fee': 1, b: 1 }), false ) | ||
test('running functions should work', function(t) { | ||
test('functions should work', function(t) { | ||
t.plan(2) | ||
t.plan(5) | ||
t.equal( run('NUMBERVALUE("2")'), 2 ) | ||
t.equal( run('numbervalue("2,000,000.00")'), 2000000 ) | ||
// all variations of IF should work | ||
t.equal( run('IF(6, 2)'), 2 ) | ||
t.equal( run('If(6, 2)'), 2 ) | ||
t.equal( run('if(6, 2)'), 2 ) | ||
}) | ||
test('run complex nesting should work', function(t) { | ||
test('complex nesting should work', function(t) { | ||
t.plan(1) | ||
@@ -40,1 +45,13 @@ t.equal(run('2+2=((2-2+2)+(3-1))'), true) | ||
}) | ||
test('variable names can include underscore', function(t) { | ||
t.plan(1) | ||
t.equal( run('a_1=b_1', { a_1: 1, b_1: 1 }), true ) | ||
}) | ||
test('scope/sheet names should be supported', function(t) { | ||
t.plan(3) | ||
t.equal( run('abc!xyz', { abc: { xyz: 1 } }), 1 ) | ||
t.equal( run('abc_def!xyz', { abc_def: { xyz: 1 } }), 1 ) | ||
t.equal( run("'abc_def'!xyz", { abc_def: { xyz: 1 } }), 1 ) | ||
}) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
500435
9833
+ Addedfunctionfoundry@0.12.7(transitive)
- Removedfunctionfoundry@0.11.2(transitive)
Updatedfunctionfoundry@^0.12.1