diff --git a/source/src/BNFC/Backend/Java/RegToAntlrLexer.hs b/source/src/BNFC/Backend/Java/RegToAntlrLexer.hs index 39b178ae..6cbe1105 100644 --- a/source/src/BNFC/Backend/Java/RegToAntlrLexer.hs +++ b/source/src/BNFC/Backend/Java/RegToAntlrLexer.hs @@ -2,7 +2,7 @@ module BNFC.Backend.Java.RegToAntlrLexer (printRegJLex, escapeChar) where -- modified from RegToJLex.hs -import Data.Char (showLitChar) +import Data.Char (ord, showLitChar) import AbsBNF @@ -42,8 +42,10 @@ instance Print Char where prtList = map (concat . prt 0) escapeChar :: Char -> String -escapeChar x | x `elem` reserved = '\\' : [x] -escapeChar x = showLitChar x "" +escapeChar x + | x `elem` reserved = '\\' : [x] + | ord x >= 256 = [x] + | otherwise = showLitChar x "" -- Characters that must be escaped in ANTLR regular expressions reserved :: [Char] diff --git a/source/src/BNFC/Backend/Java/RegToJLex.hs b/source/src/BNFC/Backend/Java/RegToJLex.hs index b12d3098..ca8d29a5 100644 --- a/source/src/BNFC/Backend/Java/RegToJLex.hs +++ b/source/src/BNFC/Backend/Java/RegToJLex.hs @@ -2,7 +2,7 @@ module BNFC.Backend.Java.RegToJLex (printRegJLex, escapeChar) where -- modified from pretty-printer generated by the BNF converter -import Data.Char (showLitChar) +import Data.Char (ord, showLitChar) import AbsBNF import BNFC.Options (JavaLexerParser(..)) @@ -44,8 +44,10 @@ instance Print Char where escapeChar :: JavaLexerParser -> Char -> String escapeChar _ '^' = "\\x5E" -- special case, since \^ is a control character escape escapeChar JFlexCup x | x `elem` jflexReserved = '\\' : [x] -escapeChar _ x | x `elem` jlexReserved = '\\' : [x] -escapeChar _ x = showLitChar x "" +escapeChar _ x + | x `elem` jlexReserved = '\\' : [x] + | ord x >= 255 = [x] + | otherwise = showLitChar x "" -- Characters that must be escaped in JLex regular expressions jlexReserved :: [Char]