BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
587 stars 165 forks source link

Pygments backend is generating regex with unescaped symbol #477

Open praduca opened 8 months ago

praduca commented 8 months ago

I have a grammar (a basic language) that have ^ as an operator. The generated code for the operators on the pygments code include this symbol unescaped, and the generated highlighter is locking at 100% cpu usage because of this. Escaping the symbol solves the lock.

Other symbols are being correctly escaped, it appears that is only ^ that is not being escaped.

andreasabel commented 8 months ago

Should ^ be added here then? https://github.com/BNFC/bnfc/blob/28a41fc746f509c36bba89acbcc7f9b4dfa3f489/source/src/BNFC/Backend/Pygments.hs#L160

We need a self-contained reproducer (that will go into the testsuite) if we want to fix this.

praduca commented 8 months ago

Can calc.cf be expanded and used? something like this

EAdd.      Exp  ::= Exp  "+" Exp1 ;
ESub.      Exp  ::= Exp  "-" Exp1 ;
EMul.      Exp1 ::= Exp1 "*" Exp2 ;
EDiv.      Exp1 ::= Exp1 "/" Exp2 ;
EPow.      Exp2 ::= Exp2 "^" Exp3; 
EInt.      Exp3 ::= Integer       ;
coercions  Exp  3