Skip to content

Commit

Permalink
Updated syntax and indent rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
JessieAMorris committed Nov 1, 2012
1 parent 7d36786 commit 6f7e7c1
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 13 deletions.
111 changes: 105 additions & 6 deletions indent/krl.vim
Original file line number Diff line number Diff line change
@@ -1,15 +1,114 @@
" Vim indent file
" Language: Kynetx Rule Language (KRL)
" Maintainer: AKO & JAM
" Last Change: 2010 September 1
" Last Change: 2012 November 1

echo "Loaded file"

" Only load this indent file when no other was loaded.
"if exists("b:did_indent")
if exists("b:did_indent")
"finish
"endif
"let b:did_indent = 1
endif
" let b:did_indent = 1

" C indenting is not too bad.
"setlocal cindent
" I've decided to no longer do cindenting. JAM 11/01/2012
" setlocal cindentmman

echo "function assignment"
setlocal indentexpr=GetKRLIndent(v:lnum)

if exists("*GetKRLIndent")
"finish
endif


function! s:GetPrevKRLNonCommentLineNum( line_num )
let SKIP_LINES = '^\s*\(\((\*\)\|\(\*\ \)\|\(\*)\)\)'

let nline = a:line_num
while nline > 0
let nline = prevnonblank(nline-1)
if getline(nline) !~? SKIP_LINES
break
endif
endwhile

return nline
endfunction

echo "function definition"
function! GetKRLIndent( line_num )
echo "Loaded line: ".a:line_num
" Line 0 always starts at column 0
if a:line_num == 1
echo "First line, is 0"
return 0
endif

let this_codeline = getline( a:line_num )

" If in the middle of a three-part comment (i.e. \* */)
if this_codeline =~ '^\s*\*'
echo "Is part of a three line comment"
return indent( a:line_num )
endif

let prev_codeline_num = s:GetPrevKRLNonCommentLineNum( a:line_num )
let prev_codeline = getline( prev_codeline_num )
let indnt = indent ( prev_codeline_num )

echo "Previous line number: ".prev_codeline_num." and previous indent: ".indnt

" Rules, meta, and global blocks all have exactly one indent
if this_codeline =~ '^\s*\<\(meta\|global\|rule\|dispatch\)\>'
echo "Begins with meta, global, or rule"
return &shiftwidth
endif

if this_codeline =~ '^\s*\<\(name\|description\|author\|logging\|use\|provides\)\>'
echo "Is the author, description, etc"
if prev_codeline =~ '^\s*\<\(meta\|global\|rule\|dispatch\)\>'
echo "Was right after meta, global, or rule"
return indnt + &shiftwidth
else
echo "Was not right after meta, global, or rule"
return indnt
endif
endif

" If the previous line ends in { or << increase the indent
if prev_codeline =~ '\s*\({\|<<\)\s*$'
echo "Previous was an open brace or open heredoc"
return indnt + &shiftwidth
endif

" If this line ends in } or >>, decrease the indent
if this_codeline =~ '^\s*\(}\|>>\);\?$'
echo "This line is a close brace or close heredoc"
return indnt - &shiftwidth
endif

" These two rules handle the indentation of with/and.
" The first handles the case where with/and is on this line,
" and the second handles the case where it was on the previous line.
" Since the previous line unindent case comes after the return,
" this should work correctly.
if this_codeline =~ '^\s*\<with\>'
return indnt + &shiftwidth
endif

if prev_codeline =~ '^\s*\<configure\>'
echo "Previous line was configure"
if this_codeline =~ '^\s*\<and\>'
return indnt + &shiftwidth
endif
endif

if prev_codeline =~ '^\s*\<with\|and\>'
return indnt - &shiftwidth
end

"let b:undo_indent = "setl cin<"
"If all else fails, just return the previous line's indentation
return indnt
endfunction
26 changes: 19 additions & 7 deletions syntax/krl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
" (ss) repaired several quoting and grouping glitches
" (ss) fixed regex parsing issue with multiple qualifiers [gi]
" (ss) additional factoring of keywords, globals, and members
" Last Change: 2006 Jun 19
" Last Change: 2012 November 1

if !exists("main_syntax")
if version < 600
Expand All @@ -27,28 +27,40 @@ syn match krlLineComment "\/\/.*" contains=@Spell,krlCommentTodo
syn match krlCommentSkip "^[ \t]*\*\($\|[ \t]\+\)"
syn region krlComment start="/\*" end="\*/" contains=@Spell,krlCommentTodo

" The emits
syn region krlEmit matchgroup=Emit start=+emit\s\+<<+ end=+>>+ contains=@JS
syn region krlClownHat matchgroup=Emit start=/<|/ end=/|>/ contains=@JS

" CSS
syn region krlCSS matchgroup=Snip start=+css\s\+<<+ end=+>>+ contains=@CSS
syn region krlHereDoc matchgroup=Snip start=/<</ end=/>>/ contains=krlString

" HTML
syn region krlHereDoc matchgroup=Snip start=/<</ end=/>>/ contains=@HTML
syn region krlHTMLHereDoc matchgroup=Snip start=/\w\+\s\+=\s\+<</ end=/>>/ contains=@HTML
syn region krlClownHat matchgroup=Emit start=/<|/ end=/|>/ contains=@JS

" KRL Strings
syn region krlString start=+"+ skip=+\\\\\|\\"+ end=+"\|$+
syn region krlString start=+'+ skip=+\\\\\|\\'+ end=+'\|$+

" KRL Regexes
syn region krlRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@perlInterpMatch oneline
syn region krlNewRegexpString start=+re/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@perlInterpMatch oneline
syn region krlPoundRegexpString start=+#[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+#[gi]\{0,2\}\s*$+ end=+#[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@perlInterpMatch oneline

" JSON Path
syn region krlJSONPath start=+"\$\.+ skip=+\\\\\|\\'+ end=+"\|$+
syn region krlJSONPath start=+'\$\.+ skip=+\\\\\|\\'+ end=+'\|$+

" Used in Modules
syn match krlNamespace "\w\+:"he=e-1,me=e-1
syn match krlMethod ":\w\+"hs=s+1,ms=s+1

syn keyword krlSelect select
syn keyword krlDomain domain
syn keyword krlOptions opacity width sticky message tabColor backgroundColor color delay life divCSS pathToTabImage tabLocation topPos imageWidth imageHeight
syn keyword krlOptions opacity width sticky message tabColor backgroundColor color delay life divCSS pathToTabImage tabLocation topPos imageWidth imageHeight configure
syn keyword krlConditional if then fired else neq eq like between not is once within
syn keyword krlLibraries twitter amazon google odata rss
syn keyword krlWith with
syn keyword krlLibraries twitter amazon google odata rss provides
syn keyword krlWith with using
syn keyword krlAnd and
syn keyword krlKeywords rule every global meta ruleset dispatch choose current module tags
syn keyword krlAction log noop send_directive after alert annotate_search_results query annotate_local_search_results before float float_html let_it_snow move_after move_to_top noop notify close_notification percolate popup prepend redirect replace peplace_html replace_inner replace_image_src sidetab set_element_attr watch status_bar
Expand All @@ -61,7 +73,7 @@ syn keyword krlReserved names twitterId alias app authz sharing using second web

syn match krlSymbols "==\|=>\||"

syn keyword krlFunction function
syn keyword krlFunction function defaction
syn match krlBraces "[{}\[\]]"
syn match krlParens "[()]"

Expand Down

0 comments on commit 6f7e7c1

Please sign in to comment.