Haskell highlighting in Sublime 2/3 is not very good, so I just went to fix some of the stuff. You can find a file with some pathological examples at the end of this post, just paste it in Sublime and see what it looks like. Note that there are some of the class “it’s a bug unless you can disable it” in in the list, just ignore those if you like them. A very brief description on how to fix the bug is also included, just edit your Haskell.tmLanguage file accordingly.
Fixed:
-
Comments in module declarations
-
Comments in imports
-
“import” or “module” inside an identifier doesn’t break the whole layout anymore
-
Multiline strings aren’t allowed in Haskell, but Sublime highlighted them as if they were (C-style)
Not fixed yet:
-
Multiple type constraints for one function
-
Multiline type declarations
Ideas on how to fix the remaining bugs are welcome.
[code]-- Sublime text Haskell highlighting issues
– Comments in module declarations don’t render properly
– Fix: Add the following after the dict block containing “I don’t know”
–
– include
– #comments
–
module Main (
foo, – This doesn’t render as a comment
bar
) where – Works
– Comments after imports don’t work
– Fix: Add the following after the #module_exports dict element:
–
– include
– #comments
–
import Data.List – Comment
import Data.Maybe {- Comment -}
– Class constraints are highlighted differently when they’re parenthesized
– Fix: Change
– (\s*([A-Z][A-Za-z])\s+([a-z][A-Za-z_’]))\s*(=>)
– to
– (?x) # x turns off whitespaces. This block matches a single constraint. Fix?
– (\s*[A-Z][A-Za-z])\s+([a-z][A-Za-z_’])\s*(=>) # Non-parenthesized expression
– |
– (\s*([A-Z][A-Za-z])\s+([a-z][A-Za-z_’]))\s*(=>) # Parenthesized expression
–
cc :: (Monad a) => a -> a
cc’ :: Monad a => a -> a
– Custom types in type declarations have the wrong color
bar :: MyType a -> String -> String
– Multiline type declarations render wrong
foo :: (Eq a) => MyType a -> String
-> String
– ‘module’ or ‘import’ in an identifier breaks highlighting.
– Fix: change “(module)” to “\b(module)\b”
moduleInName = “This should render as a string, but doesn’t.\n”
importInName = “This should render as a string, but doesn’t.\n”
– Strings over multiple lines have to be explicitly constructed using (++).
– Fix: Go to the string section and change
– end
– "
– to
– end
– $|"
baz = “You cannot write multiline
strings directly in Haskell,
but Sublime colors them like it.”
– Prelude names get special highlighting
– Fix: Comment out the dict block containing ‘length’ and ‘IO(Error)?’
qux :: IO Int -> Maybe Int
qux = length [1…10][/code]