Skip to content

Syntax issues #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions syntax/purescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ syn keyword purescriptBoolean true false
syn match purescriptDelimiter "[,;|.()[\]{}]"

" Constructor
syn match purescriptConstructor "\<[A-Z]\w*\>"
syn match purescriptConstructor "\%(\<class\s\+\)\@15<!\<[A-Z]\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

" Type
syn match purescriptType "\<[A-Z]\w*\>" contained
syn match purescriptType "\%(\<class\s\+\)\@15<!\<[A-Z]\w*\>" contained
\ containedin=purescriptTypeAlias
\ nextgroup=purescriptType,purescriptTypeVar skipwhite
syn match purescriptTypeVar "\<[_a-z]\(\w\|\'\)*\>" contained
Expand All @@ -34,18 +34,29 @@ syn region purescriptTypeExport matchgroup=purescriptType start="\<[A-Z]\(\S\&[^
\ contains=purescriptConstructor,purescriptDelimiter

" Function
syn match purescriptFunction "\<[_a-z]\(\w\|\'\)*\>" contained
syn match purescriptFunction "(\(\W\&[^(),\"]\)\+)" contained extend
syn match purescriptBacktick "`[_A-Za-z][A-Za-z0-9_]*`"
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

" Module
syn match purescriptModuleName "\(\w\+\.\?\)*" contained excludenl
syn match purescriptModuleKeyword "\<module\>"
syn match purescriptModule "^module\>\s\+\<\(\w\+\.\?\)*\>"
\ contains=purescriptModuleKeyword,purescriptModuleName
\ nextgroup=purescriptModuleParams skipwhite skipnl skipempty
syn region purescriptModuleParams start="(" end=")" fold contained keepend
\ contains=purescriptDelimiter,purescriptType,purescriptTypeExport,purescriptFunction,purescriptStructure,purescriptModuleKeyword,@purescriptComment
syn region purescriptModuleParams start="(" skip="([^)]\{-})" end=")" fold contained keepend
\ contains=purescriptClassDecl,purescriptClass,purescriptClassName,purescriptDelimiter,purescriptType,purescriptTypeExport,purescriptFunction,purescriptStructure,purescriptModuleKeyword,@purescriptComment
\ nextgroup=purescriptImportParams skipwhite

" Import
Expand Down Expand Up @@ -84,8 +95,9 @@ syn match purescriptForall "∀"
syn keyword purescriptConditional if then else
syn keyword purescriptStatement do case of in
syn keyword purescriptLet let
" syn keyword purescriptClass class
syn keyword purescriptWhere where
syn match purescriptStructure "\<\(data\|newtype\|type\|class\|kind\)\>"
syn match purescriptStructure "\<\(data\|newtype\|type\|kind\)\>"
\ nextgroup=purescriptType skipwhite
syn keyword purescriptStructure derive
syn keyword purescriptStructure instance
Expand All @@ -99,7 +111,7 @@ syn match purescriptInfix "^\(infix\|infixl\|infixr\)\>\s\+\([0-9]\+\)\s\+\(type

" Operators
syn match purescriptOperator "\([-!#$%&\*\+/<=>\?@\\^|~:]\|\<_\>\)"
syn match purescriptOperatorType "\(::\|∷\)"
syn match purescriptOperatorType "\%(\<instance\>.*\)\@40<!\(::\|∷\)"
\ nextgroup=purescriptForall,purescriptType skipwhite skipnl skipempty
syn match purescriptOperatorFunction "\(->\|<-\|[\\→←]\)"
syn match purescriptOperatorTypeSig "\(->\|<-\|=>\|<=\|::\|[∷∀→←⇒⇐]\)" contained
Expand Down Expand Up @@ -174,6 +186,8 @@ highlight def link purescriptLineComment purescriptComment
highlight def link purescriptBlockComment purescriptComment

" purescript general highlights
highlight def link purescriptClass purescriptKeyword
highlight def link purescriptClassName Type
highlight def link purescriptStructure purescriptKeyword
highlight def link purescriptKeyword Keyword
highlight def link purescriptStatement Statement
Expand Down