├── LICENSE ├── README.md ├── ftdetect └── fstar.vim ├── ftplugin ├── fstar-inter.py └── fstar.vim ├── syntax └── fstar.vim └── syntax_checkers └── fstar └── fstar.vim /LICENSE: -------------------------------------------------------------------------------- 1 | VIM LICENSE 2 | 3 | I) There are no restrictions on distributing unmodified copies of Vim except 4 | that they must include this license text. You can also distribute 5 | unmodified parts of Vim, likewise unrestricted except that they must 6 | include this license text. You are also allowed to include executables 7 | that you made from the unmodified Vim sources, plus your own usage 8 | examples and Vim scripts. 9 | 10 | II) It is allowed to distribute a modified (or extended) version of Vim, 11 | including executables and/or source code, when the following four 12 | conditions are met: 13 | 1) This license text must be included unmodified. 14 | 2) The modified Vim must be distributed in one of the following five ways: 15 | a) If you make changes to Vim yourself, you must clearly describe in 16 | the distribution how to contact you. When the maintainer asks you 17 | (in any way) for a copy of the modified Vim you distributed, you 18 | must make your changes, including source code, available to the 19 | maintainer without fee. The maintainer reserves the right to 20 | include your changes in the official version of Vim. What the 21 | maintainer will do with your changes and under what license they 22 | will be distributed is negotiable. If there has been no negotiation 23 | then this license, or a later version, also applies to your changes. 24 | The current maintainer is Bram Moolenaar . If this 25 | changes it will be announced in appropriate places (most likely 26 | vim.sf.net, www.vim.org and/or comp.editors). When it is completely 27 | impossible to contact the maintainer, the obligation to send him 28 | your changes ceases. Once the maintainer has confirmed that he has 29 | received your changes they will not have to be sent again. 30 | b) If you have received a modified Vim that was distributed as 31 | mentioned under a) you are allowed to further distribute it 32 | unmodified, as mentioned at I). If you make additional changes the 33 | text under a) applies to those changes. 34 | c) Provide all the changes, including source code, with every copy of 35 | the modified Vim you distribute. This may be done in the form of a 36 | context diff. You can choose what license to use for new code you 37 | add. The changes and their license must not restrict others from 38 | making their own changes to the official version of Vim. 39 | d) When you have a modified Vim which includes changes as mentioned 40 | under c), you can distribute it without the source code for the 41 | changes if the following three conditions are met: 42 | - The license that applies to the changes permits you to distribute 43 | the changes to the Vim maintainer without fee or restriction, and 44 | permits the Vim maintainer to include the changes in the official 45 | version of Vim without fee or restriction. 46 | - You keep the changes for at least three years after last 47 | distributing the corresponding modified Vim. When the maintainer 48 | or someone who you distributed the modified Vim to asks you (in 49 | any way) for the changes within this period, you must make them 50 | available to him. 51 | - You clearly describe in the distribution how to contact you. This 52 | contact information must remain valid for at least three years 53 | after last distributing the corresponding modified Vim, or as long 54 | as possible. 55 | e) When the GNU General Public License (GPL) applies to the changes, 56 | you can distribute the modified Vim under the GNU GPL version 2 or 57 | any later version. 58 | 3) A message must be added, at least in the output of the ":version" 59 | command and in the intro screen, such that the user of the modified Vim 60 | is able to see that it was modified. When distributing as mentioned 61 | under 2)e) adding the message is only required for as far as this does 62 | not conflict with the license used for the changes. 63 | 4) The contact information as required under 2)a) and 2)d) must not be 64 | removed or changed, except that the person himself can make 65 | corrections. 66 | 67 | III) If you distribute a modified version of Vim, you are encouraged to use 68 | the Vim license for your changes and make them available to the 69 | maintainer, including the source code. The preferred way to do this is 70 | by e-mail or by uploading the files to a server and e-mailing the URL. 71 | If the number of changes is small (e.g., a modified Makefile) e-mailing a 72 | context diff will do. The e-mail address to be used is 73 | 74 | 75 | IV) It is not allowed to remove this license from the distribution of the Vim 76 | sources, parts of it or from a modified version. You may use this 77 | license for previous Vim releases instead of the license that they came 78 | with, at your option. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VimFStar Interactive 2 | 3 | *VimFStar Interactive* is a [Vim] plugin for [F*], an [ML]-like language with a type system for program verification. 4 | 5 | ## Features 6 | 7 | - `.fst` file detection. 8 | - Syntax highlighting (based on [Vim's OCaml syntax file]). 9 | - Interactive verification of code 10 | 11 | ## Installation 12 | 13 | You can use your favorite [pathogen]-compatible plugin manager to install *VimFStar*. 14 | 15 | If you're using [vim-plug], for example, perform the following steps to install *VimFStar*: 16 | 17 | 1. Edit your .vimrc and add a `Plug` declaration for VimFStar. 18 | 19 | ```vim 20 | call plug#begin() 21 | " ... 22 | Plug 'FStarLang/VimFStar', {'for': 'fstar'} 23 | " ... 24 | call plug#end() 25 | ``` 26 | 27 | 2. Restart Vim 28 | 3. `:PlugInstall` to install the plugin. 29 | 30 | ## Use of the interactive verification 31 | 32 | *Note: Interactive mode requires a Cygwin build of (g)Vim.* 33 | 34 | First, put ```fstar.exe``` in your $PATH. VimFStar will check that ```fstar.exe``` is present before loading interactive functions. 35 | 36 | To test your code and it to the environment up to the current position of the cursor, press `````` in normal mode. The marker ```v``` is set to the line just after the end of the checked part, so you can go there with ```'v```. If you already know that your code is correct until the cursor and just want to add it to the context, you can press `````` for a quick test (useful for projects with thousands of lines and where normal tests last very long). 37 | 38 | If you want to test some part of your code without adding it to the environment, select it in visual line mode (Shift+V) and press `````` 39 | 40 | If you want to get the result of the test you launched, press `````` in normal mode 41 | 42 | If you want to see again the errors sent by F*, press `````` 43 | 44 | If you are working on a big chunk of code, and it has no empty new line inside, you can try to select it quicker with `````` in order to check it with ``````. You can go back to where you were with `````` 45 | 46 | You can reset the interaction with the command ```:Freset``` in case something went wrong or if 47 | you want to change a checked part. 48 | 49 | If you want to use library files and/or set options, use ```build-config``` in your file. For example, if my file is at ```$FSTAR_HOME/examples/metatheory``` and I want to use ```classical.fst``` and ```ext.fst``` in ```$FSTAR_HOME/lib``` and set some options, I will put the following code at the top of my file: 50 | 51 | ```fstar 52 | (*--build-config 53 | options:--z3timeout 20 --max_fuel 8 --max_ifuel 6 --initial_fuel 4 --initial_ifuel 2; 54 | other-files:../../lib/classical.fst ../../lib/ext.fst 55 | --*) 56 | ``` 57 | 58 | This configuration is read when the buffer is loaded or when the plugin is reset. So do not forget to reset the plugin if you change `build-config`. 59 | 60 | ## License 61 | 62 | *VimFStar* is distributed under the same license as Vim itself. See [LICENSE] for more details. 63 | 64 | ## Planned Improvements 65 | 66 | - more accurate syntax highlighting. 67 | - [syntastic] integration. 68 | - better highlighting of verified code 69 | - quick access to error locations 70 | - ability to pop environment 71 | 72 | [ML]:http://en.wikipedia.org/wiki/ML_(programming_language) 73 | [Vim]: http://www.vim.org 74 | [F*]: http://www.fstar-lang.org 75 | [vim-plug]: https://github.com/junegunn/vim-plug 76 | [pathogen]: https://github.com/tpope/vim-pathogen 77 | [syntastic]: https://github.com/scrooloose/syntastic 78 | [Vim's OCaml syntax file]: https://github.com/vim/vim/blob/master/runtime/syntax/ocaml.vim 79 | [LICENSE]: http://github.com/FStarLang/VimFStar/blob/master/LICENSE 80 | -------------------------------------------------------------------------------- /ftdetect/fstar.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype detection file 2 | " Language: F* 3 | " Filenames: *.fst 4 | " Maintainers: Michael Lowell Roberts 5 | " URL: http://research.microsoft.com/en-us/projects/fstar/ 6 | " 7 | " Distributed under the VIM LICENSE. Please refer to the LICENSE file or 8 | " visit for details. 9 | 10 | autocmd BufNewFile,BufRead *.fst set filetype=fstar 11 | autocmd BufNewFile,BufRead *.fsti set filetype=fstar 12 | -------------------------------------------------------------------------------- /ftplugin/fstar-inter.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import re 3 | import vim 4 | from subprocess import PIPE,Popen 5 | from threading import Thread 6 | from Queue import Queue, Empty 7 | fstarpath='fstar.exe' 8 | fstarbusy=0 9 | fstarcurrentline=0 10 | fstarpotentialline=0 11 | fstarrequestline=0 12 | fstaranswer=None 13 | fstarupdatehi=False 14 | fstarmatch=None 15 | fst=None 16 | interout=None 17 | 18 | ON_POSIX = 'posix' in sys.builtin_module_names 19 | 20 | def fstar_reset_hi() : 21 | global fstarmatch 22 | if fstarmatch != None: 23 | vim.command("call matchdelete("+str(fstarmatch)+")") 24 | fstarmatch=None 25 | return 26 | 27 | def fstar_add_hi(pos) : 28 | global fstarmatch 29 | if pos >= 1 : 30 | fstarmatch=int(vim.eval("matchadd('FChecked','\\%<"+str(pos+1)+"l')")) 31 | return 32 | 33 | def fstar_update_hi(newpos) : 34 | fstar_reset_hi() 35 | fstar_add_hi(newpos) 36 | return 37 | 38 | def fstar_update_marker(newpos) : 39 | vim.command('exe "normal! ' + str(newpos) + 'G1|mv\\"') 40 | return 41 | 42 | #no waiting read as in http://stackoverflow.com/a/4896288/2598986 43 | def fstar_enqueue_output(out, queue): 44 | for line in iter(out.readline, b''): 45 | queue.put(line) 46 | out.close() 47 | 48 | def fstar_readinter () : 49 | global interout 50 | try : line = interout.get_nowait() 51 | except Empty : 52 | return None 53 | else : 54 | return line 55 | 56 | def fstar_writeinter (s) : 57 | global fst 58 | fst.stdin.write(s) 59 | 60 | def fstar_init () : 61 | global fst,interout 62 | fst=Popen([fstarpath,'--in'],stdin=PIPE, stdout=PIPE,bufsize=1,close_fds=ON_POSIX) 63 | interout=Queue() 64 | t=Thread(target=fstar_enqueue_output,args=(fst.stdout,interout)) 65 | t.daemon=True 66 | t.start() 67 | 68 | def fstar_reset() : 69 | global fstarbusy,fstarcurrentline,fstarpotentialline,fstaranswer,fstarupdatehi,fstarmatch 70 | fstarbusy=0 71 | fstarcurrentline=0 72 | fstarpotentialline=0 73 | fstaranswer=None 74 | fstarupdatehi=False 75 | fstar_reset_hi() 76 | fstar_init() 77 | print 'Interaction reset' 78 | 79 | 80 | def fstar_test_code (code,keep,quickcheck=False) : 81 | global fstarbusy,fst 82 | if fstarbusy == 1 : 83 | return 'Already busy' 84 | fstarbusy = 1 85 | fstar_writeinter('#push\n') 86 | if quickcheck : 87 | fstar_writeinter('#set-options "--admit_smt_queries true"\n') 88 | fstar_writeinter(code) 89 | fstar_writeinter('\n') 90 | if quickcheck : 91 | fstar_writeinter('#reset-options\n') 92 | fstar_writeinter('#end\n') 93 | if not keep : 94 | fstar_writeinter('#pop\n') 95 | return '' 96 | 97 | def fstar_convert_answer(ans) : 98 | global fstarrequestline 99 | res = re.match(r"\\((\d+)\,(\d+)\-(\d+)\,(\d+)\)\: (.*)",ans) 100 | if res == None : 101 | return ans 102 | return '(%d,%s-%d,%s) : %s' % (int(res.group(1))+fstarrequestline-1,res.group(2),int(res.group(3))+fstarrequestline-1,res.group(4),res.group(5)) 103 | 104 | def fstar_gather_answer () : 105 | global fstarbusy,fst,fstaranswer,fstarpotentialline,fstarcurrentline,fstarupdatehi 106 | if fstarbusy == 0 : 107 | return 'No verification pending' 108 | line=fstar_readinter() 109 | while line != None : 110 | if line=='ok\n' : 111 | fstarbusy=0 112 | fstarcurrentline=fstarpotentialline 113 | if fstarupdatehi : 114 | fstar_update_hi(fstarcurrentline) 115 | fstar_update_marker(fstarcurrentline+1) 116 | return 'Verification succeeded' 117 | if line=='fail\n' : 118 | fstarbusy=0 119 | fstarpotentialline=fstarcurrentline 120 | return fstaranswer 121 | fstaranswer+='\n'+fstar_convert_answer(line) 122 | line=fstar_readinter() 123 | return 'Busy' 124 | 125 | def fstar_vim_query_answer () : 126 | r = fstar_gather_answer() 127 | if r != None : 128 | print r 129 | 130 | def fstar_get_range(firstl,lastl) : 131 | lines = vim.eval("getline(%s,%s)"%(firstl,lastl)) 132 | lines = lines + ["\n"] 133 | code = "\n".join(lines) 134 | return code 135 | 136 | 137 | def fstar_get_selection () : 138 | firstl = int(vim.eval("getpos(\"'<\")")[1]) 139 | endl = int(vim.eval("getpos(\"'>\")")[1]) 140 | lines = vim.eval("getline(%d,%d)"%(firstl,endl)) 141 | lines = lines + ["\n"] 142 | code = "\n".join(lines) 143 | return code 144 | 145 | 146 | def fstar_vim_test_code () : 147 | global fstarrequestline, fstaranswer 148 | global fstarupdatehi 149 | if fstarbusy == 1 : 150 | print 'Already busy' 151 | return 152 | fstaranswer='' 153 | fstarrequestline = int(vim.eval("getpos(\"'<\")")[1]) 154 | code = fstar_get_selection() 155 | fstarupdatehi=False 156 | fstar_test_code(code,False) 157 | print 'Test of selected code launched' 158 | 159 | def fstar_vim_until_cursor (quick=False) : 160 | global fstarcurrentline,fstarpotentialline,fstarrequestline,fstarupdatehi, fstaranswer 161 | if fstarbusy == 1 : 162 | print 'Already busy' 163 | return 164 | fstaranswer = '' 165 | vimline = int(vim.eval("getpos(\".\")")[1]) 166 | if vimline <= fstarcurrentline : 167 | print 'Already checked' 168 | return 169 | firstl = fstarcurrentline+1 170 | fstarrequestline=firstl 171 | endl = vimline 172 | code = fstar_get_range(firstl,endl) 173 | fstarpotentialline=endl 174 | fstarupdatehi=True 175 | fstar_test_code(code,True,quick) 176 | if quick : 177 | print 'Quick test until this point launched' 178 | else : 179 | print 'Test until this point launched' 180 | 181 | def fstar_vim_get_answer() : 182 | global fstaranswer 183 | print fstaranswer 184 | 185 | def fstar_get_current_line () : 186 | global fstarcurrentline 187 | print fstarcurrentline 188 | -------------------------------------------------------------------------------- /ftplugin/fstar.vim: -------------------------------------------------------------------------------- 1 | if exists("b:did_ftplugin") 2 | finish 3 | endif 4 | let b:did_ftplugin=1 5 | 6 | let s:path = system("echo $PATH") 7 | let s:jpath = substitute(s:path,":",",","g") 8 | let s:jpath = substitute(s:jpath,"\n","","g") 9 | let s:matchs = globpath(s:jpath,"fstar.exe") 10 | 11 | "Disable interactive feature 12 | "let g:fstar_inter = 1 13 | 14 | "Disable mappings 15 | "let g:fstar_inter_maps = 1 16 | 17 | 18 | if !empty(s:matchs) && !exists('g:fstar_inter') 19 | 20 | let g:fstar_inter = 1 21 | pyfile :p:h/fstar-inter.py 22 | 23 | fu! Ftest_code () 24 | py fstar_vim_test_code() 25 | endfunction 26 | 27 | fu! Funtil_cursor() 28 | py fstar_vim_until_cursor() 29 | endfunction 30 | 31 | fu! Funtil_cursor_quick() 32 | py fstar_vim_until_cursor(True) 33 | endfunction 34 | 35 | fu! Fget_result() 36 | py fstar_vim_query_answer() 37 | endfunction 38 | 39 | fu! Freset() 40 | py fstar_reset() 41 | endfunction 42 | 43 | fu! Fget_answer() 44 | py fstar_vim_get_answer() 45 | endfunction 46 | 47 | py fstar_init() 48 | 49 | command Funtil call Funtil_cursor() 50 | command Funtilquick call Funtil_cursor_quick() 51 | command Fresult call Fget_result() 52 | command Freset call Freset() 53 | command Fanswer call Fget_answer() 54 | 55 | "Here you can set the color you want for checked code 56 | highlight FChecked ctermbg=darkgrey guibg=lightGreen 57 | endif 58 | 59 | 60 | if !exists("g:fstar_inter_maps") 61 | vnoremap :call Ftest_code() 62 | nnoremap :call Funtil_cursor() 63 | nnoremap :call Fget_result() 64 | nnoremap :call Fget_answer() 65 | nnoremap (v)k$ 66 | nnoremap :call Funtil_cursor_quick() 67 | " is to remove '<,'> which execute the command for each selected line 68 | endif 69 | 70 | 71 | " Add mappings, unless the user didn't want this. 72 | if !exists("no_plugin_maps") && !exists("no_fstar_maps") 73 | " (un)commenting 74 | if !hasmapto('Comment') 75 | nmap c LUncomOn 76 | xmap c BUncomOn 77 | nmap C LUncomOff 78 | xmap C BUncomOff 79 | endif 80 | 81 | nnoremap LUncomOn gI(* *) 82 | nnoremap LUncomOff :s/^(\* \(.*\) \*)/\1/:noh 83 | xnoremap BUncomOn :'<,'>`0i(*`>o0i*)`< 84 | xnoremap BUncomOff :'<,'>`dd`< 85 | endif 86 | 87 | -------------------------------------------------------------------------------- /syntax/fstar.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: F* 3 | " Filenames: *.fst 4 | " Maintainers: Michael Lowell Roberts 5 | " URL: http://research.microsoft.com/en-us/projects/fstar/ 6 | " 7 | " Based on the ocaml.vim syntax file distributed with Vim. 8 | " Distributed under the VIM LICENSE. Please refer to the LICENSE file or 9 | " visit for details. 10 | 11 | if version < 600 12 | syntax clear 13 | elseif exists("b:current_syntax") && b:current_syntax == "fstar" 14 | finish 15 | endif 16 | 17 | " OCaml is case sensitive. 18 | syn case match 19 | 20 | " Access to the method of an object 21 | syn match fstarMethod "#" 22 | 23 | " Script headers highlighted like comments 24 | syn match fstarComment "^#!.*" contains=@Spell 25 | 26 | " Scripting directives 27 | syn match fstarScript "^#\<\(quit\|labels\|warnings\|directory\|cd\|load\|use\|install_printer\|remove_printer\|require\|thread\|trace\|untrace\|untrace_all\|print_depth\|print_length\|camlp4o\)\>" 28 | 29 | " lowercase identifier - the standard way to match 30 | syn match fstarLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/ 31 | 32 | syn match fstarKeyChar "|" 33 | 34 | " Errors 35 | syn match fstarBraceErr "}" 36 | syn match fstarBrackErr "\]" 37 | syn match fstarParenErr ")" 38 | syn match fstarArrErr "|]" 39 | 40 | syn match fstarCommentErr "\*)" 41 | 42 | syn match fstarCountErr "\" 43 | syn match fstarCountErr "\" 44 | 45 | if !exists("fstar_revised") 46 | syn match fstarDoErr "\" 47 | endif 48 | 49 | syn match fstarDoneErr "\" 50 | syn match fstarThenErr "\" 51 | 52 | " Error-highlighting of "end" without synchronization: 53 | " as keyword or as error (default) 54 | if exists("fstar_noend_error") 55 | syn match fstarKeyword "\" 56 | else 57 | syn match fstarEndErr "\" 58 | endif 59 | 60 | " Some convenient clusters 61 | syn cluster fstarAllErrs contains=fstarBraceErr,fstarBrackErr,fstarParenErr,fstarCommentErr,fstarCountErr,fstarDoErr,fstarDoneErr,fstarEndErr,fstarThenErr 62 | 63 | syn cluster fstarAENoParen contains=fstarBraceErr,fstarBrackErr,fstarCommentErr,fstarCountErr,fstarDoErr,fstarDoneErr,fstarEndErr,fstarThenErr 64 | 65 | syn cluster fstarContained contains=fstarTodo,fstarPreDef,fstarModParam,fstarModParam1,fstarPreMPRestr,fstarMPRestr,fstarMPRestr1,fstarMPRestr2,fstarMPRestr3,fstarModRHS,fstarFuncWith,fstarFuncStruct,fstarModTypeRestr,fstarModTRWith,fstarWith,fstarWithRest,fstarModType,fstarFullMod,fstarVal 66 | 67 | 68 | " Enclosing delimiters 69 | syn region fstarEncl transparent matchgroup=fstarKeyword start="(" matchgroup=fstarKeyword end=")" contains=ALLBUT,@fstarContained,fstarParenErr 70 | syn region fstarEncl transparent matchgroup=fstarKeyword start="{" matchgroup=fstarKeyword end="}" contains=ALLBUT,@fstarContained,fstarBraceErr 71 | syn region fstarEncl transparent matchgroup=fstarKeyword start="\[" matchgroup=fstarKeyword end="\]" contains=ALLBUT,@fstarContained,fstarBrackErr 72 | syn region fstarEncl transparent matchgroup=fstarKeyword start="\[|" matchgroup=fstarKeyword end="|\]" contains=ALLBUT,@fstarContained,fstarArrErr 73 | 74 | 75 | " Comments 76 | syn region fstarComment start="(\*" end="\*)" contains=@Spell,fstarComment,fstarTodo 77 | syn match fstarCommentLine "//.*$" contains=fstarComment,fstarCommentLine,fstarTodo,@Spell 78 | syn keyword fstarTodo contained TODO FIXME XXX NOTE 79 | 80 | 81 | " Objects 82 | syn region fstarEnd matchgroup=fstarObject start="\" matchgroup=fstarObject end="\" contains=ALLBUT,@fstarContained,fstarEndErr 83 | 84 | 85 | " Blocks 86 | if !exists("fstar_revised") 87 | syn region fstarEnd matchgroup=fstarKeyword start="\" matchgroup=fstarKeyword end="\" contains=ALLBUT,@fstarContained,fstarEndErr 88 | endif 89 | 90 | 91 | " "for" 92 | syn region fstarNone matchgroup=fstarKeyword start="\" matchgroup=fstarKeyword end="\<\(to\|downto\)\>" contains=ALLBUT,@fstarContained,fstarCountErr 93 | 94 | 95 | " "do" 96 | if !exists("fstar_revised") 97 | syn region fstarDo matchgroup=fstarKeyword start="\" matchgroup=fstarKeyword end="\" contains=ALLBUT,@fstarContained,fstarDoneErr 98 | endif 99 | 100 | " "if" 101 | syn region fstarNone matchgroup=fstarKeyword start="\" matchgroup=fstarKeyword end="\" contains=ALLBUT,@fstarContained,fstarThenErr 102 | 103 | 104 | "" Modules 105 | 106 | " "sig" 107 | syn region fstarSig matchgroup=fstarModule start="\" matchgroup=fstarModule end="\" contains=ALLBUT,@fstarContained,fstarEndErr,fstarModule 108 | syn region fstarModSpec matchgroup=fstarKeyword start="\" matchgroup=fstarModule end="\<\u\(\w\|'\)*\>" contained contains=@fstarAllErrs,fstarComment,fstarCommentLine skipwhite skipempty nextgroup=fstarModTRWith,fstarMPRestr 109 | 110 | " "open" 111 | syn region fstarNone matchgroup=fstarKeyword start="\" matchgroup=fstarModule end="\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*\>" contains=@fstarAllErrs,fstarComment,fstarCommentLine 112 | 113 | " "include" 114 | syn match fstarKeyword "\" skipwhite skipempty nextgroup=fstarModParam,fstarFullMod 115 | 116 | " "module" - somewhat complicated stuff ;-) 117 | syn region fstarModule matchgroup=fstarKeyword start="\" matchgroup=fstarModule end="\<\u\(\w\|\.\)*\>" contains=@fstarAllErrs,fstarComment,fstarCommentLine skipwhite skipempty nextgroup=fstarPreDef 118 | syn region fstarPreDef start="[:print:]"me=e-1 matchgroup=fstarKeyword end="\l\|=\|)"me=e-1 contained contains=@fstarAllErrs,fstarComment,fstarCommentLine,fstarModParam,fstarModTypeRestr,fstarModTRWith nextgroup=fstarModPreRHS 119 | syn region fstarModParam start="([^*]" end=")" contained contains=@fstarAENoParen,fstarModParam1,fstarVal 120 | syn match fstarModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=fstarPreMPRestr 121 | 122 | syn region fstarPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@fstarAllErrs,fstarComment,fstarCommentLine,fstarMPRestr,fstarModTypeRestr 123 | 124 | syn region fstarMPRestr start=":" end="."me=e-1 contained contains=@fstarComment,fstarCommentLine skipwhite skipempty nextgroup=fstarMPRestr1,fstarMPRestr2,fstarMPRestr3 125 | syn region fstarMPRestr1 matchgroup=fstarModule start="\ssig\s\=" matchgroup=fstarModule end="\" contained contains=ALLBUT,@fstarContained,fstarEndErr,fstarModule 126 | syn region fstarMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=fstarKeyword end="->" contained contains=@fstarAllErrs,fstarComment,fstarCommentLine,fstarModParam skipwhite skipempty nextgroup=fstarFuncWith,fstarMPRestr2 127 | syn match fstarMPRestr3 "\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*" contained 128 | syn match fstarModPreRHS "=" contained skipwhite skipempty nextgroup=fstarModParam,fstarFullMod 129 | syn keyword fstarKeyword val 130 | syn region fstarVal matchgroup=fstarKeyword start="\" matchgroup=fstarLCIdentifier end="\<\l\(\w\|'\)*\>" contains=@fstarAllErrs,fstarComment,fstarCommentLine,fstarFullMod skipwhite skipempty nextgroup=fstarMPRestr 131 | syn region fstarModRHS start="." end=". *\w\|([^*]"me=e-2 contained contains=fstarComment,fstarCommentLine skipwhite skipempty nextgroup=fstarModParam,fstarFullMod 132 | syn match fstarFullMod "\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=fstarFuncWith 133 | 134 | syn region fstarFuncWith start="([^*]"me=e-1 end=")" contained contains=fstarComment,fstarCommentLine,fstarWith,fstarFuncStruct skipwhite skipempty nextgroup=fstarFuncWith 135 | syn region fstarFuncStruct matchgroup=fstarModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=fstarModule end="\" contains=ALLBUT,@fstarContained,fstarEndErr 136 | 137 | syn match fstarModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contained 138 | syn region fstarModTRWith start=":\s*("hs=s+1 end=")" contained contains=@fstarAENoParen,fstarWith 139 | syn match fstarWith "\<\(\u\(\w\|'\)* *\. *\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=fstarWithRest 140 | syn region fstarWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@fstarContained 141 | 142 | " "struct" 143 | syn region fstarStruct matchgroup=fstarModule start="\<\(module\s\+\)\=struct\>" matchgroup=fstarModule end="\" contains=ALLBUT,@fstarContained,fstarEndErr 144 | 145 | " "module type" 146 | syn region fstarKeyword start="\\s*\\(\s*\\)\=" matchgroup=fstarModule end="\<\w\(\w\|'\)*\>" contains=fstarComment,fstarCommentLine skipwhite skipempty nextgroup=fstarMTDef 147 | syn match fstarMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s+1 skipwhite skipempty nextgroup=fstarFullMod 148 | 149 | syn keyword fstarKeyword and as assume assert 150 | syn keyword fstarKeyword constraint decreases else ensures 151 | syn keyword fstarKeyword exception external fun 152 | 153 | syn keyword fstarKeyword in inherit initializer 154 | syn keyword fstarKeyword land lazy let logic match 155 | syn keyword fstarKeyword method mutable new of opaque 156 | syn keyword fstarKeyword parser pattern private raise rec requires 157 | syn keyword fstarKeyword try type 158 | syn keyword fstarKeyword virtual when while with 159 | 160 | syn keyword fstarBoolean True False 161 | syn keyword fstarKeyword function 162 | syn keyword fstarBoolean true false 163 | syn match fstarKeyChar "!" 164 | 165 | syn keyword fstarType array bool char exn float format format4 166 | syn keyword fstarType nat int int32 int64 lazy_t list nativeint option 167 | syn keyword fstarType string unit 168 | syn keyword fstarType set map forall exists 169 | 170 | syn keyword fstarOperator asr lnot lor lsl lsr lxor mod not 171 | 172 | syn match fstarConstructor "(\s*)" 173 | syn match fstarConstructor "\[\s*\]" 174 | syn match fstarConstructor "\[|\s*>|]" 175 | syn match fstarConstructor "\[<\s*>\]" 176 | syn match fstarConstructor "\u\(\w\|'\)*\>" 177 | 178 | " Polymorphic variants 179 | syn match fstarConstructor "`\w\(\w\|'\)*\>" 180 | 181 | " Module prefix 182 | syn match fstarModPath "\u\(\w\|'\)* *\."he=e-1 183 | 184 | syn match fstarCharacter "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'" 185 | syn match fstarCharacter "'\\x\x\x'" 186 | syn match fstarCharErr "'\\\d\d'\|'\\\d'" 187 | syn match fstarCharErr "'\\[^\'ntbr]'" 188 | syn region fstarString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell 189 | 190 | syn match fstarFunDef "->" 191 | syn match fstarRefAssign ":=" 192 | syn match fstarTopStop ";;" 193 | syn match fstarOperator "\^" 194 | syn match fstarOperator "::" 195 | syn match fstarOperator ":" 196 | 197 | syn match fstarOperator "\\/" 198 | syn match fstarOperator "/\\" 199 | syn match fstarOperator "&&" 200 | syn match fstarOperator "<" 201 | syn match fstarOperator ">" 202 | syn match fstarOperator "\<\>" 203 | syn match fstarAnyVar "\<_\>" 204 | syn match fstarKeyChar "|[^\]]"me=e-1 205 | syn match fstarKeyChar ";" 206 | syn match fstarKeyChar "\~" 207 | syn match fstarKeyChar "?" 208 | syn match fstarKeyChar "\*" 209 | syn match fstarKeyChar "=" 210 | 211 | if exists("fstar_revised") 212 | syn match fstarErr "<-" 213 | else 214 | syn match fstarOperator "<-" 215 | endif 216 | 217 | syn match fstarNumber "\<-\=\d\(_\|\d\)*[l|L|n]\?\>" 218 | syn match fstarNumber "\<-\=0[x|X]\(\x\|_\)\+[l|L|n]\?\>" 219 | syn match fstarNumber "\<-\=0[o|O]\(\o\|_\)\+[l|L|n]\?\>" 220 | syn match fstarNumber "\<-\=0[b|B]\([01]\|_\)\+[l|L|n]\?\>" 221 | syn match fstarFloat "\<-\=\d\(_\|\d\)*\.\?\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>" 222 | 223 | " Labels 224 | syn match fstarLabel "\~\(\l\|_\)\(\w\|'\)*"lc=1 225 | syn match fstarLabel "?\(\l\|_\)\(\w\|'\)*"lc=1 226 | syn region fstarLabel transparent matchgroup=fstarLabel start="?(\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@fstarContained,fstarParenErr 227 | 228 | 229 | " Synchronization 230 | syn sync minlines=50 231 | syn sync maxlines=500 232 | 233 | if !exists("fstar_revised") 234 | syn sync match fstarDoSync grouphere fstarDo "\" 235 | syn sync match fstarDoSync groupthere fstarDo "\" 236 | endif 237 | 238 | if exists("fstar_revised") 239 | syn sync match fstarEndSync grouphere fstarEnd "\<\(object\)\>" 240 | else 241 | syn sync match fstarEndSync grouphere fstarEnd "\<\(begin\|object\)\>" 242 | endif 243 | 244 | syn sync match fstarEndSync groupthere fstarEnd "\" 245 | syn sync match fstarStructSync grouphere fstarStruct "\" 246 | syn sync match fstarStructSync groupthere fstarStruct "\" 247 | syn sync match fstarSigSync grouphere fstarSig "\" 248 | syn sync match fstarSigSync groupthere fstarSig "\" 249 | 250 | " Define the default highlighting. 251 | " For version 5.7 and earlier: only when not done already 252 | " For version 5.8 and later: only when an item doesn't have highlighting yet 253 | if version >= 508 || !exists("did_fstar_syntax_inits") 254 | if version < 508 255 | let did_fstar_syntax_inits = 1 256 | command -nargs=+ HiLink hi link 257 | else 258 | command -nargs=+ HiLink hi def link 259 | endif 260 | 261 | HiLink fstarBraceErr Error 262 | HiLink fstarBrackErr Error 263 | HiLink fstarParenErr Error 264 | HiLink fstarArrErr Error 265 | 266 | HiLink fstarCommentErr Error 267 | 268 | HiLink fstarCountErr Error 269 | HiLink fstarDoErr Error 270 | HiLink fstarDoneErr Error 271 | HiLink fstarEndErr Error 272 | HiLink fstarThenErr Error 273 | 274 | HiLink fstarCharErr Error 275 | 276 | HiLink fstarErr Error 277 | 278 | HiLink fstarComment Comment 279 | HiLink fstarCommentLine Comment 280 | 281 | HiLink fstarModPath Include 282 | HiLink fstarObject Include 283 | HiLink fstarModule Include 284 | HiLink fstarModParam1 Include 285 | HiLink fstarModType Include 286 | HiLink fstarMPRestr3 Include 287 | HiLink fstarFullMod Include 288 | HiLink fstarModTypeRestr Include 289 | HiLink fstarWith Include 290 | HiLink fstarMTDef Include 291 | 292 | HiLink fstarScript Include 293 | 294 | HiLink fstarConstructor Constant 295 | 296 | HiLink fstarVal Keyword 297 | HiLink fstarModPreRHS Keyword 298 | HiLink fstarMPRestr2 Keyword 299 | HiLink fstarKeyword Keyword 300 | HiLink fstarMethod Include 301 | HiLink fstarFunDef Keyword 302 | HiLink fstarRefAssign Keyword 303 | HiLink fstarKeyChar Keyword 304 | HiLink fstarAnyVar Keyword 305 | HiLink fstarTopStop Keyword 306 | HiLink fstarOperator Keyword 307 | 308 | HiLink fstarBoolean Boolean 309 | HiLink fstarCharacter Character 310 | HiLink fstarNumber Number 311 | HiLink fstarFloat Float 312 | HiLink fstarString String 313 | 314 | HiLink fstarLabel Identifier 315 | 316 | HiLink fstarType Type 317 | 318 | HiLink fstarTodo Todo 319 | 320 | HiLink fstarEncl Keyword 321 | 322 | delcommand HiLink 323 | endif 324 | 325 | let b:current_syntax = "fstar" 326 | 327 | " vim: ts=8 328 | -------------------------------------------------------------------------------- /syntax_checkers/fstar/fstar.vim: -------------------------------------------------------------------------------- 1 | " Syntastic syntax checker file 2 | " Language: F* 3 | " Filenames: *.fst 4 | " Maintainers: Michael Lowell Roberts 5 | " URL: http://research.microsoft.com/en-us/projects/fstar/ 6 | " 7 | " Distributed under the VIM LICENSE. Please refer to the LICENSE file or 8 | " visit for details. 9 | 10 | if exists('g:loaded_syntastic_fstar_checker') 11 | finish 12 | endif 13 | let g:loaded_syntastic_fstar_checker = 1 14 | 15 | if !exists('g:syntastic_fstar_sort') 16 | let g:syntastic_fstar_sort = 1 17 | endif 18 | 19 | let s:save_cpo = &cpo 20 | set cpo&vim 21 | 22 | function! SyntaxCheckers_fstar_fstar_IsAvailable() dict 23 | " Decho "self.getExec() => " . self.getExec() 24 | return executable(self.getExec()) 25 | endfunction 26 | 27 | "function! SyntaxCheckers_fstar_fstar_GetHighlightRegex(item) 28 | "if match(a:item['text'], 'assigned but unused variable') > -1 29 | "let term = split(a:item['text'], ' - ')[1] 30 | "return '\V\\<'.term.'\\>' 31 | "endif 32 | 33 | "return '' 34 | "endfunction 35 | 36 | function! SyntaxCheckers_fstar_fstar_GetLocList() dict 37 | let makeprg = self.makeprgBuild({ 38 | \ 'args': '', 39 | \ 'args_after': '' }) 40 | let errorformat = '\ %#%f(%l\\\,%c):\ %m' 41 | let env = {} 42 | return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'env': env }) 43 | endfunction 44 | 45 | call g:SyntasticRegistry.CreateAndRegisterChecker({ 46 | \ 'filetype': 'fstar', 47 | \ 'name': 'fstar', 48 | \ 'exec': 'fstar' }) 49 | 50 | let &cpo = s:save_cpo 51 | unlet s:save_cpo 52 | 53 | " vim: set sw=4 sts=4 et fdm=marker: 54 | --------------------------------------------------------------------------------