Added indent file for TTCN-3 from vimscript #754

This commit is contained in:
Gustaf Johansson 2012-09-20 00:41:05 +02:00
commit 08801596d7
2 changed files with 134 additions and 5 deletions

11
README
View File

@ -1,8 +1,9 @@
This is a mirror of http://www.vim.org/scripts/script.php?script_id=753
Based on:
ttcn-syntax:
http://www.vim.org/scripts/script.php?script_id=753
Folds: If the variable "g:ttcn_fold" is defined (e.g. by ":let g:ttcn_fold = 1" in your .vimrc file), folds will automatically be defined for each {...} block.
I couldn't find any syntax file for TTCN-3, so I made my own. The file is based on ETSI document no. ES 201 873-1 (V2.2.1 2003-02).
ttcn-indent:
http://www.vim.org/scripts/script.php?script_id=754
For information about TTCN-3, see http://www.etsi.org.
Folds: If the variable "g:ttcn_fold" is defined (e.g. by ":let g:ttcn_fold = 1" in your .vimrc file), folds will automatically be defined for each {...} block.

128
indent/ttcn.vim Normal file
View File

@ -0,0 +1,128 @@
" Vim indent file
"
" Language: TTCN-3
" Maintainer: Stefan Karlsson <stefan.74@comhem.se>
" Last Change: 22 July 2004
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" Basic strategy for calculating the indent:
"
" 1. Use cindent as far as possible
" 2. Correct the indent for those parts where cindent fails
setlocal indentexpr=Get_ttcn_indent(v:lnum)
setlocal indentkeys=0{,0},0),!^F,o,O,e
setlocal cinwords=
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
if exists("*Get_ttcn_indent")
finish
endif
" Returns the number of the closest previous line that contains code (i.e. it
" skips blank lines and pure comment lines)
function Get_previous_code_line(lnum)
let i = a:lnum - 1
while i > 0
let i = prevnonblank(i)
if getline(i) =~ '\*/\s*$'
while getline(i) !~ '/\*' && i > 1
let i = i - 1
endwhile
if getline(i) =~ '^\s*/\*'
let i = i - 1
else
break
endif
elseif getline(i) =~ '^\s*//'
let i = i - 1
else
break
endif
endwhile
return i
endfunction
" Returns true if the given line contains code
function Is_code_line(lnum)
return Get_previous_code_line(a:lnum + 1) == a:lnum
endfunction
" Returns the value of a given component of the 'cindent' option
function Parse_cindent(ch)
let pat = a:ch . '[0-9]\+s\?'
let str = matchstr(&cinoptions, pat)
if str == ""
let n = &sw
else
let n = matchstr(str, '[0-9]\+')
if str =~# 's'
let n = n * &sw
endif
endif
return n
endfunction
" cindent has problems with these constructs
let s:prob1 = '[^) \t]\s*:=\s*$'
let s:prob2 = '^\s*\i\+\s*:='
let s:prob3 = ',\s*$'
" Start of code block
let s:sblock = '^\s*\(\(module\|group\|type\|function\|testcase\|control\|alt\(step\)\?\|while\|do\|for\|if\|else\|interleave\)\>'
\. '\|\(var\|const\)\s\+\i\+\s\+\i\+\s*:='
\. '\|template\s\+\i\+\s\+\i\+\s*\(:=\|(\)'
\. '\|\i\+\s*:=\s*{\)'
function Get_ttcn_indent(lnum)
let m1 = Get_previous_code_line(a:lnum)
let m2 = Get_previous_code_line(m1)
let prevl1 = getline(m1)
let prevl2 = getline(m2)
let thisl = getline(a:lnum)
if prevl1 =~# s:prob1
let ind = indent(m1) + Parse_cindent('+')
elseif prevl1 =~ s:prob2
if prevl1 =~ '{[^}]*$'
let ind = indent(m1) + &sw
else
if thisl =~ '^\s*}'
let ind = indent(m1) - &sw
else
let ind = indent(m1)
endif
endif
elseif prevl1 =~ ':=\s*{'
let ind = indent(m1) + &sw
elseif thisl =~# s:prob2
let i = m1
while i > 0 && getline(i) !~# s:sblock
let i = Get_previous_code_line(i)
endwhile
if getline(i) =~# '\<alt\(step\)\?\>\|\<interleave\>'
let ind = indent(i) + 2*&sw
else
let ind = indent(i) + &sw
endif
elseif prevl1 =~ s:prob3 || prevl2 =~ s:prob3 && !Is_code_line(a:lnum)
let ind = indent(m1)
else
let ind = cindent(a:lnum)
endif
return ind
endfunction