Skip to content

Commit

Permalink
adding JISON test cases as provided by zaach/jison-lex#23 (with a min…
Browse files Browse the repository at this point in the history
…or tweak to test/showcase `e + e` action code expansion with named variables: `$e1 + $e2` instead of the more cryptic (old-skool yacc style action code) `$1 + $3`
  • Loading branch information
GerHobbelt committed Dec 13, 2017
1 parent 5cb5cd4 commit 2c2f82c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/issue-lex-23-good.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// title: Parse error when using arrow function in rules
//
// ...
//
// This is the SUCCESSFUL lexer spec
//

let grammar = {
lex: {
rules: [
['\\s+', ''],
['\\d+', function () { return 'NUMBER'}],
['\\+', function () { return '+' }],
['$', function () { return 'EOF' }],
]
},
operators: [
['left', '+']
],
bnf: {
'es': [
['e EOF', 'return $1']
],
'e': [
['e + e', '$$ = $e1 + $e2'],
['NUMBER', '$$ = Number(yytext)']
]
}
};

module.exports = grammar;
// export default grammar;

33 changes: 33 additions & 0 deletions examples/issue-lex-23-trouble.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// title: Parse error when using arrow function in rules
//
// ...
//
// This is the FAILING lexer spec
//

let grammar = {
lex: {
rules: [
['\\s+', ''],
['\\d+', () => 'NUMBER'],
['\\+', () => '+'],
['$', () => 'EOF'],
]
},
operators: [
['left', '+']
],
bnf: {
'es': [
['e EOF', 'return $1']
],
'e': [
['e + e', '$$ = $e1 + $e2'],
['NUMBER', '$$ = Number(yytext)']
]
}
};

module.exports = grammar;
// export default grammar;

0 comments on commit 2c2f82c

Please sign in to comment.