jgm / skylighting

A Haskell syntax highlighting library with tokenizers derived from KDE syntax highlighting descriptions
189 stars 61 forks source link

Haskell highlighting is broken #120

Closed abhin4v closed 3 years ago

abhin4v commented 3 years ago

Haskell code highlighting with version 0.8.5:

image

Haskell code highlighting with version 0.10.4.1:

image

I suspect it has something to do with the way Haskell characters are detected.

Code snippet in the image for testing purpose:

jsonChar :: Parser String Char
jsonChar =   string "\\\"" $> '"'
         <|> string "\\\\" $> '\\'
         <|> string "\\/"  $> '/'
         <|> string "\\b"  $> '\b'
         <|> string "\\f"  $> '\f'
         <|> string "\\n"  $> '\n'
         <|> string "\\r"  $> '\r'
         <|> string "\\t"  $> '\t'
         <|> unicodeChar
         <|> satisfy (\c -> not (c == '\"' || c == '\\' || isControl c))
  where
    unicodeChar =
      chr . fromIntegral . digitsToNumber 16 0
        <$> (string "\\u" *> replicateM 4 hexDigit)

    hexDigit = digitToInt <$> satisfy isHexDigit

digitsToNumber :: Int -> Integer -> [Int] -> Integer
digitsToNumber base =
  foldl (\num d -> num * fromIntegral base + fromIntegral d)
jgm commented 3 years ago

Simpler case:

c = '"' -- this fails

Here the comment is parsed as a StringTok.

jgm commented 3 years ago

I see the problem. I made a mistake when reimplementing PR #40 (DetectChar instead of RegExpr). Should have a fix shortly.