Skip to content

Commit

Permalink
Add vim config from rachitnigam/pyret-lang.vim.
Browse files Browse the repository at this point in the history
  • Loading branch information
rachitnigam committed Aug 31, 2017
1 parent 7b0c78e commit 227fe2e
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 46 deletions.
11 changes: 11 additions & 0 deletions tools/ctags/pyret.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--langdef=pyret
--langmap=pyret:.arr

--regex-pyret=/^[ \t]*fun[ \t]+([a-zA-Z0-9_-]+)/\1/f,function/
--regex-pyret=/^[ \t]*data[ \t]+([a-zA-Z0-9_-]+)/\1/d,data/
--regex-pyret=/^[ \t]*\|[ \t]*([a-zA-Z0-9_-]+)[^=]*$/\1/d,data/
--regex-pyret=/^[ \t]*\|[ \t]*([a-zA-Z0-9_-]+)[^=]*$/is-\1/d,data/
--regex-pyret=/^([a-zA-Z0-9_-]+)[ \t]*=/\1/v,value/
--regex-pyret=/^([a-zA-Z0-9_-]+)[ \t]*::[ \t]*[a-zA-Z0-9_<>}{. -]+[ \t]*=/\1/v,value/
--regex-pyret=/^[ \t]*import[ \t]+[a-zA-Z0-9_-]+[ \t]+as[ \t]+([a-zA-Z0-9_-]+)/\1/i,import/
--regex-pyret=/^[ \t]*import[ \t]+file\([^)]+\)[ \t]+as[ \t]+([a-zA-Z0-9_-]+)/\1/i,import/
12 changes: 12 additions & 0 deletions tools/vim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Pyret-lang.vim

This is a copy of the repository [rachitnigam/pyret-lang.vim](https://github.com/rachitnigam/pyret-lang.vim)
as available on 08/31/2017.

### Installation
For vim-plug, add the following:
```
Plug '<path-to-pyret-repo>/tools/vim'
```

Install [UltiSnips](https://github.com/SirVer/ultisnips) for snippet support.
52 changes: 52 additions & 0 deletions tools/vim/UltiSnips/pyret.snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
snippet fun "fun ... end (fun)"
fun ${1:function_name}(${2:arguments}):
${VISUAL}$0
end
endsnippet

snippet meth "method ... end (meth)"
meth ${1:method_name}(${2:arguments}):

This comment has been minimized.

Copy link
@blerner

blerner Sep 1, 2017

Member

If I'm reading this right, the inserted keyword should be method

This comment has been minimized.

Copy link
@rachitnigam

rachitnigam Sep 1, 2017

Author Member

Correct. This is a mistake, I'll fix it.

${VISUAL}$0
end
endsnippet

snippet lam "lam ... end (lam)"
lam(${2:arguments}): ${VISUAL}$0 end
endsnippet

snippet (lam "(lam ... end ((lam)"
(lam(${2:arguments}): ${VISUAL}$0 end

This comment has been minimized.

Copy link
@blerner

blerner Sep 1, 2017

Member

Unbalanced parentheses?

This comment has been minimized.

Copy link
@rachitnigam

rachitnigam Sep 1, 2017

Author Member

No, this is supposed to work with automatic parent balancing. So you write () and then inside it, start writing Lam and then expand it.

endsnippet

snippet ife "if ... else: ... end (ife)"
if ${1:condition}:
${VISUAL}$0
else:
${3:else_branch}
end
endsnippet

snippet cases "cases (type) ... end (cases)"
cases(${1:type}) ${2:v}:
| ${3:case1}
end
endsnippet

snippet for "for ... end (for)"
for ${1:iterators}:

This comment has been minimized.

Copy link
@blerner

blerner Sep 1, 2017

Member

Missing parentheses around the iterators section?

${2:body}
end
endsnippet

snippet block "block ... end (block)"
block:
${VISUAL}$0
end
endsnippet

snippet data "data ... end (data)"
data ${1:Type}:
| ${2:Variant}
end
endsnippet

1 change: 1 addition & 0 deletions tools/vim/ftdetect/pyret.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
au BufNewFile,BufRead *.arr set filetype=pyret
8 changes: 8 additions & 0 deletions tools/vim/ftplugin/pyret.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if exists('b:did_ftplugin')
finish
endif

let b:did_ftplugin = 1

" Set comment string
setlocal commentstring=#\ %s
2 changes: 2 additions & 0 deletions tools/vim/indent/pyret.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
" Language: Pyret
" Maintainer: Dorai Sitaram, ds26gte.github.io
" Last Change: 2015-06-12
" Originally from
" https://github.com/brownplt/pyret-lang/blob/master/tools/vim/indent/pyret.vim

if exists("b:did_indent")
finish
Expand Down
222 changes: 176 additions & 46 deletions tools/vim/syntax/pyret.vim
Original file line number Diff line number Diff line change
@@ -1,61 +1,191 @@
" Vim syntax file
" Language: Pyret
" Maintainer: Joe Gibbs Politz ([email protected])
" Maintainer: Rachit Nigam ([email protected])

if exists("b:current_syntax")
finish
endif

syn case match
syn sync minlines=200 maxlines=1000

set iskeyword+=-
set iskeyword+=:

syn match delimeter '!'
syn match delimeter '\.'
syn match delimeter '|'
syn match delimeter '('
syn match delimeter ')'
syn match delimeter '->'
syn match delimeter '='
syn match delimeter '=>'
syn match delimeter ':='

syn match delimeter '\['
syn match delimeter '\]'
syn match delimeter '{'
syn match delimeter '}'
syn match delimeter ':'
syn match delimeter '::'

syn keyword basic var fun end with: sharing: data include import provide as try: except when
syn keyword basic for from check: where: doc: and or not else: if else cases
syn keyword basic is is== is=~ is<=> is-not is-not== is-not=~ is-not<=> raises
syn keyword basic deriving ref graph: m-graph: block: satisfies violates shadow lam type type-let provide-types newtype
syn keyword basic let rec letrec ask: table: extend using row: select extract order sieve by

syn match op ' + '
syn match op ' - '
syn match op ' / '
syn match op ' * '
syn match op ' > '
syn match op ' < '
syn match op ' >= '
syn match op ' <= '
syn match op ' <> '

syn match comment '\#.*$'
syntax region comment start=/#|/ skip=/\./ end=/|#/

syntax region string start=/\v"/ skip=/\v\\./ end=/\v"/
syntax region string start=/\v'/ skip=/\v\\./ end=/\v'/
syntax region string start=/\v```/ skip=/\v\\./ end=/\v```/

syn match number "[0-9]+"

hi def link comment Comment
hi def link basic Function
hi def link delimeter PreProc
hi def link op Label
hi def link string Constant
hi def link number Constant
hi def link literal Constant

hi link delimeter PreProc

" Keywords
syn keyword pyretKeyword var from shadow ref
hi link pyretKeyword Special

" Imports and exports
syn keyword pyretImport include import provide provide-types as
hi link pyretImport PreProc

" Block structures in pyret
syn keyword pyretBlock end for check examples
syn keyword pyretBlock except when
syn keyword pyretBlock if else
syn keyword pyretBlock deriving satisfies
syn keyword pyretBlock violates type-let
syn keyword pyretBlock let rec letrec extend using select
syn keyword pyretBlock extract order sieve by raises newtype
hi link pyretBlock Function

" Built-in functions
syn keyword pyretBuiltin is is== is=~ is<=> is-not is-not== is-not=~ is-not<=>
syn keyword pyretBuiltin and or not
syn keyword pyretBuiltin torepr to-repr tostring to-string raise
syn keyword pyretBuiltin is-boolean is-number is-string is-raw-array is-nothing
syn keyword pyretBuiltin is-function is-object
hi link pyretBuiltin Constant

" Operators
syn match pyretOperator '+'
syn match pyretOperator '-'
syn match pyretOperator '/'
syn match pyretOperator '*'
syn match pyretOperator '>'
syn match pyretOperator '<'
syn match pyretOperator '>='
syn match pyretOperator '<='
syn match pyretOperator '<>'
syn match pyretOperator '\^'
hi link pyretOperator Label

" Comments
syn match pyretComment '\#.*$' contains=pyretTodo
syntax region pyretComment start=/#|/ skip=/\./ end=/|#/ contains=pyretTodo
hi link pyretComment Comment

" Todo
syn match pyretTodo /\v<(TODO|FIXME|NOTE)>/ contained
hi link pyretTodo Todo

" Strings
syn region pyretString start=/\v"/ skip=/\v\\./ end=/\v("|$)/
syn region pyretString start=/\v'/ skip=/\v\\./ end=/\v('|$)/
syn region pyretString start=/\v```/ skip=/\v\\./ end=/\v```/
hi link pyretString String
syn match pyretEscapedChar '\v\\.' containedin=pyretString contained
hi link pyretEscapedChar Special

" Numbers
syn match pyretConstant "\v(\-|\+)?[0-9]+(\.[0-9]+)?(e[0-9]+)?"
" Booleans
syn keyword pyretConstant true
syn keyword pyretConstant false
" nothing
syn keyword pyretConstant nothing

hi link pyretConstant Constant

" Template
syntax match pyretTemplate '\v\.\.\.'
hi link pyretTemplate ERROR

" Variable names in pyret. Need to be higher priority than numbers
syn match pyretName '\v[_a-zA-Z]((\-+)?[_a-zA-Z0-9]+)*'
\ nextgroup=pyretColonColon skipwhite
syn match pyretColonColon '::' nextgroup=@pyretAnn skipwhite
hi link pyretColonColon Keyword

" Keywords ending with :. Need to be after variables.
syn match pyretBlock 'with:'
syn match pyretBlock 'sharing:'
syn match pyretBlock 'try:'
syn match pyretBlock 'check:'
syn match pyretBlock 'where:'
syn match pyretBlock 'doc:'
syn match pyretBlock 'else:'
syn match pyretBlock 'graph:'
syn match pyretBlock 'block:'
syn match pyretBlock 'ask:'
syn match pyretBlock 'table:'
syn match pyretBlock 'row:'
syn match pyretBlock 'm-graph:'

" Variables bound by `from`
syn match pyretFromName '\v[_a-zA-Z]((\-+)?[_a-zA-Z0-9]+)*\ze(\s+::\s+\S+)?\s+from'
hi link pyretFromName Identifier

" Type Annotations
syn cluster pyretAnn
\ contains=pyretSimpleAnn,pyretComplexAnn,pyretRecordAnn,pyretParenAnn,pyretAnnDot

syn region pyretComplexAnn matchgroup=Keyword start='\v\<' end='\v\>'
\ contained contains=@pyretAnn nextgroup=pyretAnnArrow,pyretRefineStart skipwhite
hi link pyretComplexAnn Type

syn match pyretSimpleAnn '\v%((\w+-\w+)|\w+)' contained
\ nextgroup=pyretComplexAnn,pyretAnnArrow,pyretAnnDot,pyretRefineStart skipwhite
hi link pyretSimpleAnn Type

syn match pyretRefineStart '\v\%' contained nextgroup=pyretRefineAnn
hi link pyretRefineStart Keyword

syn region pyretRefineAnn matchgroup=Keyword start='\v\(' end='\v\)' contained
\ contains=pyretName nextgroup=pyretAnnArrow skipwhite

syn match pyretAnnDot '\.' contained nextgroup=pyretSimpleAnn
hi link pyretAnnDot Keyword

syn region pyretRecordAnn matchgroup=Keyword start='\v\{' end='\v\}' contained
\ contains=@pyretAnn,pyretSemicolon nextgroup=pyretAnnArrow skipwhite
hi link pyretRecordAnn Type

syn match pyretSemicolon ';' contained
hi link pyretSemicolon Keyword

syn region pyretParenAnn matchgroup=Keyword start='\v\(' end='\v\)' contained
\ contains=@pyretAnn skipwhite
hi link pyretParenAnn Type

syn match pyretAnnArrow '\v-\>' contained nextgroup=@pyretAnn skipwhite
hi link pyretAnnArrow Keyword

" `type` expressions
syn region pyretTypeDecl matchgroup=Keyword start='\v<type>' end='\v$'
\ contains=@pyretAnn,pyretComment skipwhite keepend

" fun defintions
syn keyword pyretBlock fun method nextgroup=pyretFunName skipwhite
syn keyword pyretBlock lam nextgroup=pyretArgs,pyretFunTypeParam skipwhite
syn match pyretFunComma ',' contained
hi link pyretFunComma Special

syn match pyretFunName '\v[_a-zA-Z]((\-+)?[_a-zA-Z0-9]+)*' contained
\ nextgroup=pyretArgs,pyretFunTypeParam skipwhite
hi link pyretFunName Constant

syn region pyretFunTypeParam matchgroup=Keyword start='\v\<' end='\v\>'
\ contained contains=@pyretAnn nextgroup=pyretArgs skipwhite
hi link pyretFunTypeParam Type

syn region pyretArgs matchgroup=Keyword start='\v\(' end='\v\)'
\ contained contains=pyretArgName,pyretFunComma,pyretKeyword,pyretComment
\ nextgroup=pyretAnnArrow skipwhite
hi link pyretArgs Identifier

syn match pyretArgName '\v[_a-zA-Z]((\-+)?[_a-zA-Z0-9]+)*' contained transparent
\ nextgroup=pyretColonColon skipwhite

" cases using |
syn match pyretBar '\v\|' nextgroup=pyretFunName skipwhite
hi link pyretBar Keyword
syn match pyretCaseArrow '\v\=\>'
hi link pyretCaseArrow Keyword

" Data defintions
syn keyword pyretBlock data nextgroup=pyretSimpleAnn skipwhite

" cases keyword
syn keyword pyretBlock cases nextgroup=pyretCaseType skipwhite
syn region pyretCaseType matchgroup=Keyword start='\v\(' end='\v\)'
\ contained contains=@pyretAnn skipwhite

Loading

0 comments on commit 227fe2e

Please sign in to comment.