Add parser support for block params

This commit is contained in:
Martin Muñoz
2014-11-11 21:35:10 -05:00
parent b3b5b35889
commit b8a9f7264d
9 changed files with 51 additions and 12 deletions
+2 -1
View File
@@ -9,10 +9,11 @@ function LocationInfo(locInfo) {
}
var AST = {
ProgramNode: function(statements, strip, locInfo) {
ProgramNode: function(statements, blockParams, strip, locInfo) {
LocationInfo.call(this, locInfo);
this.type = "program";
this.statements = statements;
this.blockParams = blockParams;
this.strip = strip;
},
+3 -1
View File
@@ -23,7 +23,7 @@ export function prepareRawBlock(openRawBlock, content, close, locInfo) {
throw new Exception(openRawBlock.sexpr.id.original + " doesn't match " + close, errorNode);
}
var program = new this.ProgramNode([content], {}, locInfo);
var program = new this.ProgramNode([content], null, {}, locInfo);
return new this.BlockNode(openRawBlock.sexpr, program, undefined, undefined, locInfo);
}
@@ -40,6 +40,8 @@ export function prepareBlock(openBlock, program, inverseAndProgram, close, inver
throw new Exception(openBlock.sexpr.id.original + ' doesn\'t match ' + close.path.original, errorNode);
}
program.blockParams = openBlock.blockParams;
// Safely handle a chained inverse that does not have a non-conditional inverse
// (i.e. both inverseAndProgram AND close are undefined)
if (!close) {
+9
View File
@@ -26,6 +26,15 @@ PrintVisitor.prototype.program = function(program) {
statements = program.statements,
i, l;
if (program.blockParams) {
var blockParams = "BLOCK PARAMS: [";
for(i=0, l=program.blockParams.length; i<l; i++) {
blockParams += " " + program.blockParams[i];
}
blockParams += " ]";
out += this.pad(blockParams);
}
for(i=0, l=statements.length; i<l; i++) {
out = out + this.accept(statements[i]);
}