diff --git a/README.md b/README.md index 9af59f3..edc14bc 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo - [powershell](https://github.com/Persistent13/vim-ps1) (syntax, indent, ftplugin, ftdetect) - [protobuf](https://github.com/uarun/vim-protobuf) (syntax, ftdetect) - [puppet](https://github.com/voxpupuli/vim-puppet) (syntax, indent, ftplugin, ftdetect) +- [purescript](https://github.com/raichoo/purescript-vim) (syntax, indent, ftdetect) - [python](https://github.com/mitsuhiko/vim-python-combined) (syntax, indent) - [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin, ftdetect) - [r-lang](https://github.com/vim-scripts/R.vim) (syntax, ftplugin) diff --git a/build b/build index 99716c4..92923de 100755 --- a/build +++ b/build @@ -153,6 +153,7 @@ PACKS=" powershell:Persistent13/vim-ps1 protobuf:uarun/vim-protobuf puppet:voxpupuli/vim-puppet + purescript:raichoo/purescript-vim python:mitsuhiko/vim-python-combined qml:peterhoeg/vim-qml r-lang:vim-scripts/R.vim diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index afe8ce4..799b7c6 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -383,6 +383,11 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'puppet') == -1 au! BufRead,BufNewFile *.pp setfiletype puppet au! BufRead,BufNewFile Puppetfile setfiletype ruby endif +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'purescript') == -1 + +au BufNewFile,BufRead *.purs setf purescript +au FileType purescript let &l:commentstring='{--%s--}' +endif if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'qml') == -1 autocmd BufRead,BufNewFile *.qml setfiletype qml diff --git a/indent/purescript.vim b/indent/purescript.vim new file mode 100644 index 0000000..c456c60 --- /dev/null +++ b/indent/purescript.vim @@ -0,0 +1,141 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'purescript') == -1 + +" indentation for purescript +" +" Based on idris indentation +" +" author: raichoo (raichoo@googlemail.com) +" +" Modify g:purescript_indent_if and g:purescript_indent_case to +" change indentation for `if'(default 3) and `case'(default 5). +" Example (in .vimrc): +" > let g:purescript_indent_if = 2 + +if exists('b:did_indent') + finish +endif + +let b:did_indent = 1 + +if !exists('g:purescript_indent_if') + " if bool + " >>>then ... + " >>>else ... + let g:purescript_indent_if = 3 +endif + +if !exists('g:purescript_indent_case') + " case xs of + " >>>>>[] -> ... + " >>>>>(y:ys) -> ... + let g:purescript_indent_case = 5 +endif + +if !exists('g:purescript_indent_let') + " let x = 0 in + " >>>>x + let g:purescript_indent_let = 4 +endif + +if !exists('g:purescript_indent_where') + " where f :: Int -> Int + " >>>>>>f x = x + let g:purescript_indent_where = 6 +endif + +if !exists('g:purescript_indent_do') + " do x <- a + " >>>y <- b + let g:purescript_indent_do = 3 +endif + +setlocal indentexpr=GetPurescriptIndent() +setlocal indentkeys=!^F,o,O,},=where,=in + +function! GetPurescriptIndent() + let prevline = getline(v:lnum - 1) + let line = getline(v:lnum) + + if line =~ '^\s*\' + let s = match(prevline, '\S') + return s + 2 + endif + + if line =~ '^\s*\' + let n = v:lnum + let s = 0 + + while s <= 0 && n > 0 + let n = n - 1 + let s = match(getline(n),'\') + endwhile + + return s + 1 + endif + + if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$' + let s = match(prevline, '=') + if s > 0 + return s + 2 + endif + + let s = match(prevline, ':') + if s > 0 + return s + 3 + else + return match(prevline, '\S') + endif + endif + + if prevline =~ '[{([][^})\]]\+$' + return match(prevline, '[{([]') + endif + + if prevline =~ '\\s\+.\+\(\\)\?\s*$' + return match(prevline, '\') + g:purescript_indent_let + endif + + if prevline !~ '\' + let s = match(prevline, '\.*\&.*\zs\') + if s > 0 + return s + endif + + let s = match(prevline, '\') + if s > 0 + return s + g:purescript_indent_if + endif + endif + + if prevline =~ '\(\\|\\|=\|[{([]\)\s*$' + return match(prevline, '\S') + &shiftwidth + endif + + if prevline =~ '\\s\+\S\+.*$' + return match(prevline, '\') + g:purescript_indent_where + endif + + if prevline =~ '\\s\+\S\+.*$' + return match(prevline, '\') + g:purescript_indent_do + endif + + if prevline =~ '^\s*\\s\+[^=]\+\s\+=\s\+\S\+.*$' + return match(prevline, '=') + endif + + if prevline =~ '\\s\+.\+\\s*$' + return match(prevline, '\') + g:purescript_indent_case + endif + + if prevline =~ '^\s*\<\data\>\s\+\S\+\s*$' + return match(prevline, '\') + &shiftwidth + endif + + if (line =~ '^\s*}\s*' && prevline !~ '^\s*;') + return match(prevline, '\S') - &shiftwidth + endif + + return match(prevline, '\S') +endfunction + +endif diff --git a/syntax/purescript.vim b/syntax/purescript.vim new file mode 100644 index 0000000..298a300 --- /dev/null +++ b/syntax/purescript.vim @@ -0,0 +1,56 @@ +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 + +syn keyword purescriptModule module +syn keyword purescriptImport foreign import hiding +syn region purescriptQualifiedImport start="\" contains=purescriptType,purescriptDot end="\" +syn keyword purescriptStructure data newtype type class instance derive where +syn keyword purescriptStatement forall do case of let in +syn keyword purescriptConditional if then else +syn match purescriptNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>" +syn match purescriptFloat "\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>" +syn match purescriptDelimiter "[(),;[\]{}]" +syn keyword purescriptInfix infix infixl infixr +syn match purescriptOperators "\([-!#$%&\*\+/<=>\?@\\^|~:]\|\<_\>\)" +syn match purescriptDot "\." +syn match purescriptType "\<\([A-Z][a-zA-Z0-9_]*\|_|_\)\>" +syn match purescriptLineComment "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$" +syn match purescriptChar "'[^'\\]'\|'\\.'\|'\\u[0-9a-fA-F]\{4}'" +syn match purescriptBacktick "`[A-Za-z][A-Za-z0-9_]*`" +syn region purescriptString start=+"+ skip=+\\\\\|\\"+ end=+"+ +syn region purescriptMultilineString start=+"""+ end=+"""+ +syn region purescriptBlockComment start="{-" end="-}" contains=purescriptBlockComment + +highlight def link purescriptImport Structure +highlight def link purescriptQualifiedImport Structure +highlight def link purescriptModule Structure +highlight def link purescriptStructure Structure +highlight def link purescriptStatement Statement +highlight def link purescriptConditional Conditional +highlight def link purescriptNumber Number +highlight def link purescriptFloat Float +highlight def link purescriptDelimiter Delimiter +highlight def link purescriptInfix PreProc +highlight def link purescriptOperators Operator +highlight def link purescriptDot Operator +highlight def link purescriptType Include +highlight def link purescriptLineComment Comment +highlight def link purescriptBlockComment Comment +highlight def link purescriptString String +highlight def link purescriptMultilineString String +highlight def link purescriptChar String +highlight def link purescriptBacktick Operator + +let b:current_syntax = "purescript" + +endif