Skip to content

Commit

Permalink
added example/test code for issue zaach#387
Browse files Browse the repository at this point in the history
  • Loading branch information
GerHobbelt committed Sep 25, 2019
1 parent 26f84ca commit d8153dc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
8 changes: 7 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ GITHUB_ISSUE_TARGETS = \
issue-348 \
issue-357-url-lexing \
issue-360 \
issue-362
issue-362 \
issue-387


CODEGEN_TARGETS = \
Expand Down Expand Up @@ -416,6 +417,11 @@ issue-360:
# build *AND* run the test:
issue-362: documentation--custom-lexer-ULcase documentation--custom-lexer-ULcase-alt

# build *AND* run the test:
issue-387:
$(JISON) --main ./$@.jison
$(NODE) ./output/$@/$@.js

jscore:
$(JISON) --main ./$@.jison

Expand Down
48 changes: 48 additions & 0 deletions examples/issue-387.jison
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* lexical grammar */
%lex
%%

\s+ /* skip whitespace */
"constructor" return 'constructor'
<<EOF>> return 'EOF'
. return 'INVALID'

/lex

/* operator associations and precedence */

%start expressions

%% /* language grammar */

expressions
: "constructor" EOF
{return "constructor";}
;


%%
// feature of the GH fork: specify your own main.
//
// compile with
//
// jison -o test.js --main that/will/be/me.jison
//
// then run
//
// node ./test.js
//
// to see the output.
var assert = require("assert");
parser.main = function () {
var rv = parser.parse('constructor');
console.log("test #1: 'constructor' ==> ", rv, parser.yy);
assert.equal(rv, 'constructor');
// if you get past the assert(), you're good.
console.log("tested OK");
};

0 comments on commit d8153dc

Please sign in to comment.