[xwt-users] vim syntax file

Rod Martin <[email protected]> Mon, 10 Nov 2003 14:09:47 -0500
Newsgroups gmane.comp.java.xwt.users
Organization Benshaw
Message-ID <[email protected]>
Here's a half-decent start at a vim syntax file.  (Even more half-decent than 
the one that was started earlier: 
http://lists.xwt.org/pipermail/users/2003-January/000064.html  :)

I took the xml.vim file by Paul Siegmann and made some changes to it to fit 
better with XWT.  It now imports javascript.vim and supplies a few extra 
highlighting features for traps, XWT keywords, and other XWT nuances.  It's 
not complete, though: most of <a 
href="http://www.xwt.org/reference.html#thexwtobject">these</a> are not 
getting highlighted yet.

I'll keep working away at it.  Comments/suggestions are welcome.

Rod

_______________________________________________
users mailing list
[email protected]
http://lists.xwt.org/listinfo/users
xwt.vim (text/plain, 8.5 KB)
" Vim syntax file
" Language:	XWT
" Maintainer:	Rod Martin <[email protected]>
" Last Change:	
" Filenames:	*.xwt

" CREDITS:
"   Adapted from xml.vim by Paul Siegmann
"
" REFERENCES:
"   [1] http://www.xwt.org/reference.html
"
" NOTE:
"   1) empty tag delimiters "/>" inside attribute values (strings)
"      confuse syntax highlighting.
"   2) for large files, folding can be pretty slow, especially when
"      loading a file the first time and viewoptions contains 'folds'
"      so that folds of previous sessions are applied.
"      Don't use 'foldmethod=syntax' in this case.
"   3) I left the CDATA and DTD stuff from xml.vim in but commented just in case...


" Quit when a syntax file was already loaded
if exists("b:current_syntax")
    finish
endif

let s:xwt_cpo_save = &cpo
set cpo&vim

syn case match

" mark illegal characters
syn match xwtError "[<&]"


" Import javascript highlighting
syn include @xwtECMAScript <sfile>:p:h/javascript.vim

" strings (inside tags) aka VALUES
"
" EXAMPLE:
"
" <tag foo.attribute = "value">
"                      ^^^^^^^
syn region  xwtString contained start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=xwtEntity display
syn region  xwtString contained start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=xwtEntity display

" no highlighting for xwtEqual (xwtEqual has no highlighting group)
syn match   xwtEqual +=+ display

syn keyword xwtTodo         contained TODO FIXME XXX


" =====  XML-ish Stuff ======================================================================================


" punctuation (within attributes) e.g. <tag xwt:foo.attribute ...>
"                                              ^   ^
" syn match   xwtAttribPunct +[-:._]+ contained display
syn match   xwtAttribPunct +[:.]+ contained display

" attribute, everything before the '='
"
" PROVIDES: @xwtAttribHook
"
" EXAMPLE:
"
" <tag foo.attribute = "value">
"      ^^^^^^^^^^^^^
"
syn match   xwtAttrib
    \ +[-'"<]\@<!\<[a-zA-Z:_][-.0-9a-zA-Z0-9:_]*\>\(['">]\@!\|$\)+
    \ contained
    \ contains=xwtAttribPunct,@xwtAttribHook
    \ display


" namespace spec
"
" PROVIDES: @xwtNamespaceHook
"
" EXAMPLE:
"
" <xsl:for-each select = "lola">
"  ^^^
"
if exists("g:xwt_namespace_transparent")
syn match   xwtNamespace
    \ +\(<\|</\)\@<=[^ /!?<>"':]\+[:]\@=+
    \ contained
    \ contains=@xwtNamespaceHook
    \ transparent
    \ display
else
syn match   xwtNamespace
    \ +\(<\|</\)\@<=[^ /!?<>"':]\+[:]\@=+
    \ contained
    \ contains=@xwtNamespaceHook
    \ display
endif


" tag name
"
" PROVIDES: @xwtTagHook
"
" EXAMPLE:
"
" <tag foo.attribute = "value">
"  ^^^
"
syn match   xwtTagName
    \ +[<]\@<=[^ /!?<>"']\++
    \ contained
    \ contains=xwtNamespace,xwtAttribPunct,@xwtTagHook
    \ display


" start tag
" use matchgroup=xwtTag to skip over the leading '<'
"
" PROVIDES: @xwtStartTagHook
"
" EXAMPLE:
"
" <tag id="whoops">
" s^^^^^^^^^^^^^^^e
"
syn region   xwtTag
    \ matchgroup=xwtTag start=+<[^ /!?<>"']\@=+
    \ matchgroup=xwtTag end=+>+
    \ contained
    \ contains=xwtError,xwtTagName,xwtAttrib,xwtEqual,xwtString,@xwtStartTagHook

" end tag name
"
" PROVIDES: @xwtTagHook
"
" EXAMPLE:
"
" </tag>
"   ^^^
"
syn match   xwtEndTagName
    \ +\(</\)\@<=[^ /!?<>"']\++
    \ contained
    \ contains=xwtNamespace,xwtAttribPunct,@xwtTagHook
    \ display


" highlight the end tag
"
" PROVIDES: @xwtTagHook
" (should we provide a separate @xwtEndTagHook ?)
"
" EXAMPLE:
"
" </tag>
" ^^^^^^
"
syn region   xwtEndTag
    \ matchgroup=xwtEndTag start=+</[^ /!?<>"']\@=+
    \ matchgroup=xwtEndTag end=+>+
    \ contained
    \ contains=xwtError,xwtEndTagName,@xwtTagHook


" tag elements with syntax-folding.
" NOTE: NO HIGHLIGHING -- highlighing is done by contained elements
"
" PROVIDES: @xwtRegionHook
"
" EXAMPLE:
"
" <tag id="whoops">
"   <!-- comment -->
"   <another.tag></another.tag>
"   <empty.tag/>
"   some data
" </tag>
"
syn region   xwtRegion
    \ start=+<\z([^ /!?<>"']\+\)+
    \ skip=+<!--\_.\{-}-->+
    \ end=+</\z1\_\s\{-}>+
    \ matchgroup=xwtEndTag end=+/>+
    \ fold
    \ contains=xwtTag,xwtEndTag,xwtCdata,xwtRegion,xwtHeaderComments,xwtComment,xwtComment2,xwtEntity,
    \     xwtProcessing,xwtTrap,xwtBoxRef,xwtBoxRefName,@xwtECMAScript,@xwtKeyword,@xwtRegionHook
    \ keepend
    \ extend


" &entities;
syn match   xwtEntity                 "&[^; \t]*;" contains=xwtEntityPunct
syn match   xwtEntityPunct  contained "[&.;]"


" Comments 

" FIXME: The start= regex isn't very efficient, but I couldn't get anything else to work
syn region  xwtHeaderComments
    \ start=+\(<xwt>\_.\)\@<=\_.+     
    \ end=+\(<static\|<template\|<import\|<preapply\|<redirect\|<postapply\)\@=+
    \ contains=xwtTodo
    \ extend

syn region  xwtComment start=+<!--+ end=+-->+ contains=xwtTodo,xwtCommentError extend
syn region  xwtComment2 start=+//+ end=+\n+ contains=xwtTodo keepend
"syn match   xwtCommentError contained "[^><!]"





" =====  XWT-Specific Stuff  ======================================================================================

" The '+=' or '-=' of a trap
syn match  xwtTrap        "\(\(+=\)\|\(-=\)\)\(\s*function\)\@=" contained

" In a box reference '$foo',  '$' is the xwtBoxRef and 'foo' is the xwtBoxRefName
syn match  xwtBoxRef      "\$\(\w\+\)\@=" contained
syn match  xwtBoxRefName  "\$\@<=\(\w\+\)" contained


" XWT keywords
syn cluster xwtKeyword      contains=xwt_thisbox,xwt_xwt,xwt_box,xwt_null,xwt_root

syn keyword xwt_thisbox     contained thisbox
syn keyword xwt_xwt         contained xwt
syn keyword xwt_box         contained box
syn keyword xwt_root        contained root
syn keyword xwt_null        contained null NULL


" XWT functions


" ================================================================================================================


" CData sections
"
" PROVIDES: @xwtCdataHook
"
"syn region    xwtCdata
"    \ start=+<!\[CDATA\[+
"    \ end=+]]>+
"    \ contains=xwtCdataStart,xwtCdataEnd,@xwtCdataHook
"    \ keepend
"    \ extend

" using the following line instead leads to corrupt folding at CDATA regions
" syn match    xwtCdata      +<!\[CDATA\[\_.\{-}]]>+  contains=xwtCdataStart,xwtCdataEnd,@xwtCdataHook
"syn match    xwtCdataStart +<!\[CDATA\[+  contained contains=xwtCdataCdata
"syn keyword  xwtCdataCdata CDATA          contained
"syn match    xwtCdataEnd   +]]>+          contained


" Processing instructions
" This allows "?>" inside strings -- good idea?
"syn region  xwtProcessing matchgroup=xwtProcessingDelim start="<?" end="?>" contains=xwtAttrib,xwtEqual,xwtString


" DTD -- we use dtd.vim here
"syn region  xwtDocType matchgroup=xwtDocTypeDecl
"    \ start="<!DOCTYPE"he=s+2,rs=s+2 end=">"
"    \ fold
"    \ contains=xwtDocTypeKeyword,xwtInlineDTD,xwtString
"syn keyword xwtDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM
"syn region  xwtInlineDTD contained matchgroup=xwtDocTypeDecl start="\[" end="]" contains=@xwtDTD
"syn include @xwtDTD <sfile>:p:h/dtd.vim
"unlet b:current_syntax


" synchronizing
" TODO !!! to be improved !!!

"syn sync match xwtSyncDT grouphere  xwtDocType +\_.\(<!DOCTYPE\)\@=+
" syn sync match xwtSyncDT groupthere  NONE       +]>+

syn sync match xwtSync grouphere   xwtRegion  +\_.\(<[^ /!?<>"']\+\)\@=+
" syn sync match xwtSync grouphere  xwtRegion "<[^ /!?<>"']*>"
syn sync match xwtSync groupthere  xwtRegion  +</[^ /!?<>"']\+>+

syn sync minlines=100


" The default highlighting.
hi def link xwtTodo		Todo
hi def link xwtTag		Function
hi def link xwtTagName		Statement
hi def link xwtEndTag		Function
hi def link xwtEndTagName       Statement
if !exists("g:xwt_namespace_transparent")
    hi def link xwtNamespace	Tag
endif
hi def link xwtEntity		Statement
hi def link xwtEntityPunct	Statement

hi def link xwtAttribPunct	Normal
hi def link xwtAttrib		Identifier

hi def link xwtTrap             Special
hi def link xwtBoxRef           Special     
hi def link xwtBoxRefName       Keyword     
hi def link xwt_thisbox         Keyword

" Keywords
hi def link xwt_xwt             Keyword
hi def link xwt_box             Keyword
hi def link xwt_root            Keyword
hi def link xwt_null            Special

hi def link xwtString		String
hi def link xwtHeaderComments	Comment
hi def link xwtComment		Comment
hi def link xwtComment2		Comment
hi def link xwtCommentPart	Comment
hi def link xwtCommentError	Error
hi def link xwtError		Error

hi def link xwtProcessingDelim	Comment
hi def link xwtProcessing	Type

"hi def link xwtCdata		String
"hi def link xwtCdataCdata	Statement
"hi def link xwtCdataStart	Type
"hi def link xwtCdataEnd	Type

"hi def link xwtDocTypeDecl	Function
"hi def link xwtDocTypeKeyword	Statement
"hi def link xwtInlineDTD	Function

let b:current_syntax = "xwt"

let &cpo = s:xwt_cpo_save
unlet s:xwt_cpo_save

" vim: ts=8