Add cryptol syntax, closes #107

This commit is contained in:
Adam Stankiewicz 2016-05-02 10:44:59 +02:00
parent 5dd1a7e839
commit 76d23a21e6
No known key found for this signature in database
GPG Key ID: A62480DCEAC884DF
6 changed files with 197 additions and 0 deletions

View File

@ -33,6 +33,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
- [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin) - [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin)
- [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin, ftdetect) - [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin, ftdetect)
- [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin, ftdetect) - [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
- [cryptol](https://github.com/victoredwardocallaghan/cryptol.vim) (syntax, compiler, ftplugin, ftdetect)
- [cql](https://github.com/elubow/cql-vim) (syntax, ftdetect) - [cql](https://github.com/elubow/cql-vim) (syntax, ftdetect)
- [css](https://github.com/JulesWang/css.vim) (syntax) - [css](https://github.com/JulesWang/css.vim) (syntax)
- [cucumber](https://github.com/tpope/vim-cucumber) (syntax, indent, compiler, ftplugin, ftdetect) - [cucumber](https://github.com/tpope/vim-cucumber) (syntax, indent, compiler, ftplugin, ftdetect)

1
build
View File

@ -104,6 +104,7 @@ PACKS="
cjsx:mtscout6/vim-cjsx cjsx:mtscout6/vim-cjsx
clojure:guns/vim-clojure-static clojure:guns/vim-clojure-static
coffee-script:kchmck/vim-coffee-script coffee-script:kchmck/vim-coffee-script
cryptol:victoredwardocallaghan/cryptol.vim
cql:elubow/cql-vim cql:elubow/cql-vim
css:JulesWang/css.vim css:JulesWang/css.vim
cucumber:tpope/vim-cucumber cucumber:tpope/vim-cucumber

24
compiler/cryptol.vim Normal file
View File

@ -0,0 +1,24 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
" Vim compiler file
" Compiler: Cryptol version 1.8.19-academic Compiler
" Maintainer: Edward O'Callaghan <victoredwardocallaghan AT gmail DOT com>
" Latest Revision: 25-Apr-2013
if exists("current_compiler")
finish
endif
let current_compiler = "cryptol"
if exists(":CompilerSet") != 2
command = -nargs =* CompilerSet setlocal <args>
endif
" TODO: Work out errorformat for the Cryptol compiler, see
" :help errorformat
CompilerSet errorformat& " use the default 'errorformat'
" "%<" means the current file name without extension.
CompilerSet makeprg=cryptol\ -o\ %<\ %
endif

View File

@ -53,6 +53,13 @@ if has("autocmd")
au BufNewFile,BufRead *.cql set filetype=cql au BufNewFile,BufRead *.cql set filetype=cql
endif endif
endif endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
au! BufRead,BufNewFile *.cry set filetype=cryptol
au! BufRead,BufNewFile *.cyl set filetype=cryptol
au! BufRead,BufNewFile *.lcry set filetype=cryptol
au! BufRead,BufNewFile *.lcyl set filetype=cryptol
endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cucumber') == -1 if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cucumber') == -1
autocmd BufNewFile,BufReadPost *.feature,*.story set filetype=cucumber autocmd BufNewFile,BufReadPost *.feature,*.story set filetype=cucumber

View File

@ -0,0 +1,50 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
" Copyright © 2013 Edward O'Callaghan. All Rights Reserved.
"setlocal foldmethod=indent
"setlocal foldignore=
setlocal foldmethod=expr
setlocal foldexpr=GetPotionFold(v:lnum)
" Helper function: To tackle non-blank lines,
" wish to know their indentation level
function! IndentLevel(lnum)
return indent(a:lnum) / &shiftwidth
endfunction
" Helper function: .
function! NextNonBlankLine(lnum)
let numlines = line('$')
let current = a:lnum + 1
while current <= numlines
if getline(current) =~? '\v\S'
return current
endif
let current += 1
endwhile
return -2
endfunction
function! GetPotionFold(lnum)
if getline(a:lnum) =~? '\v^\s*$'
return '-1'
endif
let this_indent = IndentLevel(a:lnum)
let next_indent = IndentLevel(NextNonBlankLine(a:lnum))
if next_indent == this_indent
return this_indent
elseif next_indent < this_indent
return this_indent
elseif next_indent > this_indent
return '>' . next_indent
endif
endfunction
endif

114
syntax/cryptol.vim Normal file
View File

@ -0,0 +1,114 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
" Vim syntax file
" Language: Cryptol
" Maintainer: Fergus Henderson
" Last Change: Thu Feb 10 13:14:24 PST 2005
"
" Remove any old syntax stuff hanging around
if version < 600
syn clear
elseif exists("b:current_syntax")
finish
endif
set expandtab
set list lcs=tab:>-,trail:.
" (Qualified) identifiers (no default highlighting)
" XXX copied from Haskell
syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[A-Z][a-zA-Z0-9_']*\>"
syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[a-z][a-zA-Z0-9_']*\>"
" Infix operators--most punctuation characters and any (qualified) identifier
" enclosed in `backquotes`. An operator starting with : is a constructor,
" others are variables (e.g. functions).
" XXX copied from Haskell
syn match cryVarSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[-!#$%&\*\+/<=>\?@\\^|~.][-!#$%&\*\+/<=>\?@\\^|~:.]*"
syn match cryConSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=:[-!#$%&\*\+./<=>\?@\\^|~:]*"
syn match cryVarSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[a-z][a-zA-Z0-9_']*`"
syn match cryConSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[A-Z][a-zA-Z0-9_']*`"
" Reserved symbols
syn match cryDelimiter "(\|)\|\[|\||]\|||\|\[\|\]\|,\|;\|{\|}"
" Strings and constants
" XXX Copied from Haskell
syn match crySpecialChar contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)"
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\)"
syn match crySpecialCharError contained "\\&\|'''\+"
syn region cryString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=crySpecialChar
syn region cryString start=+``+ skip=+\\\\\|\\"+ end=+``+ contains=hsSpecialChar
syn match cryCharacter "[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=crySpecialChar,crySpecialCharError
syn match cryCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=crySpecialChar,crySpecialCharError
syn match cryNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>"
" Keyword definitions.
syn keyword cryInclude include
syn keyword cryConditional if then else
syn keyword cryWhere where
syn keyword cryTypeSyn type
syn keyword cryPragma pragma
syn keyword cryProp extern theorem proof forall codeGen Cpp Haskell SMT Isabelle axioms
syn keyword cryType Bit inf
" Primitives
syn keyword cryBoolean False True
syn keyword cryPrimitive zero undefined
syn keyword cryPrimitive error parity lg2 pmod pdiv pmult format
syn keyword cryPrimitive join split groupBy take drop min max negate reverse
syn keyword cryPrimitive project tail width
syn keyword cryPrimitive ASSERT
" Comments
syn match cryLineComment "//.*"
syn region cryBlockComment start="/\*" end="\*/" contains=cryBlockComment
if !exists("cry_minlines")
let cry_minlines = 50
endif
exec "syn sync lines=" . cry_minlines
if version >= 508 || !exists("did_cry_syntax_inits")
if version < 508
let did_cry_syntax_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
hi link cryInclude Include
hi link cryTypeSyn Keyword
hi link cryImportMod cryImport
hi link cryConditional Conditional
hi link crySpecialChar SpecialChar
hi link cryTypedef Typedef
hi link cryPragma Keyword
hi link cryVarSym cryOperator
hi link cryConSym cryOperator
hi link cryOperator Operator
hi link cryDelimiter Delimiter
hi link crySpecialCharError Error
hi link cryString String
hi link cryCharacter Character
hi link cryNumber Number
hi link cryConditional Conditional
hi link cryWhere Keyword
hi link cryPrimitive Keyword
hi link cryBlockComment cryComment
hi link cryLineComment cryComment
hi link cryComment Comment
hi link cryBoolean Boolean
hi link cryType Type
hi link cryProp Keyword
delcommand HiLink
endif
let b:current_syntax = "cryptol"
" Options for vi: ts=8 sw=2 sts=2 nowrap noexpandtab ft=vim
endif