I’m trying to write a syntax definition for Haskell, but it’s turning out to be fairly difficult since it’s an indentation-based syntax (like Python) but most operations can go on the next line, provided they are indented more, and the syntax ends on the next line that starts at the original indentation. For example:
foo
:: Int
-> String
foo x = "foo" ++ show x
This example is equivalent to
foo :: Int -> String
foo x = "foo" ++ show x
or even
foo :: Int -> String; foo x = "foo" ++ show x
Some syntaxes I’ve had trouble writing definitions for include:
-- how to tell the `:: Int -> String` group that `x y = ...`
-- ends the type annotation?
let x :: Int
-> String
x y = show y ++ " hello "
in x 3 ++ "world"
-- matching `^(\s*){{ident}}` for `myFoo` lets me write
-- ```
-- match: '^\1\S'
-- pop: true
-- ```
-- on the top level, but when i push another context:
-- ```
-- match: '::'
-- push:
-- - match: '^\1\S'
-- pop: true
-- ```
-- `\1` no longer refers to the captured indentation
class Foo f where
myFoo :: f -> Int
myBar :: f -> Bool
If anyone could solve these syntax problems, that’d be great; otherwise if there’s some way to hook into Sublime Text to attach scopes manually in Python, please point me to such a reference. Thanks!
Note: the only relevant topic I found was: Indent-block syntax highlighting, but it doesn’t address this more complicated syntax.