bnfc icon indicating copy to clipboard operation
bnfc copied to clipboard

Pygments backend is generating regex with unescaped symbol

Open praduca opened this issue 1 year ago • 2 comments

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.

praduca avatar Mar 19 '24 17:03 praduca

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.

andreasabel avatar Mar 20 '24 07:03 andreasabel

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             

praduca avatar Mar 30 '24 03:03 praduca