zaach / jison

Bison in JavaScript.
http://jison.org
4.35k stars 448 forks source link

Tests generate SyntaxError: Function statements require a function name #399

Open BurtHarris opened 3 years ago

BurtHarris commented 3 years ago

Running npm install and npm test seems to produce two error messages (in addition to conflict messages).

  testLR1
  test LR parse
        test basic JSON grammar
          ⚡ SyntaxError: Function statements require a function name
              at new RegExpLexer (C:\try\jison\node_modules\jison-lex\regexp-lexer.js:124:22)
              at o.constructor.Jison_Generator [as constructor] (C:\try\jison\lib\jison.js:111:22)        
              at o.constructor.<computed> [as constructor] (C:\try\jison\lib\util\typal.js:23:28)
              at new o.constructor (C:\try\jison\lib\util\typal.js:77:70)
              at Object.Jison_Generator [as Generator] (C:\try\jison\lib\jison.js:1902:20)
              at new Parser (C:\try\jison\lib\jison.js:1911:25)
              at exports.test basic JSON grammar (C:\try\jison\tests\parser\lr1.js:116:18)
              at test (C:\try\jison\node_modules\test\test.js:29:20)
              at next (C:\try\jison\node_modules\test\test.js:69:7)
              at Object.end (C:\try\jison\node_modules\test\test.js:25:7)
test module include
        ⚡ SyntaxError: Function statements require a function name
            at new RegExpLexer (C:\try\jison\node_modules\jison-lex\regexp-lexer.js:124:22)
            at o.constructor.Jison_Generator [as constructor] (C:\try\jison\lib\jison.js:111:22)        
            at o.constructor.<computed> [as constructor] (C:\try\jison\lib\util\typal.js:23:28)
            at new o.constructor (C:\try\jison\lib\util\typal.js:77:70)
            at new Jison_Generator (C:\try\jison\lib\jison.js:1906:20)
            at exports.test module include (C:\try\jison\tests\parser\generator.js:223:15)
            at test (C:\try\jison\node_modules\test\test.js:29:20)
            at next (C:\try\jison\node_modules\test\test.js:69:7)
            at Object.end (C:\try\jison\node_modules\test\test.js:25:7)
            at test (C:\try\jison\node_modules\test\test.js:41:28)

Environment

node v14.17.0 npm 7.13.0

BurtHarris commented 3 years ago

It looks like this is a duplicate of zaach/jison-lex#27 under Node versions greater than 10.

fraczak commented 1 year ago

I was able to fix it by changing regexp in jison-lex/regexp-lexer.js (line 57) to:

rules[i][1] = String(rules[i][1]).replace(/^(?:\s|\n)*function\s*\(\s*\)(?:\s|\n)*\{((.|\n)*)\}(?:\s|\n|;)*$/, '$1');