Skip to content

Commit ece34d9

Browse files
author
Marcin Szamotulski
authored
Syntax issues (#35)
* syntax * add purescriptClassDecl region - import class - class statement - higlight class keyword and class name * higlight instances Issues: #22, #23 * remove commented code * Indent (#44) * indent class and remove '|' from operator characters If '|' was included then there is extra indent in ``` class RowLacking (entry :: Type) (key :: Symbol) (typ :: Type) (row :: # Type) | >> entry typ -> key row ``` * indent pattern guards * guard against class * if the previous line contains `| otherwise` find the first line that does not start with `|` (actually find the first line that starts with `\k`, '^\%(\s*|\)\@!' did not work inside indent function for some reason. * Fixed #48 * Fixed #49
1 parent 517d9de commit ece34d9

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

syntax/purescript.vim

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ syn keyword purescriptBoolean true false
1919
syn match purescriptDelimiter "[,;|.()[\]{}]"
2020

2121
" Constructor
22-
syn match purescriptConstructor "\<[A-Z]\w*\>"
22+
syn match purescriptConstructor "\%(\<class\s\+\)\@15<!\<[A-Z]\w*\>"
2323
syn region purescriptConstructorDecl matchgroup=purescriptConstructor start="\<[A-Z]\w*\>" end="\(|\|$\)"me=e-1,re=e-1 contained
2424
\ containedin=purescriptData,purescriptNewtype
2525
\ contains=purescriptType,purescriptTypeVar,purescriptDelimiter,purescriptOperatorType,purescriptOperatorTypeSig,@purescriptComment
2626

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

3636
" Function
37-
syn match purescriptFunction "\<[_a-z]\(\w\|\'\)*\>" contained
38-
syn match purescriptFunction "(\(\W\&[^(),\"]\)\+)" contained extend
39-
syn match purescriptBacktick "`[_A-Za-z][A-Za-z0-9_]*`"
37+
syn match purescriptFunction "\%(\<instance\s\+\|\<class\s\+\)\@18<!\<[_a-z]\(\w\|\'\)*\>" contained
38+
" syn match purescriptFunction "\<[_a-z]\(\w\|\'\)*\>" contained
39+
syn match purescriptFunction "(\%(\<class\s\+\)\@18<!\(\W\&[^(),\"]\)\+)" contained extend
40+
syn match purescriptBacktick "`[_A-Za-z][A-Za-z0-9_\.]*`"
41+
42+
" Class
43+
syn region purescriptClassDecl start="^\%(\s*\)class\>"ms=e-5 end="\<where\>\|$"
44+
\ contains=purescriptClass,purescriptClassName,purescriptOperatorType,purescriptOperator,purescriptType,purescriptWhere
45+
\ nextgroup=purescriptClass
46+
\ skipnl
47+
syn match purescriptClass "\<class\>" containedin=purescriptClassDecl contained
48+
\ nextgroup=purescriptClassName
49+
\ skipnl
50+
syn match purescriptClassName "\<[A-Z]\w*\>" containedin=purescriptClassDecl contained
4051

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

5162
" Import
@@ -84,8 +95,9 @@ syn match purescriptForall "∀"
8495
syn keyword purescriptConditional if then else
8596
syn keyword purescriptStatement do case of in
8697
syn keyword purescriptLet let
98+
" syn keyword purescriptClass class
8799
syn keyword purescriptWhere where
88-
syn match purescriptStructure "\<\(data\|newtype\|type\|class\|kind\)\>"
100+
syn match purescriptStructure "\<\(data\|newtype\|type\|kind\)\>"
89101
\ nextgroup=purescriptType skipwhite
90102
syn keyword purescriptStructure derive
91103
syn keyword purescriptStructure instance
@@ -99,7 +111,7 @@ syn match purescriptInfix "^\(infix\|infixl\|infixr\)\>\s\+\([0-9]\+\)\s\+\(type
99111

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

176188
" purescript general highlights
189+
highlight def link purescriptClass purescriptKeyword
190+
highlight def link purescriptClassName Type
177191
highlight def link purescriptStructure purescriptKeyword
178192
highlight def link purescriptKeyword Keyword
179193
highlight def link purescriptStatement Statement

0 commit comments

Comments
 (0)