Skip to content

Commit 227fe2e

Browse files
committed
Add vim config from rachitnigam/pyret-lang.vim.
1 parent 7b0c78e commit 227fe2e

File tree

8 files changed

+367
-46
lines changed

8 files changed

+367
-46
lines changed

tools/ctags/pyret.ctags

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--langdef=pyret
2+
--langmap=pyret:.arr
3+
4+
--regex-pyret=/^[ \t]*fun[ \t]+([a-zA-Z0-9_-]+)/\1/f,function/
5+
--regex-pyret=/^[ \t]*data[ \t]+([a-zA-Z0-9_-]+)/\1/d,data/
6+
--regex-pyret=/^[ \t]*\|[ \t]*([a-zA-Z0-9_-]+)[^=]*$/\1/d,data/
7+
--regex-pyret=/^[ \t]*\|[ \t]*([a-zA-Z0-9_-]+)[^=]*$/is-\1/d,data/
8+
--regex-pyret=/^([a-zA-Z0-9_-]+)[ \t]*=/\1/v,value/
9+
--regex-pyret=/^([a-zA-Z0-9_-]+)[ \t]*::[ \t]*[a-zA-Z0-9_<>}{. -]+[ \t]*=/\1/v,value/
10+
--regex-pyret=/^[ \t]*import[ \t]+[a-zA-Z0-9_-]+[ \t]+as[ \t]+([a-zA-Z0-9_-]+)/\1/i,import/
11+
--regex-pyret=/^[ \t]*import[ \t]+file\([^)]+\)[ \t]+as[ \t]+([a-zA-Z0-9_-]+)/\1/i,import/

tools/vim/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Pyret-lang.vim
2+
3+
This is a copy of the repository [rachitnigam/pyret-lang.vim](https://github.com/rachitnigam/pyret-lang.vim)
4+
as available on 08/31/2017.
5+
6+
### Installation
7+
For vim-plug, add the following:
8+
```
9+
Plug '<path-to-pyret-repo>/tools/vim'
10+
```
11+
12+
Install [UltiSnips](https://github.com/SirVer/ultisnips) for snippet support.

tools/vim/UltiSnips/pyret.snippets

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
snippet fun "fun ... end (fun)"
2+
fun ${1:function_name}(${2:arguments}):
3+
${VISUAL}$0
4+
end
5+
endsnippet
6+
7+
snippet meth "method ... end (meth)"
8+
meth ${1:method_name}(${2:arguments}):
9+
${VISUAL}$0
10+
end
11+
endsnippet
12+
13+
snippet lam "lam ... end (lam)"
14+
lam(${2:arguments}): ${VISUAL}$0 end
15+
endsnippet
16+
17+
snippet (lam "(lam ... end ((lam)"
18+
(lam(${2:arguments}): ${VISUAL}$0 end
19+
endsnippet
20+
21+
snippet ife "if ... else: ... end (ife)"
22+
if ${1:condition}:
23+
${VISUAL}$0
24+
else:
25+
${3:else_branch}
26+
end
27+
endsnippet
28+
29+
snippet cases "cases (type) ... end (cases)"
30+
cases(${1:type}) ${2:v}:
31+
| ${3:case1}
32+
end
33+
endsnippet
34+
35+
snippet for "for ... end (for)"
36+
for ${1:iterators}:
37+
${2:body}
38+
end
39+
endsnippet
40+
41+
snippet block "block ... end (block)"
42+
block:
43+
${VISUAL}$0
44+
end
45+
endsnippet
46+
47+
snippet data "data ... end (data)"
48+
data ${1:Type}:
49+
| ${2:Variant}
50+
end
51+
endsnippet
52+

tools/vim/ftdetect/pyret.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
au BufNewFile,BufRead *.arr set filetype=pyret

tools/vim/ftplugin/pyret.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if exists('b:did_ftplugin')
2+
finish
3+
endif
4+
5+
let b:did_ftplugin = 1
6+
7+
" Set comment string
8+
setlocal commentstring=#\ %s

tools/vim/indent/pyret.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
" Language: Pyret
33
" Maintainer: Dorai Sitaram, ds26gte.github.io
44
" Last Change: 2015-06-12
5+
" Originally from
6+
" https://github.com/brownplt/pyret-lang/blob/master/tools/vim/indent/pyret.vim
57

68
if exists("b:did_indent")
79
finish

tools/vim/syntax/pyret.vim

Lines changed: 176 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,191 @@
11
" Vim syntax file
22
" Language: Pyret
3-
" Maintainer: Joe Gibbs Politz ([email protected])
3+
" Maintainer: Rachit Nigam ([email protected])
44

55
if exists("b:current_syntax")
66
finish
77
endif
88

9+
syn case match
10+
syn sync minlines=200 maxlines=1000
11+
912
set iskeyword+=-
10-
set iskeyword+=:
1113

1214
syn match delimeter '!'
1315
syn match delimeter '\.'
14-
syn match delimeter '|'
15-
syn match delimeter '('
16-
syn match delimeter ')'
17-
syn match delimeter '->'
1816
syn match delimeter '='
19-
syn match delimeter '=>'
2017
syn match delimeter ':='
21-
22-
syn match delimeter '\['
23-
syn match delimeter '\]'
24-
syn match delimeter '{'
25-
syn match delimeter '}'
2618
syn match delimeter ':'
27-
syn match delimeter '::'
28-
29-
syn keyword basic var fun end with: sharing: data include import provide as try: except when
30-
syn keyword basic for from check: where: doc: and or not else: if else cases
31-
syn keyword basic is is== is=~ is<=> is-not is-not== is-not=~ is-not<=> raises
32-
syn keyword basic deriving ref graph: m-graph: block: satisfies violates shadow lam type type-let provide-types newtype
33-
syn keyword basic let rec letrec ask: table: extend using row: select extract order sieve by
34-
35-
syn match op ' + '
36-
syn match op ' - '
37-
syn match op ' / '
38-
syn match op ' * '
39-
syn match op ' > '
40-
syn match op ' < '
41-
syn match op ' >= '
42-
syn match op ' <= '
43-
syn match op ' <> '
44-
45-
syn match comment '\#.*$'
46-
syntax region comment start=/#|/ skip=/\./ end=/|#/
47-
48-
syntax region string start=/\v"/ skip=/\v\\./ end=/\v"/
49-
syntax region string start=/\v'/ skip=/\v\\./ end=/\v'/
50-
syntax region string start=/\v```/ skip=/\v\\./ end=/\v```/
51-
52-
syn match number "[0-9]+"
53-
54-
hi def link comment Comment
55-
hi def link basic Function
56-
hi def link delimeter PreProc
57-
hi def link op Label
58-
hi def link string Constant
59-
hi def link number Constant
60-
hi def link literal Constant
19+
20+
hi link delimeter PreProc
21+
22+
" Keywords
23+
syn keyword pyretKeyword var from shadow ref
24+
hi link pyretKeyword Special
25+
26+
" Imports and exports
27+
syn keyword pyretImport include import provide provide-types as
28+
hi link pyretImport PreProc
29+
30+
" Block structures in pyret
31+
syn keyword pyretBlock end for check examples
32+
syn keyword pyretBlock except when
33+
syn keyword pyretBlock if else
34+
syn keyword pyretBlock deriving satisfies
35+
syn keyword pyretBlock violates type-let
36+
syn keyword pyretBlock let rec letrec extend using select
37+
syn keyword pyretBlock extract order sieve by raises newtype
38+
hi link pyretBlock Function
39+
40+
" Built-in functions
41+
syn keyword pyretBuiltin is is== is=~ is<=> is-not is-not== is-not=~ is-not<=>
42+
syn keyword pyretBuiltin and or not
43+
syn keyword pyretBuiltin torepr to-repr tostring to-string raise
44+
syn keyword pyretBuiltin is-boolean is-number is-string is-raw-array is-nothing
45+
syn keyword pyretBuiltin is-function is-object
46+
hi link pyretBuiltin Constant
47+
48+
" Operators
49+
syn match pyretOperator '+'
50+
syn match pyretOperator '-'
51+
syn match pyretOperator '/'
52+
syn match pyretOperator '*'
53+
syn match pyretOperator '>'
54+
syn match pyretOperator '<'
55+
syn match pyretOperator '>='
56+
syn match pyretOperator '<='
57+
syn match pyretOperator '<>'
58+
syn match pyretOperator '\^'
59+
hi link pyretOperator Label
60+
61+
" Comments
62+
syn match pyretComment '\#.*$' contains=pyretTodo
63+
syntax region pyretComment start=/#|/ skip=/\./ end=/|#/ contains=pyretTodo
64+
hi link pyretComment Comment
65+
66+
" Todo
67+
syn match pyretTodo /\v<(TODO|FIXME|NOTE)>/ contained
68+
hi link pyretTodo Todo
69+
70+
" Strings
71+
syn region pyretString start=/\v"/ skip=/\v\\./ end=/\v("|$)/
72+
syn region pyretString start=/\v'/ skip=/\v\\./ end=/\v('|$)/
73+
syn region pyretString start=/\v```/ skip=/\v\\./ end=/\v```/
74+
hi link pyretString String
75+
syn match pyretEscapedChar '\v\\.' containedin=pyretString contained
76+
hi link pyretEscapedChar Special
77+
78+
" Numbers
79+
syn match pyretConstant "\v(\-|\+)?[0-9]+(\.[0-9]+)?(e[0-9]+)?"
80+
" Booleans
81+
syn keyword pyretConstant true
82+
syn keyword pyretConstant false
83+
" nothing
84+
syn keyword pyretConstant nothing
85+
86+
hi link pyretConstant Constant
87+
88+
" Template
89+
syntax match pyretTemplate '\v\.\.\.'
90+
hi link pyretTemplate ERROR
91+
92+
" Variable names in pyret. Need to be higher priority than numbers
93+
syn match pyretName '\v[_a-zA-Z]((\-+)?[_a-zA-Z0-9]+)*'
94+
\ nextgroup=pyretColonColon skipwhite
95+
syn match pyretColonColon '::' nextgroup=@pyretAnn skipwhite
96+
hi link pyretColonColon Keyword
97+
98+
" Keywords ending with :. Need to be after variables.
99+
syn match pyretBlock 'with:'
100+
syn match pyretBlock 'sharing:'
101+
syn match pyretBlock 'try:'
102+
syn match pyretBlock 'check:'
103+
syn match pyretBlock 'where:'
104+
syn match pyretBlock 'doc:'
105+
syn match pyretBlock 'else:'
106+
syn match pyretBlock 'graph:'
107+
syn match pyretBlock 'block:'
108+
syn match pyretBlock 'ask:'
109+
syn match pyretBlock 'table:'
110+
syn match pyretBlock 'row:'
111+
syn match pyretBlock 'm-graph:'
112+
113+
" Variables bound by `from`
114+
syn match pyretFromName '\v[_a-zA-Z]((\-+)?[_a-zA-Z0-9]+)*\ze(\s+::\s+\S+)?\s+from'
115+
hi link pyretFromName Identifier
116+
117+
" Type Annotations
118+
syn cluster pyretAnn
119+
\ contains=pyretSimpleAnn,pyretComplexAnn,pyretRecordAnn,pyretParenAnn,pyretAnnDot
120+
121+
syn region pyretComplexAnn matchgroup=Keyword start='\v\<' end='\v\>'
122+
\ contained contains=@pyretAnn nextgroup=pyretAnnArrow,pyretRefineStart skipwhite
123+
hi link pyretComplexAnn Type
124+
125+
syn match pyretSimpleAnn '\v%((\w+-\w+)|\w+)' contained
126+
\ nextgroup=pyretComplexAnn,pyretAnnArrow,pyretAnnDot,pyretRefineStart skipwhite
127+
hi link pyretSimpleAnn Type
128+
129+
syn match pyretRefineStart '\v\%' contained nextgroup=pyretRefineAnn
130+
hi link pyretRefineStart Keyword
131+
132+
syn region pyretRefineAnn matchgroup=Keyword start='\v\(' end='\v\)' contained
133+
\ contains=pyretName nextgroup=pyretAnnArrow skipwhite
134+
135+
syn match pyretAnnDot '\.' contained nextgroup=pyretSimpleAnn
136+
hi link pyretAnnDot Keyword
137+
138+
syn region pyretRecordAnn matchgroup=Keyword start='\v\{' end='\v\}' contained
139+
\ contains=@pyretAnn,pyretSemicolon nextgroup=pyretAnnArrow skipwhite
140+
hi link pyretRecordAnn Type
141+
142+
syn match pyretSemicolon ';' contained
143+
hi link pyretSemicolon Keyword
144+
145+
syn region pyretParenAnn matchgroup=Keyword start='\v\(' end='\v\)' contained
146+
\ contains=@pyretAnn skipwhite
147+
hi link pyretParenAnn Type
148+
149+
syn match pyretAnnArrow '\v-\>' contained nextgroup=@pyretAnn skipwhite
150+
hi link pyretAnnArrow Keyword
151+
152+
" `type` expressions
153+
syn region pyretTypeDecl matchgroup=Keyword start='\v<type>' end='\v$'
154+
\ contains=@pyretAnn,pyretComment skipwhite keepend
155+
156+
" fun defintions
157+
syn keyword pyretBlock fun method nextgroup=pyretFunName skipwhite
158+
syn keyword pyretBlock lam nextgroup=pyretArgs,pyretFunTypeParam skipwhite
159+
syn match pyretFunComma ',' contained
160+
hi link pyretFunComma Special
161+
162+
syn match pyretFunName '\v[_a-zA-Z]((\-+)?[_a-zA-Z0-9]+)*' contained
163+
\ nextgroup=pyretArgs,pyretFunTypeParam skipwhite
164+
hi link pyretFunName Constant
165+
166+
syn region pyretFunTypeParam matchgroup=Keyword start='\v\<' end='\v\>'
167+
\ contained contains=@pyretAnn nextgroup=pyretArgs skipwhite
168+
hi link pyretFunTypeParam Type
169+
170+
syn region pyretArgs matchgroup=Keyword start='\v\(' end='\v\)'
171+
\ contained contains=pyretArgName,pyretFunComma,pyretKeyword,pyretComment
172+
\ nextgroup=pyretAnnArrow skipwhite
173+
hi link pyretArgs Identifier
174+
175+
syn match pyretArgName '\v[_a-zA-Z]((\-+)?[_a-zA-Z0-9]+)*' contained transparent
176+
\ nextgroup=pyretColonColon skipwhite
177+
178+
" cases using |
179+
syn match pyretBar '\v\|' nextgroup=pyretFunName skipwhite
180+
hi link pyretBar Keyword
181+
syn match pyretCaseArrow '\v\=\>'
182+
hi link pyretCaseArrow Keyword
183+
184+
" Data defintions
185+
syn keyword pyretBlock data nextgroup=pyretSimpleAnn skipwhite
186+
187+
" cases keyword
188+
syn keyword pyretBlock cases nextgroup=pyretCaseType skipwhite
189+
syn region pyretCaseType matchgroup=Keyword start='\v\(' end='\v\)'
190+
\ contained contains=@pyretAnn skipwhite
61191

0 commit comments

Comments
 (0)