lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

Haskell.sublime-syntax (9389B)


      1 %YAML 1.2
      2 ---
      3 # http://www.sublimetext.com/docs/3/syntax.html
      4 name: Haskell
      5 file_extensions:
      6   - hs
      7 scope: source.haskell
      8 contexts:
      9   main:
     10     - match: "(`)[a-zA-Z_']*?(`)"
     11       comment: "In case this regex seems unusual for an infix operator, note that Haskell allows any ordinary function application (elem 4 [1..10]) to be rewritten as an infix expression (4 `elem` [1..10])."
     12       scope: keyword.operator.function.infix.haskell
     13       captures:
     14         1: punctuation.definition.entity.haskell
     15         2: punctuation.definition.entity.haskell
     16     - match: \(\)
     17       scope: constant.language.unit.haskell
     18     - match: '\[\]'
     19       scope: constant.language.empty-list.haskell
     20     - match: \b(module)\b
     21       captures:
     22         1: keyword.other.haskell
     23       push:
     24         - meta_scope: meta.declaration.module.haskell
     25         - match: (where)
     26           captures:
     27             1: keyword.other.haskell
     28           pop: true
     29         - include: module_name
     30         - include: module_exports
     31         - match: "[a-z]+"
     32           scope: invalid
     33     - match: \b(class)\b
     34       captures:
     35         1: keyword.other.haskell
     36       push:
     37         - meta_scope: meta.declaration.class.haskell
     38         - match: \b(where)\b
     39           captures:
     40             1: keyword.other.haskell
     41           pop: true
     42         - match: \b(Mon(ad|oid)|Functor|Applicative|(Folda|Traversa)ble|Eq|Ord|Read|Show|Num|(Frac|Ra)tional|Enum|Bounded|Real(Frac|Float)?|Integral|Floating)\b
     43           scope: support.class.prelude.haskell
     44         - match: "[A-Z][A-Za-z_']*"
     45           scope: entity.other.inherited-class.haskell
     46         - match: '\b[a-z][a-zA-Z0-9_'']*\b'
     47           scope: variable.other.generic-type.haskell
     48     - match: \b(instance)\b
     49       captures:
     50         1: keyword.other.haskell
     51       push:
     52         - meta_scope: meta.declaration.instance.haskell
     53         - match: \b(where)\b|$
     54           captures:
     55             1: keyword.other.haskell
     56           pop: true
     57         - include: type_signature
     58     - match: \b(import)\b
     59       captures:
     60         1: keyword.other.haskell
     61       push:
     62         - meta_scope: meta.import.haskell
     63         - match: ($|;)
     64           pop: true
     65         - match: (qualified|as|hiding)
     66           scope: keyword.other.haskell
     67         - include: module_name
     68         - include: module_exports
     69         - include: comments
     70     - match: (deriving)\s*\(
     71       captures:
     72         1: keyword.other.haskell
     73       push:
     74         - meta_scope: meta.deriving.haskell
     75         - match: \)
     76           pop: true
     77         - match: '\b[A-Z][a-zA-Z_'']*'
     78           scope: entity.other.inherited-class.haskell
     79     - match: \b(deriving|where|data|type|case|of|let|in|newtype|default)\b
     80       scope: keyword.other.haskell
     81     - match: '\binfix[lr]?\b'
     82       scope: keyword.operator.haskell
     83     - match: \b(do|if|then|else)\b
     84       scope: keyword.control.haskell
     85     - match: \b\d+(?:(\.)\d+(?:[eE][-+]?\d+)?|(?:[eE][-+]?\d+))\b
     86       scope: constant.numeric.float.decimal.haskell
     87       captures:
     88         1: punctuation.separator.decimal.haskell
     89     - match: \b(0[oO])[0-7]+\b
     90       scope: constant.numeric.integer.octal.haskell
     91       captures:
     92         1: punctuation.definition.numeric.base.haskell
     93     - match: \b(0[xX])\h+\b
     94       scope: constant.numeric.integer.hexadecimal.haskell
     95       captures:
     96         1: punctuation.definition.numeric.base.haskell
     97     - match: \b\d+\b
     98       scope: constant.numeric.integer.decimal.haskell
     99     - match: ^\s*(#)\s*\w+
    100       comment: In addition to Haskell's "native" syntax, GHC permits the C preprocessor to be run on a source file.
    101       scope: meta.preprocessor.c
    102       captures:
    103         1: punctuation.definition.preprocessor.c
    104     - include: pragma
    105     - match: '"'
    106       scope: punctuation.definition.string.begin.haskell
    107       push:
    108         - meta_scope: string.quoted.double.haskell
    109         - match: $|"
    110           scope: punctuation.definition.string.end.haskell
    111           pop: true
    112         - match: '\\(NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|[abfnrtv\\\"''\&])'
    113           scope: constant.character.escape.haskell
    114         - match: '\\o[0-7]+|\\x[0-9A-Fa-f]+|\\[0-9]+'
    115           scope: constant.character.escape.octal.haskell
    116         - match: '\^[A-Z@\[\]\\\^_]'
    117           scope: constant.character.escape.control.haskell
    118     - match: '\[(?:|e|d|t|p)\|'
    119       comment: Points out splices in ast quotes
    120       scope: keyword.other.quasibracket.haskell
    121       push:
    122         - meta_scope: meta.other.quasiquote.haskell
    123         - match: '(.*)(\|\])'
    124           captures:
    125             1: string.quasiquoted.haskell
    126             2: keyword.other.quasibracket.haskell
    127           pop: true
    128         - match: \$\(
    129           scope: keyword.other.splice.haskell
    130         - match: \$
    131           scope: string.quasiquoted.haskell
    132         - match: "[^$]*"
    133           scope: string.quasiquoted.haskell
    134     - match: \$\(
    135       comment: Highlight the beginning of a splice.
    136       scope: keyword.other.splice.haskell
    137     - match: '\[[a-zA-Z0-9_'']*\|'
    138       scope: keyword.other.quasibracket.haskell
    139       push:
    140         - meta_scope: meta.other.quasiquote.haskell
    141         - match: '(.*)(\|\])'
    142           captures:
    143             1: string.quasiquoted.haskell
    144             2: keyword.other.quasibracket.haskell
    145           pop: true
    146         - match: .*
    147           scope: string.quasiquoted.haskell
    148     - match: |-
    149         (?x)
    150         (')
    151         (?:
    152           [\ -\[\]-~]                             # Basic Char
    153           | (\\(?:NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE
    154             |DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS
    155             |US|SP|DEL|[abfnrtv\\\"'\&]))       # Escapes
    156           | (\\o[0-7]+)                             # Octal Escapes
    157           | (\\x[0-9A-Fa-f]+)                       # Hexadecimal Escapes
    158           | (\^[A-Z@\[\]\\\^_])                     # Control Chars
    159         )
    160         (')
    161       scope: string.quoted.single.haskell
    162       captures:
    163         1: punctuation.definition.string.begin.haskell
    164         2: constant.character.escape.haskell
    165         3: constant.character.escape.octal.haskell
    166         4: constant.character.escape.hexadecimal.haskell
    167         5: constant.character.escape.control.haskell
    168         6: punctuation.definition.string.end.haskell
    169     - match: '^(\s*)([a-z_][a-zA-Z0-9_'']*|\([|!%$+\-.,=</>]+\))\s*(::|∷)'
    170       captures:
    171         2: entity.name.function.haskell
    172         3: keyword.other.double-colon.haskell
    173       push:
    174         - meta_scope: meta.function.type-declaration.haskell
    175         - match: ^(?!\s*(?:--|{-|$)|\1\s)
    176           pop: true
    177         - include: type_signature
    178     - match: '\b[A-Z]\w*\b'
    179       scope: constant.other.haskell
    180     - include: comments
    181     - include: infix_op
    182     - match: '[|!%$?~+:\-.=</>\\]+'
    183       comment: In case this regex seems overly general, note that Haskell permits the definition of new operators which can be nearly any string of punctuation characters, such as $%^&*.
    184       scope: keyword.operator.haskell
    185     - match: ","
    186       scope: punctuation.separator.comma.haskell
    187   block_comment:
    188     - match: '\{-(?!#)'
    189       scope: punctuation.definition.comment.begin.haskell
    190       push:
    191         - meta_scope: comment.block.haskell
    192         - match: '\{-#'
    193           push:
    194             - match: '-\}'
    195               pop: true
    196             - include: block_comment
    197         - include: block_comment
    198         - match: '-\}'
    199           scope: punctuation.definition.comment.end.haskell
    200           pop: true
    201   comments:
    202     - match: '--'
    203       scope: punctuation.definition.comment.haskell
    204       push:
    205         - meta_scope: comment.line.double-dash.haskell
    206         - match: $\n?
    207           pop: true
    208     - include: block_comment
    209   infix_op:
    210     - match: \([-+*/,|!%$:.=<>]+\)
    211       scope: entity.name.function.infix.haskell
    212   module_exports:
    213     - match: \(
    214       push:
    215         - meta_scope: meta.declaration.exports.haskell
    216         - match: \)
    217           pop: true
    218         - match: '\b[a-z][a-zA-Z_''0-9]*'
    219           scope: entity.name.function.haskell
    220         - match: '\b[A-Z][A-Za-z_''0-9]*'
    221           scope: storage.type.haskell
    222         - match: ","
    223           scope: punctuation.separator.comma.haskell
    224         - include: infix_op
    225         - match: \(.*?\)
    226           comment: So named because I don't know what to call this.
    227           scope: meta.other.unknown.haskell
    228         - include: comments
    229   module_name:
    230     - match: "[A-Z][A-Za-z._']*"
    231       scope: support.other.module.haskell
    232   pragma:
    233     - match: '\{-#'
    234       push:
    235         - meta_scope: meta.preprocessor.haskell
    236         - match: '#-\}'
    237           pop: true
    238         - match: \b(LANGUAGE|OPTIONS_GHC|INCLUDE|WARNING|DEPRECATED|MINIMAL|UNPACK|NOUNPACK|SOURCE|OVERLAPPING|OVERLAPPABLE|OVERLAPS|INCOHERENT|INLINE|NOINLINE|INLINABLE|CONLIKE|LINE|RULES|SPECIALIZE|SPECIALISE)\b
    239           # https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#pragmas
    240           scope: keyword.other.preprocessor.haskell
    241   type_signature:
    242     - include: pragma
    243     - match: "(->|→)"
    244       scope: keyword.other.arrow.haskell
    245     - match: "(=>|⇒)"
    246       scope: keyword.other.big-arrow.haskell
    247     - match: '\b[a-z][a-zA-Z0-9_'']*\b'
    248       scope: variable.other.generic-type.haskell
    249     - match: '\b[A-Z][a-zA-Z0-9_'']*\b'
    250       scope: storage.type.haskell
    251     - match: \(\)
    252       scope: support.constant.unit.haskell
    253     - include: comments