From 72cbf727d098310a3c4d7a57141601c375cac46e Mon Sep 17 00:00:00 2001 From: SimonFJ20 Date: Thu, 12 Dec 2024 13:35:05 +0100 Subject: [PATCH] add vim syntax --- editors/vim/ftdetect/slige.vim | 2 ++ editors/vim/ftplugin/slige.vim | 1 + editors/vim/indent/slige.vim | 23 +++++++++++++++++ editors/vim/syntax/slige.vim | 46 ++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 editors/vim/ftdetect/slige.vim create mode 100644 editors/vim/ftplugin/slige.vim create mode 100644 editors/vim/indent/slige.vim create mode 100644 editors/vim/syntax/slige.vim diff --git a/editors/vim/ftdetect/slige.vim b/editors/vim/ftdetect/slige.vim new file mode 100644 index 0000000..c6c33a8 --- /dev/null +++ b/editors/vim/ftdetect/slige.vim @@ -0,0 +1,2 @@ +autocmd BufNewFile,BufRead *.slg setfiletype slige +autocmd BufNewFile,BufRead *.slgbc setfiletype json diff --git a/editors/vim/ftplugin/slige.vim b/editors/vim/ftplugin/slige.vim new file mode 100644 index 0000000..3143dd1 --- /dev/null +++ b/editors/vim/ftplugin/slige.vim @@ -0,0 +1 @@ +setlocal commentstring=//%s diff --git a/editors/vim/indent/slige.vim b/editors/vim/indent/slige.vim new file mode 100644 index 0000000..a346897 --- /dev/null +++ b/editors/vim/indent/slige.vim @@ -0,0 +1,23 @@ +setlocal indentexpr=SligeIndent() + +function! SligeIndent() + let line = getline(v:lnum) + let previousNum = prevnonblank(v:lnum - 1) + let previous = getline(previousNum) + + if previous =~ "(" && previous !~ ")" && (line !~ ")" || line !~ "%)") + return indent(previousNum) + &shiftwidth + elseif (line =~ ")" || line =~ "%)") && line !~ "(" + return indent(previousNum) - &shiftwidth + elif previous =~ "{" && previous !~ "}" && (line !~ "}" || line !~ "%}") + return indent(previousNum) + &shiftwidth + elseif (line =~ "}" || line =~ "%}") && line !~ "{" + return indent(previousNum) - &shiftwidth + elif previous =~ "[" && previous !~ "]" && (line !~ "]" || line !~ "%]") + return indent(previousNum) + &shiftwidth + elseif (line =~ "]" || line =~ "%]") && line !~ "[" + return indent(previousNum) - &shiftwidth + else + return indent(previousNum) + endif +endfunction diff --git a/editors/vim/syntax/slige.vim b/editors/vim/syntax/slige.vim new file mode 100644 index 0000000..ad76993 --- /dev/null +++ b/editors/vim/syntax/slige.vim @@ -0,0 +1,46 @@ +" Vim syntax file +" Language: Slige +" Maintainer: SFJ +" Latest Revision: 1 January 1984 + +if exists("b:current_syntax") + finish +endif + +syn keyword Keyword break return let fn loop if else struct import or and not +syn keyword Special null +syn keyword Type int string +syn keyword Boolean true false + +syn match Operator '+' +syn match Operator '-' +syn match Operator '\*' +syn match Operator '/' +syn match Operator '=' +syn match Operator '==' +syn match Operator '!=' +syn match Operator '<' +syn match Operator '>' +syn match Operator '<=' +syn match Operator '>=' +syn match Operator '\.' +syn match Operator ':' +syn match Operator '->' + +syn match Number '0' +syn match Number '[1-9][0-9]*' +syn match Number '0[0-7]\+' +syn match Number '0x[0-9a-fA-F]\+' +syn match Number '0b[01]\+' + +syn region String start=+"+ skip=+\\"+ end=+"+ + +syn keyword Todo contained TODO FIXME XXX NOTE +syn match Comment "/\*.*\*/" contains=Todo +syn match Comment "//.*$" contains=Todo + +syn match Function '[a-zA-Z_]\w*\ze(' + +syn region sligeBlock start="{" end="}" transparent fold + +let b:current_syntax = "slige"