From 15046265597b7c1112cd27afc349017de712a340 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Tue, 15 Aug 2017 20:01:29 +0200 Subject: [PATCH 1/5] syntax * add purescriptClassDecl region - import class - class statement - higlight class keyword and class name * higlight instances Issues: #22, #23 --- syntax/purescript.vim | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/syntax/purescript.vim b/syntax/purescript.vim index c319638..c322e0c 100644 --- a/syntax/purescript.vim +++ b/syntax/purescript.vim @@ -19,13 +19,13 @@ syn keyword purescriptBoolean true false syn match purescriptDelimiter "[,;|.()[\]{}]" " Constructor -syn match purescriptConstructor "\<[A-Z]\w*\>" +syn match purescriptConstructor "\%(\" 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 "\%(\" contained \ containedin=purescriptTypeAlias \ nextgroup=purescriptType,purescriptTypeVar skipwhite syn match purescriptTypeVar "\<[_a-z]\(\w\|\'\)*\>" contained @@ -34,10 +34,21 @@ 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 purescriptFunction "\%(\" contained +" syn match purescriptFunction "\<[_a-z]\(\w\|\'\)*\>" contained +syn match purescriptFunction "(\%(\" 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 "\" @@ -45,7 +56,7 @@ 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 + \ contains=purescriptClassDecl,purescriptClass,purescriptClassName,purescriptDelimiter,purescriptType,purescriptTypeExport,purescriptFunction,purescriptStructure,purescriptModuleKeyword,@purescriptComment \ nextgroup=purescriptImportParams skipwhite " Import @@ -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 @@ -99,7 +111,8 @@ syn match purescriptInfix "^\(infix\|infixl\|infixr\)\>\s\+\([0-9]\+\)\s\+\(type " Operators syn match purescriptOperator "\([-!#$%&\*\+/<=>\?@\\^|~:]\|\<_\>\)" -syn match purescriptOperatorType "\(::\|∷\)" +syn match purescriptOperatorType "\%(\.*\)\@40\|<-\|[\\→←]\)" syn match purescriptOperatorTypeSig "\(->\|<-\|=>\|<=\|::\|[∷∀→←⇒⇐]\)" contained @@ -174,6 +187,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 From fa4ab2222117127623bcfb61319ebc74f1304570 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Tue, 15 Aug 2017 20:03:06 +0200 Subject: [PATCH 2/5] remove commented code --- syntax/purescript.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/syntax/purescript.vim b/syntax/purescript.vim index c322e0c..778261f 100644 --- a/syntax/purescript.vim +++ b/syntax/purescript.vim @@ -112,7 +112,6 @@ syn match purescriptInfix "^\(infix\|infixl\|infixr\)\>\s\+\([0-9]\+\)\s\+\(type " Operators syn match purescriptOperator "\([-!#$%&\*\+/<=>\?@\\^|~:]\|\<_\>\)" syn match purescriptOperatorType "\%(\.*\)\@40\|<-\|[\\→←]\)" syn match purescriptOperatorTypeSig "\(->\|<-\|=>\|<=\|::\|[∷∀→←⇒⇐]\)" contained From 41cacd07abbf0b5895d502c67e0bf74431bdce26 Mon Sep 17 00:00:00 2001 From: Coot Date: Tue, 22 Aug 2017 23:13:48 +0200 Subject: [PATCH 3/5] 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. --- indent/purescript.vim | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/indent/purescript.vim b/indent/purescript.vim index 3a38fc0..71e06da 100644 --- a/indent/purescript.vim +++ b/indent/purescript.vim @@ -108,10 +108,16 @@ function! GetPurescriptIndent() endif let s = match(prevline, '[[:alnum:][:blank:]]\@<=|[[:alnum:][:blank:]$]') - if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), "purescriptFunctionDecl") == -1 - " ident pattern quards but not if we are in a type declaration + if s >= 0 && prevline !~ '^class\>' && index(s:GetSynStack(v:lnum - 1, s), "purescriptFunctionDecl") == -1 + " ident pattern guards but not if we are in a type declaration " what we detect using syntax groups - return s + if prevline =~ '|\s*otherwise\>' + return indent(search('^\s*\k', 'bnW')) + " somehow this pattern does not work :/ + " return indent(search('^\(\s*|\)\@!', 'bnW')) + else + return s + endif endif let s = match(line, '\%(\\.\{-}\)\@<=->') @@ -165,10 +171,10 @@ function! GetPurescriptIndent() endif endif - if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$' + if prevline =~ '[!#$%&*+./<>?@\\^~-]\s*$' let s = match(prevline, '=') if s > 0 - return s + 2 + return s + &l:shiftwidth endif let s = match(prevline, '\<:\>') @@ -223,6 +229,10 @@ function! GetPurescriptIndent() return match(prevline, '\S') + (line !~ '^\s*[})]]' ? 0 : &l:shiftwidth) endif + if prevline =~ '^class' + return &l:shiftwidth + endif + let s = match(prevline, '\\s*$') if s >= 0 && index(s:GetSynStack(v:lnum - 1, s), 'purescriptString') == -1 return match(prevline, '\S') + g:purescript_indent_where From 871723b6877efed9a53451058f2c94b08ae667e3 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Thu, 19 Oct 2017 11:17:28 +0200 Subject: [PATCH 4/5] Fixed #48 --- syntax/purescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/purescript.vim b/syntax/purescript.vim index 778261f..9343b62 100644 --- a/syntax/purescript.vim +++ b/syntax/purescript.vim @@ -37,7 +37,7 @@ syn region purescriptTypeExport matchgroup=purescriptType start="\<[A-Z]\(\S\&[^ syn match purescriptFunction "\%(\" contained " syn match purescriptFunction "\<[_a-z]\(\w\|\'\)*\>" contained syn match purescriptFunction "(\%(\ Date: Thu, 19 Oct 2017 11:25:03 +0200 Subject: [PATCH 5/5] Fixed #49 --- syntax/purescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/purescript.vim b/syntax/purescript.vim index 9343b62..60f8c01 100644 --- a/syntax/purescript.vim +++ b/syntax/purescript.vim @@ -55,7 +55,7 @@ syn match purescriptModuleKeyword "\" syn match purescriptModule "^module\>\s\+\<\(\w\+\.\?\)*\>" \ contains=purescriptModuleKeyword,purescriptModuleName \ nextgroup=purescriptModuleParams skipwhite skipnl skipempty -syn region purescriptModuleParams start="(" end=")" fold contained keepend +syn region purescriptModuleParams start="(" skip="([^)]\{-})" end=")" fold contained keepend \ contains=purescriptClassDecl,purescriptClass,purescriptClassName,purescriptDelimiter,purescriptType,purescriptTypeExport,purescriptFunction,purescriptStructure,purescriptModuleKeyword,@purescriptComment \ nextgroup=purescriptImportParams skipwhite