Skip to content

Commit

Permalink
vim: minizinc
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalardy committed Sep 27, 2015
1 parent 3a12a2a commit 185160a
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 1 deletion.
1 change: 1 addition & 0 deletions vim/bundle/deps
Expand Up @@ -13,3 +13,4 @@ jade https://github.com/digitaltoad/vim-jade.git
golang https://github.com/fatih/vim-go.git
surround https://github.com/tpope/vim-surround.git
pig https://github.com/motus/pig.vim.git
minizinc https://github.com/vale1410/vim-minizinc.git
8 changes: 7 additions & 1 deletion vim/bundle/deps.mk
Expand Up @@ -88,5 +88,11 @@ bundle.pig:
@rm -rf pig/.git
@find pig -name .gitignore | xargs rm

.PHONY: bundle.matchit bundle.nerdcommenter bundle.tabular bundle.coffee-script bundle.fugitive bundle.json bundle.slime bundle.spacehi bundle.syntastic bundle.less bundle.gnupg bundle.jade bundle.golang bundle.surround bundle.pig
bundle.minizinc:
@rm -rf minizinc
git clone --depth=1 https://github.com/vale1410/vim-minizinc.git minizinc
@rm -rf minizinc/.git
@find minizinc -name .gitignore | xargs rm

.PHONY: bundle.matchit bundle.nerdcommenter bundle.tabular bundle.coffee-script bundle.fugitive bundle.json bundle.slime bundle.spacehi bundle.syntastic bundle.less bundle.gnupg bundle.jade bundle.golang bundle.surround bundle.pig bundle.minizinc

23 changes: 23 additions & 0 deletions vim/bundle/minizinc/README.md
@@ -0,0 +1,23 @@
vim-minizinc
============

Simple vim-Bundle for syntax highlighting for minizinc files and Gringo ASP files. Detects .mzn, .fzn and lp files.
The definition of the syntax for vim is taken from the official minizinc-1.6 distribution.

Ensure you have [Vundle](https://github.com/gmarik/Vundle.vim) installed
Ensure your ~/.vimrc file contains the following plugin line

```
Plugin 'vale1410/vim-minizinc'
```

Then to install issue

```
$ vim +PluginInstall +qall
```

see for the original highlighting sources:

* http://www.minizinc.org/
* http://potassco.sourceforge.net/
3 changes: 3 additions & 0 deletions vim/bundle/minizinc/ftdetect/gringo.vim
@@ -0,0 +1,3 @@
autocmd BufNewFile,BufRead *.lp set filetype=gringo
autocmd BufNewFile,BufRead *.pl set filetype=gringo
autocmd BufNewFile,BufRead *.gringo set filetype=gringo
2 changes: 2 additions & 0 deletions vim/bundle/minizinc/ftdetect/minizinc.vim
@@ -0,0 +1,2 @@
autocmd BufNewFile,BufRead *.mzn set filetype=zinc
autocmd BufNewFile,BufRead *.fzn set filetype=zinc
90 changes: 90 additions & 0 deletions vim/bundle/minizinc/syntax/gringo.vim
@@ -0,0 +1,90 @@
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif

let b:current_syntax = ''
unlet b:current_syntax
syn include @Lua syntax/lua.vim

let b:current_syntax = ''
unlet b:current_syntax
syn include @Python syntax/python.vim

syn case match

syn match gringoKeyword "\*%"
syn match gringoComment +%.*+
syn region gringoBlockComment start="%\*" end="\*%"

syn match gringoError "#.*"

syn region luaCode matchgroup=gringoKeyword start="#begin_lua" keepend end="#end_lua" contains=@Lua
syn region luaCode matchgroup=gringoKeyword start="#script[ ]*([ ]*lua[ ]*)" keepend end="#end" contains=@Lua
syn region pythonCode matchgroup=gringoKeyword start="#script[ ]*([ ]*python[ ]*)" keepend end="#end" contains=@Python
syn match gringoKeyword "#ishift"
syn match gringoKeyword "#base"
syn match gringoKeyword "#domain"
syn match gringoKeyword "#hide"
syn match gringoKeyword "#show"
syn match gringoKeyword "#cumulative"
syn match gringoKeyword "#volatile"
syn match gringoKeyword "#const"
syn match gringoKeyword "#include"
syn match gringoKeyword "#incremental"
syn match gringoKeyword "#sup"
syn match gringoKeyword "#inf"
syn match gringoKeyword "#supremum"
syn match gringoKeyword "#infimum"
syn match gringoKeyword "#undef"

syn match gringoFunction "#min"
syn match gringoFunction "#max"
syn match gringoFunction "#minimise"
syn match gringoFunction "#maximise"
syn match gringoFunction "#minimize"
syn match gringoFunction "#maximize"
syn match gringoFunction "#external"
syn match gringoFunction "#count"
syn match gringoFunction "#sum"
syn match gringoFunction "#times"
syn match gringoFunction "#abs"
syn match gringoFunction "#avg"
syn match gringoFunction "#mod"
syn match gringoFunction "#odd"
syn match gringoFunction "#even"
syn match gringoFunction "#pow"
syn match gringoFunction "#program"

syn region gringoString start=+"+ skip=+\\"+ end=+"+
syn match gringoKey "\<not\>"
syn match gringoKey "#false"
syn match gringoKey "#true"
syn match gringoFunction "#compute"
syn match gringoVar "\<_*[A-Z]['a-zA-Z0-9_]*\>'*"
syn match gringoOperator "=\|<\|<=\|>\|>=\|=\|==\|!="
syn match gringoNumber "\<[0123456789]*\>"
syn match gringoRule ":-"

syn sync maxlines=500

command! -nargs=+ HiLink hi def link <args>

HiLink gringoComment Comment
HiLink gringoBlockComment Comment

HiLink gringoKeyword Type
HiLink gringoFunction PreProc
HiLink gringoNumber Number
HiLink gringoString String
HiLink gringoOperator Special
HiLink gringoRule Special
HiLink gringoVar Identifier
HiLink gringoError Error
HiLink gringoKey Keyword

delcommand HiLink

let b:current_syntax = "gringo"

87 changes: 87 additions & 0 deletions vim/bundle/minizinc/syntax/zinc.vim
@@ -0,0 +1,87 @@
" Vim syntax file
" Language: Zinc
" Author: Nicholas Nethercote <njn@csse.unimelb.edu.au>
" Based on Ralph Becket's mercury.vim.
" vim: ts=2 sw=2 et

if exists("b:current_syntax")
finish
endif
let b:current_syntax = "zinc"

" Zinc is case sensitive.
"
syn case match

" The default highlighting for Zinc comments is to highlight
" everything including the comment text. To only highlight the
" initial `%' and subsequent `line' punctuation characters, put:
"
" let zinc_only_highlight_comment_start = 1
"
" somewhere in your `.vimrc' file.
"
" By default, parts of lines that extend over 80 characters will be
" highlighted. To avoid this behaviour, add
"
" let zinc_no_highlight_overlong = 1
"
" somewhere in your `.vimrc' file.
"
if exists("zinc_only_highlight_comment_start") && zinc_only_highlight_comment_start
syn region zincComment start=+%[-=%*_]*+ end=+.*$+he=s-1 contains=zincToDo
else
syn region zincComment start=+%+ end=+.*$+ contains=zincToDo
endif

syn keyword zincType ann any array bool enum float int list of record
syn keyword zincType set string tuple par var

syn keyword zincKeyword annotation assert case constraint
syn keyword zincKeyword else elseif endif function if in include let
syn keyword zincKeyword minimize maximize op output predicate satisfy
syn keyword zincKeyword solve test then type where

syn match zincInt "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>"
syn match zincFloat "\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>"
syn match zincFloat "\<[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>"

syn keyword zincOp not xor subset superset
syn keyword zincOp union diff symdiff intersect div mod
syn match zincOp &\.\.\|+\|-\|\*\|\/\|++&
syn match zincOp +<->\|<-\|->\|/\\\|\\/+
" Although '=' can be an operator, don't highlight it because it's mostly
" used in definitions. Likewise, 'in' can be an operator, but we treat it
" as a keyword because it's mostly used in generators.
syn match zincOp +==\|!=\|<>\|=<\|<=\|<\|>=\|=>\|>\|>+
syn match zincOp +\.\.\.+

syn keyword zincToDo XXX TODO NOTE
syn region zincString start=+"+ skip=+\\.+ end=+"+ contains=zincStringFmt
syn match zincStringFmt +\\[abfnrtv]\|\\x[0-9a-fA-F]*\\\|%[-+# *.0-9]*[dioxXucsfeEgGp]+ contained

if !exists("zinc_no_highlight_overlong") || !zinc_no_highlight_overlong
" The complicated regexp here matches an 80-column string,
" with proper treatment of tabs (assuming the tab size is 8):
" each row consists of 10 columns, and each column consists of either 8
" non-tab characters, or 0-7 non-tab characters followed by a tab.
syn match zincFirst80 +^\([^ ]\{8}\|[^ ]\{0,7} \)\{10}+ contains=ALL
syn match zincTooLong +^\([^ ]\{8}\|[^ ]\{0,7} \)\{10}..*+ contains=zincFirst80
endif

syn region cComment start="/\*" end=".*\*/" contains=zincToDo

syn sync fromstart

hi link zincComment Comment
hi link cComment Comment
hi link zincType Type
hi link zincInt Number
hi link zincFloat Number
hi link zincKeyword Keyword
hi link zincToDo Todo
hi link zincOp Special
hi link zincString String
hi link zincStringFmt Special
hi link zincAtom Constant
hi link zincTooLong ErrorMsg
4 changes: 4 additions & 0 deletions vimrc
Expand Up @@ -87,6 +87,10 @@ if (target_pane == "")
endif
let g:slime_default_config = {"socket_name": "default", "target_pane": target_pane}

let g:NERDCustomDelimiters = {
\ 'zinc': { 'left': '%'},
\ }

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

source $HOME/.vim/mappings.vim
Expand Down

0 comments on commit 185160a

Please sign in to comment.