diff --git a/packages/jison-lex/dist/cli-cjs-es5.js b/packages/jison-lex/dist/cli-cjs-es5.js index 53673805c..7ad1c3444 100644 --- a/packages/jison-lex/dist/cli-cjs-es5.js +++ b/packages/jison-lex/dist/cli-cjs-es5.js @@ -7659,8 +7659,18 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts) newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement); diff --git a/packages/jison-lex/dist/cli-cjs.js b/packages/jison-lex/dist/cli-cjs.js index fa990b0b3..b7e3ca930 100644 --- a/packages/jison-lex/dist/cli-cjs.js +++ b/packages/jison-lex/dist/cli-cjs.js @@ -9969,8 +9969,18 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts) newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement); diff --git a/packages/jison-lex/dist/cli-es6.js b/packages/jison-lex/dist/cli-es6.js index 3750a31d9..c938ba00d 100644 --- a/packages/jison-lex/dist/cli-es6.js +++ b/packages/jison-lex/dist/cli-es6.js @@ -9965,8 +9965,18 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts) newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement); diff --git a/packages/jison-lex/dist/cli-umd-es5.js b/packages/jison-lex/dist/cli-umd-es5.js index a32933c28..e62a6317b 100644 --- a/packages/jison-lex/dist/cli-umd-es5.js +++ b/packages/jison-lex/dist/cli-umd-es5.js @@ -7660,8 +7660,18 @@ function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defi newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement); diff --git a/packages/jison-lex/dist/cli-umd.js b/packages/jison-lex/dist/cli-umd.js index 23b9ab95e..50690cc67 100644 --- a/packages/jison-lex/dist/cli-umd.js +++ b/packages/jison-lex/dist/cli-umd.js @@ -9971,8 +9971,18 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts) newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement); diff --git a/packages/jison-lex/dist/regexp-lexer-cjs-es5.js b/packages/jison-lex/dist/regexp-lexer-cjs-es5.js index f480d5cfb..8f076eb95 100644 --- a/packages/jison-lex/dist/regexp-lexer-cjs-es5.js +++ b/packages/jison-lex/dist/regexp-lexer-cjs-es5.js @@ -7655,8 +7655,18 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts) newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement); diff --git a/packages/jison-lex/dist/regexp-lexer-cjs.js b/packages/jison-lex/dist/regexp-lexer-cjs.js index 3f1ca6bf5..d5a77bd74 100644 --- a/packages/jison-lex/dist/regexp-lexer-cjs.js +++ b/packages/jison-lex/dist/regexp-lexer-cjs.js @@ -9965,8 +9965,18 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts) newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement); diff --git a/packages/jison-lex/dist/regexp-lexer-es6.js b/packages/jison-lex/dist/regexp-lexer-es6.js index 51ec17df7..89673c1d2 100644 --- a/packages/jison-lex/dist/regexp-lexer-es6.js +++ b/packages/jison-lex/dist/regexp-lexer-es6.js @@ -9961,8 +9961,18 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts) newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement); diff --git a/packages/jison-lex/dist/regexp-lexer-umd-es5.js b/packages/jison-lex/dist/regexp-lexer-umd-es5.js index ded55a297..be63af9e2 100644 --- a/packages/jison-lex/dist/regexp-lexer-umd-es5.js +++ b/packages/jison-lex/dist/regexp-lexer-umd-es5.js @@ -7656,8 +7656,18 @@ function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defi newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement); diff --git a/packages/jison-lex/dist/regexp-lexer-umd.js b/packages/jison-lex/dist/regexp-lexer-umd.js index 7ef057035..62d547742 100644 --- a/packages/jison-lex/dist/regexp-lexer-umd.js +++ b/packages/jison-lex/dist/regexp-lexer-umd.js @@ -9967,8 +9967,18 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts) newRules.push(m); action = rule[1]; if (typeof action === 'function') { - // TODO: also cope with Arrow Functions (and inline those as well?) -- see also https://github.com/zaach/jison-lex/issues/23 - action = String(action).replace(/^\s*function\s*\(\)\s?\{/, '').replace(/\}\s*$/, ''); + // Also cope with Arrow Functions (and inline those as well?). + // See also https://github.com/zaach/jison-lex/issues/23 + action = String(action); + if (action.match(/^\s*function\s*\(\)\s*\{/)) { + action = action.replace(/^\s*function\s*\(\)\s*\{/, '').replace(/\}\s*$/, ''); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*[^\s\r\n\{]/)) { + // () => 'TOKEN' --> return 'TOKEN' + action = action.replace(/^\s*\(\)\s*=>/, 'return '); + } else if (action.match(/^\s*\(\)\s*=>[\s\r\n]*\{/)) { + // () => { statements } --> statements (ergo: 'inline' the given function) + action = action.replace(/^\s*\(\)\s*=>[\s\r\n]*\{/, '').replace(/\}\s*$/, ''); + } } action = action.replace(/return\s*'((?:\\'|[^']+)+)'/g, tokenNumberReplacement); action = action.replace(/return\s*"((?:\\"|[^"]+)+)"/g, tokenNumberReplacement);