Skip to content

Commit 76d23a2

Browse files
committed
Add cryptol syntax, closes sheerun#107
1 parent 5dd1a7e commit 76d23a2

File tree

6 files changed

+197
-0
lines changed

6 files changed

+197
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
3333
- [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin)
3434
- [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin, ftdetect)
3535
- [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
36+
- [cryptol](https://github.com/victoredwardocallaghan/cryptol.vim) (syntax, compiler, ftplugin, ftdetect)
3637
- [cql](https://github.com/elubow/cql-vim) (syntax, ftdetect)
3738
- [css](https://github.com/JulesWang/css.vim) (syntax)
3839
- [cucumber](https://github.com/tpope/vim-cucumber) (syntax, indent, compiler, ftplugin, ftdetect)

build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ PACKS="
104104
cjsx:mtscout6/vim-cjsx
105105
clojure:guns/vim-clojure-static
106106
coffee-script:kchmck/vim-coffee-script
107+
cryptol:victoredwardocallaghan/cryptol.vim
107108
cql:elubow/cql-vim
108109
css:JulesWang/css.vim
109110
cucumber:tpope/vim-cucumber

compiler/cryptol.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
2+
3+
" Vim compiler file
4+
" Compiler: Cryptol version 1.8.19-academic Compiler
5+
" Maintainer: Edward O'Callaghan <victoredwardocallaghan AT gmail DOT com>
6+
" Latest Revision: 25-Apr-2013
7+
8+
if exists("current_compiler")
9+
finish
10+
endif
11+
let current_compiler = "cryptol"
12+
13+
if exists(":CompilerSet") != 2
14+
command = -nargs =* CompilerSet setlocal <args>
15+
endif
16+
17+
" TODO: Work out errorformat for the Cryptol compiler, see
18+
" :help errorformat
19+
CompilerSet errorformat& " use the default 'errorformat'
20+
21+
" "%<" means the current file name without extension.
22+
CompilerSet makeprg=cryptol\ -o\ %<\ %
23+
24+
endif

ftdetect/polyglot.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ if has("autocmd")
5353
au BufNewFile,BufRead *.cql set filetype=cql
5454
endif
5555
endif
56+
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
57+
58+
au! BufRead,BufNewFile *.cry set filetype=cryptol
59+
au! BufRead,BufNewFile *.cyl set filetype=cryptol
60+
au! BufRead,BufNewFile *.lcry set filetype=cryptol
61+
au! BufRead,BufNewFile *.lcyl set filetype=cryptol
62+
endif
5663
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cucumber') == -1
5764

5865
autocmd BufNewFile,BufReadPost *.feature,*.story set filetype=cucumber

ftplugin/cryptol/folding.vim

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
2+
3+
" Copyright © 2013 Edward O'Callaghan. All Rights Reserved.
4+
5+
"setlocal foldmethod=indent
6+
"setlocal foldignore=
7+
8+
setlocal foldmethod=expr
9+
setlocal foldexpr=GetPotionFold(v:lnum)
10+
11+
" Helper function: To tackle non-blank lines,
12+
" wish to know their indentation level
13+
function! IndentLevel(lnum)
14+
return indent(a:lnum) / &shiftwidth
15+
endfunction
16+
17+
" Helper function: .
18+
function! NextNonBlankLine(lnum)
19+
let numlines = line('$')
20+
let current = a:lnum + 1
21+
22+
while current <= numlines
23+
if getline(current) =~? '\v\S'
24+
return current
25+
endif
26+
27+
let current += 1
28+
endwhile
29+
30+
return -2
31+
endfunction
32+
33+
function! GetPotionFold(lnum)
34+
if getline(a:lnum) =~? '\v^\s*$'
35+
return '-1'
36+
endif
37+
38+
let this_indent = IndentLevel(a:lnum)
39+
let next_indent = IndentLevel(NextNonBlankLine(a:lnum))
40+
41+
if next_indent == this_indent
42+
return this_indent
43+
elseif next_indent < this_indent
44+
return this_indent
45+
elseif next_indent > this_indent
46+
return '>' . next_indent
47+
endif
48+
endfunction
49+
50+
endif

syntax/cryptol.vim

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
2+
3+
" Vim syntax file
4+
" Language: Cryptol
5+
" Maintainer: Fergus Henderson
6+
" Last Change: Thu Feb 10 13:14:24 PST 2005
7+
"
8+
9+
" Remove any old syntax stuff hanging around
10+
if version < 600
11+
syn clear
12+
elseif exists("b:current_syntax")
13+
finish
14+
endif
15+
16+
set expandtab
17+
set list lcs=tab:>-,trail:.
18+
19+
" (Qualified) identifiers (no default highlighting)
20+
" XXX copied from Haskell
21+
syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[A-Z][a-zA-Z0-9_']*\>"
22+
syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[a-z][a-zA-Z0-9_']*\>"
23+
24+
" Infix operators--most punctuation characters and any (qualified) identifier
25+
" enclosed in `backquotes`. An operator starting with : is a constructor,
26+
" others are variables (e.g. functions).
27+
" XXX copied from Haskell
28+
syn match cryVarSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[-!#$%&\*\+/<=>\?@\\^|~.][-!#$%&\*\+/<=>\?@\\^|~:.]*"
29+
syn match cryConSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=:[-!#$%&\*\+./<=>\?@\\^|~:]*"
30+
syn match cryVarSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[a-z][a-zA-Z0-9_']*`"
31+
syn match cryConSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[A-Z][a-zA-Z0-9_']*`"
32+
33+
" Reserved symbols
34+
syn match cryDelimiter "(\|)\|\[|\||]\|||\|\[\|\]\|,\|;\|{\|}"
35+
36+
" Strings and constants
37+
" XXX Copied from Haskell
38+
syn match crySpecialChar contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)"
39+
syn match crySpecialChar contained "\\\(NUL\|SOH\|STX\|ETX\|EOT\|ENQ\|ACK\|BEL\|BS\|HT\|LF\|VT\|FF\|CR\|SO\|SI\|DLE\|DC1\|DC2\|DC3\|DC4\|NAK\|SYN\|ETB\|CAN\|EM\|SUB\|ESC\|FS\|GS\|RS\|US\|SP\|DEL\)"
40+
syn match crySpecialCharError contained "\\&\|'''\+"
41+
syn region cryString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=crySpecialChar
42+
syn region cryString start=+``+ skip=+\\\\\|\\"+ end=+``+ contains=hsSpecialChar
43+
syn match cryCharacter "[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=crySpecialChar,crySpecialCharError
44+
syn match cryCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=crySpecialChar,crySpecialCharError
45+
syn match cryNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>"
46+
47+
" Keyword definitions.
48+
49+
syn keyword cryInclude include
50+
syn keyword cryConditional if then else
51+
syn keyword cryWhere where
52+
syn keyword cryTypeSyn type
53+
syn keyword cryPragma pragma
54+
syn keyword cryProp extern theorem proof forall codeGen Cpp Haskell SMT Isabelle axioms
55+
syn keyword cryType Bit inf
56+
57+
" Primitives
58+
syn keyword cryBoolean False True
59+
syn keyword cryPrimitive zero undefined
60+
syn keyword cryPrimitive error parity lg2 pmod pdiv pmult format
61+
syn keyword cryPrimitive join split groupBy take drop min max negate reverse
62+
syn keyword cryPrimitive project tail width
63+
syn keyword cryPrimitive ASSERT
64+
65+
" Comments
66+
syn match cryLineComment "//.*"
67+
syn region cryBlockComment start="/\*" end="\*/" contains=cryBlockComment
68+
69+
if !exists("cry_minlines")
70+
let cry_minlines = 50
71+
endif
72+
exec "syn sync lines=" . cry_minlines
73+
74+
if version >= 508 || !exists("did_cry_syntax_inits")
75+
if version < 508
76+
let did_cry_syntax_inits = 1
77+
command -nargs=+ HiLink hi link <args>
78+
else
79+
command -nargs=+ HiLink hi def link <args>
80+
endif
81+
82+
hi link cryInclude Include
83+
hi link cryTypeSyn Keyword
84+
hi link cryImportMod cryImport
85+
hi link cryConditional Conditional
86+
hi link crySpecialChar SpecialChar
87+
hi link cryTypedef Typedef
88+
hi link cryPragma Keyword
89+
hi link cryVarSym cryOperator
90+
hi link cryConSym cryOperator
91+
hi link cryOperator Operator
92+
hi link cryDelimiter Delimiter
93+
hi link crySpecialCharError Error
94+
hi link cryString String
95+
hi link cryCharacter Character
96+
hi link cryNumber Number
97+
hi link cryConditional Conditional
98+
hi link cryWhere Keyword
99+
hi link cryPrimitive Keyword
100+
hi link cryBlockComment cryComment
101+
hi link cryLineComment cryComment
102+
hi link cryComment Comment
103+
hi link cryBoolean Boolean
104+
hi link cryType Type
105+
hi link cryProp Keyword
106+
107+
delcommand HiLink
108+
endif
109+
110+
let b:current_syntax = "cryptol"
111+
112+
" Options for vi: ts=8 sw=2 sts=2 nowrap noexpandtab ft=vim
113+
114+
endif

0 commit comments

Comments
 (0)