summaryrefslogtreecommitdiff
path: root/Util
diff options
context:
space:
mode:
Diffstat (limited to 'Util')
-rw-r--r--Util/ztst-ftplugin.vim29
-rw-r--r--Util/ztst-syntax.vim101
-rw-r--r--Util/zyodl.vim16
3 files changed, 143 insertions, 3 deletions
diff --git a/Util/ztst-ftplugin.vim b/Util/ztst-ftplugin.vim
new file mode 100644
index 000000000..60f2b526f
--- /dev/null
+++ b/Util/ztst-ftplugin.vim
@@ -0,0 +1,29 @@
+" ztst filetype plugin
+
+" Only do this when not done yet for this buffer
+if exists("b:did_ftplugin")
+ finish
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+" Inherit zsh.vim
+runtime! ftplugin/zsh.vim
+
+let b:undo_ftplugin .= "| setl fo< comments< commentstring<"
+
+" Set 'formatoptions' to break comment lines but not other lines,
+" and insert the comment leader when hitting <CR> or using "o".
+setlocal fo-=t fo+=croql
+
+" Set 'comments' to format expected output/errput lines
+setlocal comments+=:*>,:>,:*?,:?,:F:
+
+" Format comments to be up to 78 characters long
+if &textwidth == 0
+ setlocal textwidth=78
+endif
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
diff --git a/Util/ztst-syntax.vim b/Util/ztst-syntax.vim
new file mode 100644
index 000000000..a39fe3fbb
--- /dev/null
+++ b/Util/ztst-syntax.vim
@@ -0,0 +1,101 @@
+"" A Vim syntax highlighting file for Test/*.ztst
+"
+" See ../Util/zyodl.vim for installation instructions.
+" Also, it's recommended to 'setlocal conceallevel=3 concealcursor=nc'.
+"
+" See B01cd.ztst for cases we cover
+
+" TODO: Some zsh syntax isn't highlighted, e.g., «{ cd $0 }» doesn't highlight either 'cd' or '$0'
+" Apparently because the $VIMRUNTIME/syntax/zsh.vim zshBrackets group is defined as 'contains=TOP'?
+" https://bugs.debian.org/947120
+" TODO: ZTST_unimplemented ZTST_skip aren't recognized everywhere
+" I haven't found yet a legitimate use where they aren't highlighted, but
+" they aren't highlighted in theoretical cases such as (( ++ZTST_skip )).
+" (This example is theoretical because those variables are string-typed.)
+
+"" Boilerplate:
+if exists("b:current_syntax")
+ finish
+endif
+let s:cpo_save = &cpo
+set cpo&vim
+
+"" Syntax groups:
+syn clear
+
+syn include @zsh syntax/zsh.vim
+
+" Note that we don't do /^\s\zs.*/ here. If we did that, lines that start
+" with " #" (a space and a hash sign) would not be highlighted as comments,
+" because zshComment's patterns won't match unless the '#' is preceded by
+" a space or start-of-line. See:
+"
+" https://github.com/chrisbra/vim-zsh/issues/21#issuecomment-577738791
+syn match ztstPayload /^\s.*/ contains=@zsh
+
+syn match ztstExitCode /^\d\+\|^-/ nextgroup=ztstFlags
+syn match ztstFlags /[.dDqf]*:/ contained nextgroup=ztstTestName contains=ztstColon
+syn match ztstColon /:/ contained
+syn region ztstTestName start=// end=/$/ contained
+
+syn match ztstInputMarker /^</ nextgroup=ztstInput
+syn region ztstInput start=// end=/$/ contained
+
+syn match ztstOutputPattern /^[*]>/ nextgroup=ztstOutput contains=ztstOutputPatternSigil,ztstOutputPatternMarker
+syn match ztstOutputPatternSigil /[*]/ contained
+syn match ztstOutputPatternMarker /[>]/ contained conceal
+syn match ztstOutputLiteral /^>/ nextgroup=ztstOutput
+syn region ztstOutput start=// end=/$/ contained
+
+syn match ztstErrputPattern /^[*][?]/ nextgroup=ztstErrput contains=ztstErrputPatternSigil,ztstErrputPatternMarker
+syn match ztstErrputPatternSigil /[*]/ contained
+syn match ztstErrputPatternMarker /[?]/ contained conceal
+syn match ztstErrputLiteral /^[?]/ nextgroup=ztstErrput
+syn region ztstErrput start=// end=/$/ contained
+
+syn match ztstFrequentExplanationMarker /^F:/ nextgroup=ztstFrequentExplanation
+syn region ztstFrequentExplanation start=// end=/$/ contained
+
+syn match ztstDirective /^%.*/
+
+syn match ztstComment /^#.*/
+
+" Highlight those variables which are /de jure/ or /de facto/ APIs of the test
+" harness to the test files.
+syn keyword ztstSpecialVariable ZTST_unimplemented ZTST_skip ZTST_testdir ZTST_fd ZTST_srcdir containedin=@zsh
+
+"" Sync
+" The following is sufficient for our modest line-based format, and helps
+" sidestep problems resulting from test cases that use syntax constructs
+" that confuse us and/or syntax/zsh.vim. If we outgrow it, we should sync
+" on empty lines instead.
+"
+" If you run into syntax highlighting issues, just scroll the line that throws
+" the syntax highlighting off off the top of the screen.
+syn sync maxlines=1
+
+"" Highlight groups:
+hi def link ztstExitCode Number
+hi def link ztstFlags Normal
+hi def link ztstColon Ignore
+hi def link ztstTestName Title
+hi def link ztstInput Normal
+hi def link ztstInputMarker Ignore
+hi def link ztstOutput String
+hi def link ztstOutputPatternSigil Type
+hi def link ztstOutputPatternMarker Ignore
+hi def link ztstOutputLiteral Ignore
+hi def link ztstErrput Identifier
+hi def link ztstErrputPatternSigil Type
+hi def link ztstErrputPatternMarker Ignore
+hi def link ztstErrputLiteral Ignore
+hi def link ztstDirective Statement
+hi def link ztstComment Comment
+hi def link ztstFrequentExplanation PreProc
+hi def link ztstFrequentExplanationMarker Ignore
+hi def link ztstSpecialVariable Underlined
+
+"" Boilerplate:
+let b:current_syntax = "ztst"
+let &cpo = s:cpo_save
+unlet s:cpo_save
diff --git a/Util/zyodl.vim b/Util/zyodl.vim
index d0d3cf54f..7acd1dfaf 100644
--- a/Util/zyodl.vim
+++ b/Util/zyodl.vim
@@ -21,7 +21,10 @@
" xitem(foo)
" item(foo)(foo)
" sitem(foo)(foo foo)
+" COMMENT(foo var(foo) foo)
+" comment(foo)
" example(print *.c+LPAR()#q:s/#%+LPAR()#b+RPAR()s+LPAR()*+RPAR().c/'S${match[1]}.C'/+RPAR())
+" example(zargs -- **/*(.) -- ls -l)
" ifzman(zmanref(zshmisc))ifnzman(noderef(Redirection))
" LPAR()foo 42 foo+RPAR()
" chapter(foo (foo) foo)
@@ -35,6 +38,8 @@
if exists("b:current_syntax")
finish
endif
+let s:cpo_save = &cpo
+set cpo&vim
"" Syntax groups:
syn clear
@@ -48,7 +53,10 @@ syn match zyodlSpecial "+\?\<\(LPAR\|RPAR\|PLUS\)()"
syn match zyodlNumber "\d\+"
syn region zyodlItem start="\<xitem(" end=")" contains=zyodlSpecial,@zyodlInline
syn region zyodlItem start="\<item(" end=")" contains=zyodlSpecial,@zyodlInline
-syn region zyodlExample start="\<example(" end=")" contains=zyodlSpecial
+syn region zyodlExample start="\<example(" end=")" contains=zyodlSpecial,zyodlParenthetical
+syn region zyodlComment start="\<COMMENT(" end=")" contains=zyodlSpecial,@zyodlInline,zyodlParenthetical
+" comment that gets output in generated texinfo/roff source
+syn region zyodlComment start="\<comment(" end=")"
syn region zyodlTitle start="\<\(chapter\|subsect\|sect\)(" end=")" contains=zyodlSpecial,@zyodlInline,zyodlParenthetical
syn match zyodlTitle "^texinode(.*$"
syn region zyodlParenthetical start="\w\@<!(" end=")" transparent contained contains=zyodlParenthetical
@@ -68,11 +76,12 @@ hi def link zyodlVar Identifier
" Not ':hi def link zyodlBold Bold' since there's no such group.
hi def zyodlBold gui=bold cterm=bold
hi def link zyodlEmph Type
-hi def link zyodlIndex Comment
+hi def link zyodlIndex PreProc
hi def link zyodlSpecial Special
hi def link zyodlNumber Number
hi def link zyodlItem Keyword
hi def link zyodlExample String
+hi def link zyodlComment Comment
hi def link zyodlTitle Title
hi def link zyodlCond Conditional
hi def link zyodlRef Include
@@ -80,4 +89,5 @@ hi def link zyodlSItemArg1 Macro
hi def link zyodlSItemArg2 Underlined
let b:current_syntax = "zyodl"
-
+let &cpo = s:cpo_save
+unlet s:cpo_save