vim-polyglot/syntax/purescript.vim

222 lines
10 KiB
VimL
Raw Normal View History

2016-05-02 05:35:06 -04:00
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'purescript') == -1
" syntax highlighting for purescript
"
" Heavily modified version of the purescript syntax
" highlighter to support purescript.
"
" author: raichoo (raichoo@googlemail.com)
if exists("b:current_syntax")
finish
endif
2016-09-11 07:24:17 -04:00
" Values
syn match purescriptIdentifier "\<[_a-z]\(\w\|\'\)*\>"
syn match purescriptNumber "0[xX][0-9a-fA-F]\+\|0[oO][0-7]\|[0-9]\+"
syn match purescriptFloat "[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\="
syn keyword purescriptBoolean true false
" Delimiters
syn match purescriptDelimiter "[,;|.()[\]{}]"
" Type
syn match purescriptType "\%(\<class\s\+\)\@15<!\<\u\w*\>" contained
2016-09-11 07:24:17 -04:00
\ containedin=purescriptTypeAlias
\ nextgroup=purescriptType,purescriptTypeVar skipwhite
syn match purescriptTypeVar "\<[_a-z]\(\w\|\'\)*\>" contained
\ containedin=purescriptData,purescriptNewtype,purescriptTypeAlias,purescriptFunctionDecl
syn region purescriptTypeExport matchgroup=purescriptType start="\<[A-Z]\(\S\&[^,.]\)*\>("rs=e-1 matchgroup=purescriptDelimiter end=")" contained extend
\ contains=purescriptConstructor,purescriptDelimiter
" Constructor
syn match purescriptConstructor "\%(\<class\s\+\)\@15<!\<\u\w*\>"
syn region purescriptConstructorDecl matchgroup=purescriptConstructor start="\<[A-Z]\w*\>" end="\(|\|$\)"me=e-1,re=e-1 contained
\ containedin=purescriptData,purescriptNewtype
\ contains=purescriptType,purescriptTypeVar,purescriptDelimiter,purescriptOperatorType,purescriptOperatorTypeSig,@purescriptComment
2016-09-11 07:24:17 -04:00
" Function
2017-11-19 15:26:59 -05:00
syn match purescriptFunction "\%(\<instance\s\+\|\<class\s\+\)\@18<!\<[_a-z]\(\w\|\'\)*\>" contained
" syn match purescriptFunction "\<[_a-z]\(\w\|\'\)*\>" contained
syn match purescriptFunction "(\%(\<class\s\+\)\@18<!\(\W\&[^(),\"]\)\+)" contained extend
syn match purescriptBacktick "`[_A-Za-z][A-Za-z0-9_\.]*`"
" Class
syn region purescriptClassDecl start="^\%(\s*\)class\>"ms=e-5 end="\<where\>\|$"
\ contains=purescriptClass,purescriptClassName,purescriptOperatorType,purescriptOperator,purescriptType,purescriptWhere
\ nextgroup=purescriptClass
\ skipnl
syn match purescriptClass "\<class\>" containedin=purescriptClassDecl contained
\ nextgroup=purescriptClassName
\ skipnl
syn match purescriptClassName "\<[A-Z]\w*\>" containedin=purescriptClassDecl contained
2016-09-11 07:24:17 -04:00
" Module
syn match purescriptModuleName "\(\u\w\*\.\?\)*" contained excludenl
2016-09-11 07:24:17 -04:00
syn match purescriptModuleKeyword "\<module\>"
syn match purescriptModule "^module\>\s\+\<\(\w\+\.\?\)*\>"
\ contains=purescriptModuleKeyword,purescriptModuleName
\ nextgroup=purescriptModuleParams
\ skipwhite
\ skipnl
\ skipempty
2017-11-19 15:26:59 -05:00
syn region purescriptModuleParams start="(" skip="([^)]\{-})" end=")" fold contained keepend
\ contains=purescriptClassDecl,purescriptClass,purescriptClassName,purescriptDelimiter,purescriptType,purescriptTypeExport,purescriptStructure,purescriptModuleKeyword,@purescriptComment
2016-09-11 07:24:17 -04:00
\ nextgroup=purescriptImportParams skipwhite
" Import
syn match purescriptImportKeyword "\<\(foreign\|import\|qualified\)\>"
syn match purescriptImport "\<import\>\s\+\(qualified\s\+\)\?\<\(\w\+\.\?\)*"
\ contains=purescriptImportKeyword,purescriptModuleName
\ nextgroup=purescriptImportParams,purescriptImportAs,purescriptImportHiding
\ skipwhite
syn region purescriptImportParams
\ start="("
\ skip="([^)]\{-})"
\ end=")"
\ contained
\ contains=purescriptClass,purescriptClass,purescriptStructure,purescriptType,purescriptIdentifier
\ nextgroup=purescriptImportAs
\ skipwhite
2016-09-11 07:24:17 -04:00
syn keyword purescriptAsKeyword as contained
syn match purescriptImportAs "\<as\>\_s\+\u\w*"
\ contains=purescriptAsKeyword,purescriptModuleName
\ nextgroup=purescriptModuleName
2016-09-11 07:24:17 -04:00
syn keyword purescriptHidingKeyword hiding contained
syn match purescriptImportHiding "hiding"
\ contained
2016-09-11 07:24:17 -04:00
\ contains=purescriptHidingKeyword
\ nextgroup=purescriptImportParams
\ skipwhite
2016-09-11 07:24:17 -04:00
" Function declaration
2017-09-27 13:57:29 -04:00
syn region purescriptFunctionDecl
\ excludenl start="^\z(\s*\)\(\(foreign\s\+import\)\_s\+\)\?[_a-z]\(\w\|\'\)*\_s\{-}\(::\|∷\)"
\ end="^\z1\=\S"me=s-1,re=s-1 keepend
2016-09-11 07:24:17 -04:00
\ contains=purescriptFunctionDeclStart,purescriptForall,purescriptOperatorType,purescriptOperatorTypeSig,purescriptType,purescriptTypeVar,purescriptDelimiter,@purescriptComment
2017-09-27 13:57:29 -04:00
syn region purescriptFunctionDecl
\ excludenl start="^\z(\s*\)where\z(\s\+\)[_a-z]\(\w\|\'\)*\_s\{-}\(::\|∷\)"
\ end="^\(\z1\s\{5}\z2\)\=\S"me=s-1,re=s-1 keepend
\ contains=purescriptFunctionDeclStart,purescriptForall,purescriptOperatorType,purescriptOperatorTypeSig,purescriptType,purescriptTypeVar,purescriptDelimiter,@purescriptComment
syn region purescriptFunctionDecl
\ excludenl start="^\z(\s*\)let\z(\s\+\)[_a-z]\(\w\|\'\)*\_s\{-}\(::\|∷\)"
\ end="^\(\z1\s\{3}\z2\)\=\S"me=s-1,re=s-1 keepend
\ contains=purescriptFunctionDeclStart,purescriptForall,purescriptOperatorType,purescriptOperatorTypeSig,purescriptType,purescriptTypeVar,purescriptDelimiter,@purescriptComment
syn match purescriptFunctionDeclStart "^\s*\(\(foreign\s\+import\|let\|where\)\_s\+\)\?\([_a-z]\(\w\|\'\)*\)\_s\{-}\(::\|∷\)" contained
\ contains=purescriptImportKeyword,purescriptWhere,purescriptLet,purescriptFunction,purescriptOperatorType
2016-09-11 07:24:17 -04:00
syn keyword purescriptForall forall
syn match purescriptForall "∀"
" Keywords
2016-05-02 05:35:06 -04:00
syn keyword purescriptConditional if then else
2018-12-26 04:41:57 -05:00
syn keyword purescriptStatement do case of in ado
2017-09-27 13:57:29 -04:00
syn keyword purescriptLet let
2016-09-11 07:24:17 -04:00
syn keyword purescriptWhere where
2017-11-19 15:26:59 -05:00
syn match purescriptStructure "\<\(data\|newtype\|type\|kind\)\>"
2016-09-11 07:24:17 -04:00
\ nextgroup=purescriptType skipwhite
syn keyword purescriptStructure derive
syn keyword purescriptStructure instance
\ nextgroup=purescriptFunction skipwhite
" Infix
syn match purescriptInfixKeyword "\<\(infix\|infixl\|infixr\)\>"
syn match purescriptInfix "^\(infix\|infixl\|infixr\)\>\s\+\([0-9]\+\)\s\+\(type\s\+\)\?\(\S\+\)\s\+as\>"
\ contains=purescriptInfixKeyword,purescriptNumber,purescriptAsKeyword,purescriptConstructor,purescriptStructure,purescriptFunction,purescriptBlockComment
\ nextgroup=purescriptFunction,purescriptOperator,@purescriptComment
" Operators
syn match purescriptOperator "\([-!#$%&\*\+/<=>\?@\\^|~:]\|\<_\>\)"
2017-11-19 15:26:59 -05:00
syn match purescriptOperatorType "\%(\<instance\>.*\)\@40<!\(::\|∷\)"
2016-09-11 07:24:17 -04:00
\ nextgroup=purescriptForall,purescriptType skipwhite skipnl skipempty
syn match purescriptOperatorFunction "\(->\|<-\|[\\→←]\)"
syn match purescriptOperatorTypeSig "\(->\|<-\|=>\|<=\|::\|[∷∀→←⇒⇐]\)" contained
\ nextgroup=purescriptType skipwhite skipnl skipempty
" Type definition
syn region purescriptData start="^data\s\+\([A-Z]\w*\)" end="^\S"me=s-1,re=s-1 transparent
syn match purescriptDataStart "^data\s\+\([A-Z]\w*\)" contained
\ containedin=purescriptData
\ contains=purescriptStructure,purescriptType,purescriptTypeVar
syn match purescriptForeignData "\<foreign\s\+import\s\+data\>"
\ contains=purescriptImportKeyword,purescriptStructure
\ nextgroup=purescriptType skipwhite
syn region purescriptNewtype start="^newtype\s\+\([A-Z]\w*\)" end="^\S"me=s-1,re=s-1 transparent
syn match purescriptNewtypeStart "^newtype\s\+\([A-Z]\w*\)" contained
\ containedin=purescriptNewtype
\ contains=purescriptStructure,purescriptType,purescriptTypeVar
syn region purescriptTypeAlias start="^type\s\+\([A-Z]\w*\)" end="^\S"me=s-1,re=s-1 transparent
syn match purescriptTypeAliasStart "^type\s\+\([A-Z]\w*\)" contained
\ containedin=purescriptTypeAlias
\ contains=purescriptStructure,purescriptType,purescriptTypeVar
" String
2016-05-02 05:35:06 -04:00
syn match purescriptChar "'[^'\\]'\|'\\.'\|'\\u[0-9a-fA-F]\{4}'"
syn region purescriptString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell
syn region purescriptMultilineString start=+"""+ end=+"""+ fold contains=@Spell
2016-09-11 07:24:17 -04:00
" Comment
syn match purescriptLineComment "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$" contains=@Spell
2016-09-11 07:24:17 -04:00
syn region purescriptBlockComment start="{-" end="-}" fold
\ contains=purescriptBlockComment,@Spell
syn cluster purescriptComment contains=purescriptLineComment,purescriptBlockComment,@Spell
2016-09-11 07:24:17 -04:00
syn sync minlines=50
" highlight links
highlight def link purescriptModule Include
highlight def link purescriptImport Include
2016-09-11 07:24:17 -04:00
highlight def link purescriptModuleKeyword purescriptKeyword
highlight def link purescriptImportAs Include
2016-09-11 07:24:17 -04:00
highlight def link purescriptModuleName Include
highlight def link purescriptModuleParams purescriptDelimiter
highlight def link purescriptImportKeyword purescriptKeyword
highlight def link purescriptAsKeyword purescriptKeyword
highlight def link purescriptHidingKeyword purescriptKeyword
2016-05-02 05:35:06 -04:00
highlight def link purescriptConditional Conditional
2016-09-11 07:24:17 -04:00
highlight def link purescriptWhere purescriptKeyword
highlight def link purescriptInfixKeyword purescriptKeyword
highlight def link purescriptBoolean Boolean
2016-05-02 05:35:06 -04:00
highlight def link purescriptNumber Number
highlight def link purescriptFloat Float
2016-09-11 07:24:17 -04:00
2016-05-02 05:35:06 -04:00
highlight def link purescriptDelimiter Delimiter
2016-09-11 07:24:17 -04:00
highlight def link purescriptOperatorTypeSig purescriptOperatorType
highlight def link purescriptOperatorFunction purescriptOperatorType
highlight def link purescriptOperatorType purescriptOperator
highlight def link purescriptConstructorDecl purescriptConstructor
highlight def link purescriptConstructor purescriptFunction
highlight def link purescriptTypeVar Identifier
highlight def link purescriptForall purescriptStatement
highlight def link purescriptChar String
highlight def link purescriptBacktick purescriptOperator
2016-05-02 05:35:06 -04:00
highlight def link purescriptString String
highlight def link purescriptMultilineString String
2016-09-11 07:24:17 -04:00
highlight def link purescriptLineComment purescriptComment
highlight def link purescriptBlockComment purescriptComment
" purescript general highlights
2017-11-19 15:26:59 -05:00
highlight def link purescriptClass purescriptKeyword
highlight def link purescriptClassName Type
2016-09-11 07:24:17 -04:00
highlight def link purescriptStructure purescriptKeyword
highlight def link purescriptKeyword Keyword
highlight def link purescriptStatement Statement
2017-09-27 13:57:29 -04:00
highlight def link purescriptLet Statement
2016-09-11 07:24:17 -04:00
highlight def link purescriptOperator Operator
highlight def link purescriptFunction Function
highlight def link purescriptType Type
highlight def link purescriptComment Comment
2016-05-02 05:35:06 -04:00
let b:current_syntax = "purescript"
endif