Skip to content

Commit

Permalink
examples/issue-254.jison now compiles and passes OK; another bit of w…
Browse files Browse the repository at this point in the history
…ork on zaach#254. Now this stuff should be documented... Not at 3AM though.
  • Loading branch information
GerHobbelt committed Oct 26, 2015
1 parent 6b1a91b commit 8330405
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

all: build test examples/issue-293
# examples/issue-254
all: build test examples/issue-293 examples/issue-254

prep: npm-install

Expand Down
48 changes: 33 additions & 15 deletions examples/issue-254.jison
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,44 @@

/lex

%start function_call
%start test

%%

test
: function_call
{
//console.log("result: ", $function_call);
return $function_call;
}
;


function_call
: IDENTIFIER ("(" (expression[e1] ("," expression[e2])* )? ")")
{
console.log($1);
console.log($3);
console.log($e1);
$$ = $IDENTIFIER + ':' + $e1;
try {
if ($5) {
console.log($5);
}
if ($e2) {
console.log($e2);
}
$$ += ':' + $e2;
} catch (e) {
console.log("exception");
}
// unreachable; injected a dot to prevent the action inspector from still seeing this one:
//console.log($.e1);
//$$ = $IDENTIFIER + ':' + $.e1;
//try {
// if ($.5) {
// console.log($.5);
// }
// if ($.e2) {
// console.log($.e2);
// }
// $$ += ':' + $.e2;
//} catch (e) {
// console.log("exception");
//}
// new code:
//
// IDENTIFIER "(" q_container ")"
// 1 2 3 4
$$ = $IDENTIFIER + ':' + $2 + JSON.stringify($3) + $4;
}
;

Expand Down Expand Up @@ -63,10 +79,12 @@ var assert = require("assert");
parser.main = function () {
var rv = parser.parse("a(b, c)");
console.log("a(b, c) ==> ", rv);
assert.equal(rv, "a:([\"b\",[[\",\",\"c\"]]])");
var rv = parser.parse("a(b)");
console.log("a(b) ==> ", rv);
assert.equal(rv, "a:([\"b\",[]])");
assert.equal(rv, "a(a(a))");
// if you get past the assert(), you're good.
console.log("tested OK");
Expand Down

0 comments on commit 8330405

Please sign in to comment.