neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

haskell.vim (9473B)


      1 " Vim syntax file
      2 " Language:		Haskell
      3 " Maintainer:		Haskell Cafe mailinglist <haskell-cafe@haskell.org>
      4 " 			(need to be subscribed to post)
      5 " Last Change:		2024 Mar 28 by Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com>
      6 "			2025 Nov 20 by Vim Project: Allow spaces in backticks #18776
      7 " Original Author:	John Williams <jrw@pobox.com>
      8 "
      9 " Thanks to Ryan Crumley for suggestions and John Meacham for
     10 " pointing out bugs. Also thanks to Ian Lynagh and Donald Bruce Stewart
     11 " for providing the inspiration for the inclusion of the handling
     12 " of C preprocessor directives, and for pointing out a bug in the
     13 " end-of-line comment handling.
     14 "
     15 " Options-assign a value to these variables to turn the option on:
     16 "
     17 " hs_highlight_delimiters - Highlight delimiter characters--users
     18 "			    with a light-colored background will
     19 "			    probably want to turn this on.
     20 " hs_highlight_boolean - Treat True and False as keywords.
     21 " hs_highlight_types - Treat names of primitive types as keywords.
     22 " hs_highlight_more_types - Treat names of other common types as keywords.
     23 " hs_highlight_debug - Highlight names of debugging functions.
     24 " hs_allow_hash_operator - Don't highlight seemingly incorrect C
     25 "			   preprocessor directives but assume them to be
     26 "			   operators
     27 "
     28 " 2004 Feb 19: Added C preprocessor directive handling, corrected eol comments
     29 "	       cleaned away literate haskell support (should be entirely in
     30 "	       lhaskell.vim)
     31 " 2004 Feb 20: Cleaned up C preprocessor directive handling, fixed single \
     32 "	       in eol comment character class
     33 " 2004 Feb 23: Made the leading comments somewhat clearer where it comes
     34 "	       to attribution of work.
     35 " 2008 Dec 15: Added comments as contained element in import statements
     36 
     37 " quit when a syntax file was already loaded
     38 if exists("b:current_syntax")
     39  finish
     40 endif
     41 
     42 " (Qualified) identifiers (no default highlighting)
     43 syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)*\<[A-Z][a-zA-Z0-9_']*\>" contains=@NoSpell
     44 syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)*\<[a-z][a-zA-Z0-9_']*\>" contains=@NoSpell
     45 
     46 " Infix operators--most punctuation characters and any (qualified) identifier
     47 " enclosed in `backquotes`. An operator starting with : is a constructor,
     48 " others are variables (e.g. functions).
     49 syn match hsVarSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[-!#$%&\*\+/<=>\?@\\^|~.][-!#$%&\*\+/<=>\?@\\^|~:.]*"
     50 syn match hsConSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=:[-!#$%&\*\+./<=>\?@\\^|~:]*"
     51 syn match hsVarSym "` *\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[a-z][a-zA-Z0-9_']* *`"
     52 syn match hsConSym "` *\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[A-Z][a-zA-Z0-9_']* *`"
     53 
     54 " (Non-qualified) identifiers which start with # are labels
     55 syn match hsLabel "#[a-z][a-zA-Z0-9_']*\>"
     56 
     57 " Reserved symbols--cannot be overloaded.
     58 syn match hsDelimiter  "(\|)\|\[\|\]\|,\|;\|{\|}"
     59 
     60 " Strings and constants
     61 syn match   hsSpecialChar	contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)"
     62 syn match   hsSpecialChar	contained "\\\(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\)"
     63 syn match   hsSpecialCharError	contained "\\&\|'''\+"
     64 syn region  hsString		start=+"+  skip=+\\\\\|\\"+  end=+"+  contains=hsSpecialChar,@NoSpell
     65 syn match   hsCharacter		"[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=hsSpecialChar,hsSpecialCharError
     66 syn match   hsCharacter		"^'\([^\\]\|\\[^']\+\|\\'\)'" contains=hsSpecialChar,hsSpecialCharError
     67 syn match   hsNumber		"\v<[0-9]%(_*[0-9])*>|<0[xX]_*[0-9a-fA-F]%(_*[0-9a-fA-F])*>|<0[oO]_*%(_*[0-7])*>|<0[bB]_*[01]%(_*[01])*>"
     68 syn match   hsFloat		"\v<[0-9]%(_*[0-9])*\.[0-9]%(_*[0-9])*%(_*[eE][-+]?[0-9]%(_*[0-9])*)?>|<[0-9]%(_*[0-9])*_*[eE][-+]?[0-9]%(_*[0-9])*>|<0[xX]_*[0-9a-fA-F]%(_*[0-9a-fA-F])*\.[0-9a-fA-F]%(_*[0-9a-fA-F])*%(_*[pP][-+]?[0-9]%(_*[0-9])*)?>|<0[xX]_*[0-9a-fA-F]%(_*[0-9a-fA-F])*_*[pP][-+]?[0-9]%(_*[0-9])*>"
     69 
     70 " Keyword definitions.
     71 syn keyword hsModule		module
     72 syn match   hsImportGroup	"\<import\>.*" contains=hsImport,hsImportModuleName,hsImportMod,hsLineComment,hsBlockComment,hsImportList,@NoSpell nextgroup=hsImport
     73 syn keyword hsImport import contained nextgroup=hsImportModuleName
     74 syn match   hsImportModuleName '\<[A-Z][A-Za-z.]*' contained
     75 syn region  hsImportList start='(' skip='([^)]\{-})' end=')' keepend contained contains=ConId,VarId,hsDelimiter,hsBlockComment,hsTypedef,@NoSpell
     76 
     77 syn keyword hsImportMod contained as qualified hiding
     78 syn keyword hsInfix infix infixl infixr
     79 syn keyword hsStructure class data deriving instance default where
     80 syn keyword hsTypedef type
     81 syn keyword hsNewtypedef newtype
     82 syn keyword hsTypeFam family
     83 syn keyword hsStatement mdo do case of let in
     84 syn keyword hsConditional if then else
     85 
     86 " Not real keywords, but close.
     87 if exists("hs_highlight_boolean")
     88  " Boolean constants from the standard prelude.
     89  syn keyword hsBoolean True False
     90 endif
     91 if exists("hs_highlight_types")
     92  " Primitive types from the standard prelude and libraries.
     93  syn keyword hsType Int Integer Char Bool Float Double IO Void Addr Array String
     94 endif
     95 if exists("hs_highlight_more_types")
     96  " Types from the standard prelude libraries.
     97  syn keyword hsType Maybe Either Ratio Complex Ordering IOError IOResult ExitCode
     98  syn keyword hsMaybe Nothing
     99  syn keyword hsExitCode ExitSuccess
    100  syn keyword hsOrdering GT LT EQ
    101 endif
    102 if exists("hs_highlight_debug")
    103  " Debugging functions from the standard prelude.
    104  syn keyword hsDebug undefined error trace
    105 endif
    106 
    107 
    108 " Comments
    109 syn match   hsLineComment      "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$" contains=hsTodo,@Spell
    110 syn region  hsBlockComment     start="{-"  end="-}" contains=hsBlockComment,hsTodo,@Spell
    111 syn region  hsPragma	       start="{-#" end="#-}"
    112 
    113 syn keyword hsTodo	        contained FIXME TODO XXX NOTE
    114 
    115 " C Preprocessor directives. Shamelessly ripped from c.vim and trimmed
    116 " First, see whether to flag directive-like lines or not
    117 if (!exists("hs_allow_hash_operator"))
    118    syn match	cError		display "^\s*\(%:\|#\).*$"
    119 endif
    120 " Accept %: for # (C99)
    121 syn region	cPreCondit	start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cCppString,cCommentError
    122 syn match	cPreCondit	display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"
    123 syn region	cCppOut		start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2
    124 syn region	cCppOut2	contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cCppSkip
    125 syn region	cCppSkip	contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cCppSkip
    126 syn region	cIncluded	display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
    127 syn match	cIncluded	display contained "<[^>]*>"
    128 syn match	cInclude	display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
    129 syn cluster	cPreProcGroup	contains=cPreCondit,cIncluded,cInclude,cDefine,cCppOut,cCppOut2,cCppSkip,cCommentStartError
    130 syn region	cDefine		matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$"
    131 syn region	cPreProc	matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend
    132 
    133 syn region	cComment	matchgroup=cCommentStart start="/\*" end="\*/" contains=cCommentStartError,cSpaceError contained
    134 syntax match	cCommentError	display "\*/" contained
    135 syntax match	cCommentStartError display "/\*"me=e-1 contained
    136 syn region	cCppString	start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained
    137 
    138 " Define the default highlighting.
    139 " Only when an item doesn't have highlighting yet
    140 
    141 hi def link hsModule			  hsStructure
    142 hi def link hsImport			  Include
    143 hi def link hsImportMod			  hsImport
    144 hi def link hsInfix			  PreProc
    145 hi def link hsStructure			  Structure
    146 hi def link hsStatement			  Statement
    147 hi def link hsConditional		  Conditional
    148 hi def link hsSpecialChar		  SpecialChar
    149 hi def link hsTypedef			  Typedef
    150 hi def link hsNewtypedef		  Typedef
    151 hi def link hsVarSym			  hsOperator
    152 hi def link hsConSym			  hsOperator
    153 hi def link hsOperator			  Operator
    154 hi def link hsTypeFam			  Structure
    155 if exists("hs_highlight_delimiters")
    156 " Some people find this highlighting distracting.
    157 hi def link hsDelimiter			  Delimiter
    158 endif
    159 hi def link hsSpecialCharError		  Error
    160 hi def link hsString			  String
    161 hi def link hsCharacter			  Character
    162 hi def link hsNumber			  Number
    163 hi def link hsFloat			  Float
    164 hi def link hsConditional			  Conditional
    165 hi def link hsLiterateComment		  hsComment
    166 hi def link hsBlockComment		  hsComment
    167 hi def link hsLineComment			  hsComment
    168 hi def link hsComment			  Comment
    169 hi def link hsTodo			  Todo
    170 hi def link hsPragma			  SpecialComment
    171 hi def link hsBoolean			  Boolean
    172 hi def link hsType			  Type
    173 hi def link hsMaybe			  hsEnumConst
    174 hi def link hsOrdering			  hsEnumConst
    175 hi def link hsEnumConst			  Constant
    176 hi def link hsDebug			  Debug
    177 hi def link hsLabel			  Special
    178 
    179 hi def link cCppString			  hsString
    180 hi def link cCommentStart		  hsComment
    181 hi def link cCommentError		  hsError
    182 hi def link cCommentStartError		  hsError
    183 hi def link cInclude			  Include
    184 hi def link cPreProc			  PreProc
    185 hi def link cDefine			  Macro
    186 hi def link cIncluded			  hsString
    187 hi def link cError			  Error
    188 hi def link cPreCondit			  PreCondit
    189 hi def link cComment			  Comment
    190 hi def link cCppSkip			  cCppOut
    191 hi def link cCppOut2			  cCppOut
    192 hi def link cCppOut			  Comment
    193 
    194 let b:current_syntax = "haskell"
    195 
    196 " Options for vi: ts=8 sw=2 sts=2 nowrap noexpandtab ft=vim