Thanks a ton for this!! I was considering fixing this, because I need to work on a module that has a lot of uses of "module".
Probably would have been better to provide a diff.. Finding where to do those changes wasn't so trivial. Otherwise, great work! Some bugs I didn't know were there.
I fixed the multiline types by ending them on things that look like top level declarations, and fixed the constraints by removing special casing - constraints are near enough to types these days anyway. I hope some of these fixes make it to the main highlighter!
Finally, I added support for highlighting quasi-quotes as if they were multiline strings, and made $( parse as a keyword (even if the ending paren isn't opreatorized..)
- Code: Select all
---Haskell.tmLanguageOld
+++ Haskell.tmLanguage
@@ -47,7 +47,7 @@
</dict>
<dict>
<key>begin</key>
- <string>(module)</string>
+ <string>\b(module)\b</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
@@ -193,6 +193,10 @@
<key>include</key>
<string>#module_exports</string>
</dict>
+ <dict>
+ <key>include</key>
+ <string>#comments</string>
+ </dict>
</array>
</dict>
<dict>
@@ -284,7 +288,7 @@
</dict>
</dict>
<key>end</key>
- <string>"</string>
+ <string>$|"</string>
<key>endCaptures</key>
<dict>
<key>0</key>
@@ -314,6 +318,104 @@
<string>\^[A-Z@\[\]\\\^_]</string>
<key>name</key>
<string>constant.character.escape.control.haskell</string>
+ </dict>
+ </array>
+ </dict>
+ <dict>
+ <key>comment</key>
+ <dict>Points out splices in ast quotes</dict>
+ <key>begin</key>
+ <string>\[(?:|e|d|t|p)\|</string>
+ <key>beginCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>keyword.other.quasibracket.haskell</string>
+ </dict>
+ </dict>
+ <key>end</key>
+ <string>(.*)(\|\])</string>
+ <key>endCaptures</key>
+ <dict>
+ <key>1</key>
+ <dict>
+ <key>name</key>
+ <string>string.quasiquoted.haskell</string>
+ </dict>
+ <key>2</key>
+ <dict>
+ <key>name</key>
+ <string>keyword.other.quasibracket.haskell</string>
+ </dict>
+ </dict>
+ <key>name</key>
+ <string>meta.other.quasiquote.haskell</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>match</key>
+ <string>\$\(</string>
+ <key>name</key>
+ <string>keyword.other.splice.haskell</string>
+ </dict>
+ <dict>
+ <key>match</key>
+ <string>\$</string>
+ <key>name</key>
+ <string>string.quasiquoted.haskell</string>
+ </dict>
+ <dict>
+ <key>match</key>
+ <string>[^$]*</string>
+ <key>name</key>
+ <string>string.quasiquoted.haskell</string>
+ </dict>
+ </array>
+ </dict>
+ <dict>
+ <key>comment</key>
+ <string>Highlight the beginning of a splice.</string>
+ <key>match</key>
+ <string>\$\(</string>
+ <key>name</key>
+ <string>keyword.other.splice.haskell</string>
+ </dict>
+ <dict>
+ <key>begin</key>
+ <string>\[[a-zA-Z0-9_']*\|</string>
+ <key>beginCaptures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>keyword.other.quasibracket.haskell</string>
+ </dict>
+ </dict>
+ <key>end</key>
+ <string>(.*)(\|\])</string>
+ <key>endCaptures</key>
+ <dict>
+ <key>1</key>
+ <dict>
+ <key>name</key>
+ <string>string.quasiquoted.haskell</string>
+ </dict>
+ <key>2</key>
+ <dict>
+ <key>name</key>
+ <string>keyword.other.quasibracket.haskell</string>
+ </dict>
+ </dict>
+ <key>name</key>
+ <string>meta.other.quasiquote.haskell</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>match</key>
+ <string>.*</string>
+ <key>name</key>
+ <string>string.quasiquoted.haskell</string>
</dict>
</array>
</dict>
@@ -385,7 +487,23 @@
</dict>
</dict>
<key>end</key>
- <string>$\n?</string>
+ <string>(?x)
+ ^(data|newtype|type|class|deriving)\s # When a top level declaration starts
+ | ^[^=]*(=)[\sa-zA-Z0-9_\(] # A function declaration
+ </string>
+ <key>endCaptures</key>
+ <dict>
+ <key>1</key>
+ <dict>
+ <key>name</key>
+ <string>keyword.other.haskell</string>
+ </dict>
+ <key>2</key>
+ <dict>
+ <key>name</key>
+ <string>keyword.operator.haskell</string>
+ </dict>
+ </dict>
<key>name</key>
<string>meta.function.type-declaration.haskell</string>
<key>patterns</key>
@@ -395,12 +513,6 @@
<string>#type_signature</string>
</dict>
</array>
- </dict>
- <dict>
- <key>match</key>
- <string>\b(Just|Nothing|Left|Right|True|False|LT|EQ|GT|\(\)|\[\])\b</string>
- <key>name</key>
- <string>support.constant.haskell</string>
</dict>
<dict>
<key>match</key>
@@ -411,12 +523,6 @@
<dict>
<key>include</key>
<string>#comments</string>
- </dict>
- <dict>
- <key>match</key>
- <string>\b(abs|acos|acosh|all|and|any|appendFile|applyM|asTypeOf|asin|asinh|atan|atan2|atanh|break|catch|ceiling|compare|concat|concatMap|const|cos|cosh|curry|cycle|decodeFloat|div|divMod|drop|dropWhile|elem|encodeFloat|enumFrom|enumFromThen|enumFromThenTo|enumFromTo|error|even|exp|exponent|fail|filter|flip|floatDigits|floatRadix|floatRange|floor|fmap|foldl|foldl1|foldr|foldr1|fromEnum|fromInteger|fromIntegral|fromRational|fst|gcd|getChar|getContents|getLine|head|id|init|interact|ioError|isDenormalized|isIEEE|isInfinite|isNaN|isNegativeZero|iterate|last|lcm|length|lex|lines|log|logBase|lookup|map|mapM|mapM_|max|maxBound|maximum|maybe|min|minBound|minimum|mod|negate|not|notElem|null|odd|or|otherwise|pi|pred|print|product|properFraction|putChar|putStr|putStrLn|quot|quotRem|read|readFile|readIO|readList|readLn|readParen|reads|readsPrec|realToFrac|recip|rem|repeat|replicate|return|reverse|round|scaleFloat|scanl|scanl1|scanr|scanr1|seq|sequence|sequence_|show|showChar|showList|showParen|showString|shows|showsPrec|significand|signum|sin|sinh|snd|span|splitAt|sqrt|subtract|succ|sum|tail|take|takeWhile|tan|tanh|toEnum|toInteger|toRational|truncate|uncurry|undefined|unlines|until|unwords|unzip|unzip3|userError|words|writeFile|zip|zip3|zipWith|zipWith3)\b</string>
- <key>name</key>
- <string>support.function.prelude.haskell</string>
</dict>
<dict>
<key>include</key>
@@ -536,6 +642,10 @@
<key>name</key>
<string>meta.other.unknown.haskell</string>
</dict>
+ <dict>
+ <key>include</key>
+ <string>#comments</string>
+ </dict>
</array>
</dict>
<key>module_name</key>
@@ -568,30 +678,6 @@
<key>patterns</key>
<array>
<dict>
- <key>captures</key>
- <dict>
- <key>1</key>
- <dict>
- <key>name</key>
- <string>entity.other.inherited-class.haskell</string>
- </dict>
- <key>2</key>
- <dict>
- <key>name</key>
- <string>variable.other.generic-type.haskell</string>
- </dict>
- <key>3</key>
- <dict>
- <key>name</key>
- <string>keyword.other.big-arrow.haskell</string>
- </dict>
- </dict>
- <key>match</key>
- <string>\(\s*([A-Z][A-Za-z]*)\s+([a-z][A-Za-z_']*)\)\s*(=>)</string>
- <key>name</key>
- <string>meta.class-constraint.haskell</string>
- </dict>
- <dict>
<key>include</key>
<string>#pragma</string>
</dict>
@@ -606,12 +692,6 @@
<string>=></string>
<key>name</key>
<string>keyword.other.big-arrow.haskell</string>
- </dict>
- <dict>
- <key>match</key>
- <string>\b(Int(eger)?|Maybe|Either|Bool|Float|Double|Char|String|Ordering|ShowS|ReadS|FilePath|IO(Error)?)\b</string>
- <key>name</key>
- <string>support.type.prelude.haskell</string>
</dict>
<dict>
<key>match</key>