Skip to content

Commit

Permalink
[ #249 Java ] fixed lexer regression introduced by #257 / #276
Browse files Browse the repository at this point in the history
Don't use showLitChar for unicode characters!

b8701c3 broke #249 for Java/ANTLR in the lexer,
c49d1fd for Java/CUP.
  • Loading branch information
andreasabel committed Jan 19, 2020
1 parent 30260b7 commit 3745b86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions source/src/BNFC/Backend/Java/RegToAntlrLexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
8 changes: 5 additions & 3 deletions source/src/BNFC/Backend/Java/RegToJLex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..))

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 3745b86

Please sign in to comment.