From 2c2f82ce010f04a5e44b3aca3f9cb95ff47e5986 Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Wed, 13 Dec 2017 02:24:21 +0100 Subject: [PATCH] adding JISON test cases as provided by https://github.com/zaach/jison-lex/issues/23 (with a minor 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` --- examples/issue-lex-23-good.js | 33 ++++++++++++++++++++++++++++++++ examples/issue-lex-23-trouble.js | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 examples/issue-lex-23-good.js create mode 100644 examples/issue-lex-23-trouble.js diff --git a/examples/issue-lex-23-good.js b/examples/issue-lex-23-good.js new file mode 100644 index 000000000..f8102f48c --- /dev/null +++ b/examples/issue-lex-23-good.js @@ -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; + diff --git a/examples/issue-lex-23-trouble.js b/examples/issue-lex-23-trouble.js new file mode 100644 index 000000000..19ee75610 --- /dev/null +++ b/examples/issue-lex-23-trouble.js @@ -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; +