From 91a34032ca66181a8374daa419dce4d97537b5d5 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Mon, 21 Jun 2010 00:26:12 +0200 Subject: Fixed highlighting and xquery and xml syntax --- .vim/syntax/xml.vim | 344 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 344 insertions(+) create mode 100644 .vim/syntax/xml.vim (limited to '.vim/syntax/xml.vim') diff --git a/.vim/syntax/xml.vim b/.vim/syntax/xml.vim new file mode 100644 index 0000000..ee976ff --- /dev/null +++ b/.vim/syntax/xml.vim @@ -0,0 +1,344 @@ +" Vim syntax file +" Language: XML +" Maintainer: Johannes Zellner +" Author and previous maintainer: +" Paul Siegmann +" Last Change: Mi, 13 Apr 2005 22:40:09 CEST +" Filenames: *.xml +" $Id: xml.vim,v 1.3 2006/04/11 21:32:00 vimboss Exp $ + +" CONFIGURATION: +" syntax folding can be turned on by +" +" let g:xml_syntax_folding = 1 +" +" before the syntax file gets loaded (e.g. in ~/.vimrc). +" This might slow down syntax highlighting significantly, +" especially for large files. +" +" CREDITS: +" The original version was derived by Paul Siegmann from +" Claudio Fleiner's html.vim. +" +" REFERENCES: +" [1] http://www.w3.org/TR/2000/REC-xml-20001006 +" [2] http://www.w3.org/XML/1998/06/xmlspec-report-19980910.htm +" +" as pointed out according to reference [1] +" +" 2.3 Common Syntactic Constructs +" [4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender +" [5] Name ::= (Letter | '_' | ':') (NameChar)* +" +" 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. + + +" Quit when a syntax file was already loaded +if exists("b:current_syntax") + finish +endif + +let s:xml_cpo_save = &cpo +set cpo&vim + +syn case match + +" mark illegal characters +syn match xmlError "[<&]" + +" strings (inside tags) aka VALUES +" +" EXAMPLE: +" +" +" ^^^^^^^ +syn region xmlString contained start=+"+ end=+"+ contains=xmlEntity,@Spell display +syn region xmlString contained start=+'+ end=+'+ contains=xmlEntity,@Spell display + + +" punctuation (within attributes) e.g. +" ^ ^ +" syn match xmlAttribPunct +[-:._]+ contained display +syn match xmlAttribPunct +[:.]+ contained display + +" no highlighting for xmlEqual (xmlEqual has no highlighting group) +syn match xmlEqual +=+ display + + +" attribute, everything before the '=' +" +" PROVIDES: @xmlAttribHook +" +" EXAMPLE: +" +" +" ^^^^^^^^^^^^^ +" +syn match xmlAttrib + \ +[-'"<]\@\(['">]\@!\|$\)+ + \ contained + \ contains=xmlAttribPunct,@xmlAttribHook + \ display + + +" namespace spec +" +" PROVIDES: @xmlNamespaceHook +" +" EXAMPLE: +" +" +" ^^^ +" +if exists("g:xml_namespace_transparent") +syn match xmlNamespace + \ +\(<\|"':]\+[:]\@=+ + \ contained + \ contains=@xmlNamespaceHook + \ transparent + \ display +else +syn match xmlNamespace + \ +\(<\|"':]\+[:]\@=+ + \ contained + \ contains=@xmlNamespaceHook + \ display +endif + + +" tag name +" +" PROVIDES: @xmlTagHook +" +" EXAMPLE: +" +" +" ^^^ +" +syn match xmlTagName + \ +[<]\@<=[^ /!?<>"']\++ + \ contained + \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook + \ display + + +if exists('g:xml_syntax_folding') + + " start tag + " use matchgroup=xmlTag to skip over the leading '<' + " + " PROVIDES: @xmlStartTagHook + " + " EXAMPLE: + " + " + " s^^^^^^^^^^^^^^^e + " + syn region xmlTag + \ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+ + \ matchgroup=xmlTag end=+>+ + \ contained + \ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook + + + " highlight the end tag + " + " PROVIDES: @xmlTagHook + " (should we provide a separate @xmlEndTagHook ?) + " + " EXAMPLE: + " + " + " ^^^^^^ + " + syn match xmlEndTag + \ +"']\+>+ + \ contained + \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook + + + " tag elements with syntax-folding. + " NOTE: NO HIGHLIGHTING -- highlighting is done by contained elements + " + " PROVIDES: @xmlRegionHook + " + " EXAMPLE: + " + " + " + " + " + " some data + " + " + syn region xmlRegion + \ start=+<\z([^ /!?<>"']\+\)+ + \ skip=++ + \ end=++ + \ matchgroup=xmlEndTag end=+/>+ + \ fold + \ contains=xmlTag,xmlEndTag,xmlCdata,xmlRegion,xmlComment,xmlEntity,xmlProcessing,@xmlRegionHook,@Spell + \ keepend + \ extend + +else + + " no syntax folding: + " - contained attribute removed + " - xmlRegion not defined + " + syn region xmlTag + \ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+ + \ matchgroup=xmlTag end=+>+ + \ contains=xmlError,xmlTagName,xmlAttrib,xmlEqual,xmlString,@xmlStartTagHook + + syn match xmlEndTag + \ +"']\+>+ + \ contains=xmlNamespace,xmlAttribPunct,@xmlTagHook + +endif + + +" &entities; compare with dtd +syn match xmlEntity "&[^; \t]*;" contains=xmlEntityPunct +syn match xmlEntityPunct contained "[&.;]" + +if exists('g:xml_syntax_folding') + + " The real comments (this implements the comments as defined by xml, + " but not all xml pages actually conform to it. Errors are flagged. + syn region xmlComment + \ start=++ + \ contains=xmlCommentPart,xmlCommentError + \ extend + \ fold + +else + + " no syntax folding: + " - fold attribute removed + " + syn region xmlComment + \ start=++ + \ contains=xmlCommentPart,xmlCommentError + \ extend + +endif + +syn keyword xmlTodo contained TODO FIXME XXX +syn match xmlCommentError contained "[^>+ + \ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook,@Spell + \ keepend + \ extend + +" using the following line instead leads to corrupt folding at CDATA regions +" syn match xmlCdata ++ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook +syn match xmlCdataStart ++ contained + + +" Processing instructions +" This allows "?>" inside strings -- good idea? +syn region xmlProcessing matchgroup=xmlProcessingDelim start="" contains=xmlAttrib,xmlEqual,xmlString + + +if exists('g:xml_syntax_folding') + + " DTD -- we use dtd.vim here + syn region xmlDocType matchgroup=xmlDocTypeDecl + \ start="" + \ fold + \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString +else + + " no syntax folding: + " - fold attribute removed + " + syn region xmlDocType matchgroup=xmlDocTypeDecl + \ start="" + \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString + +endif + +syn keyword xmlDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM +syn region xmlInlineDTD contained matchgroup=xmlDocTypeDecl start="\[" end="]" contains=@xmlDTD +syn include @xmlDTD syntax/dtd.vim +unlet b:current_syntax + + +" synchronizing +" TODO !!! to be improved !!! + +syn sync match xmlSyncDT grouphere xmlDocType +\_.\(+ + +if exists('g:xml_syntax_folding') + syn sync match xmlSync grouphere xmlRegion +\_.\(<[^ /!?<>"']\+\)\@=+ + " syn sync match xmlSync grouphere xmlRegion "<[^ /!?<>"']*>" + syn sync match xmlSync groupthere xmlRegion +"']\+>+ +endif + +syn sync minlines=100 + + +" The default highlighting. +hi def link xmlTodo Todo +hi def link xmlTag Function +hi def link xmlTagName Function +hi def link xmlEndTag Function +if !exists("g:xml_namespace_transparent") + hi def link xmlNamespace Tag +endif +hi def link xmlEntity Statement +hi def link xmlEntityPunct Type + +hi def link xmlAttribPunct Comment +hi def link xmlAttrib Type + +hi def link xmlString String +hi def link xmlComment Comment +hi def link xmlCommentPart Comment +hi def link xmlCommentError Error +hi def link xmlError Error + +hi def link xmlProcessingDelim Comment +hi def link xmlProcessing Type + +hi def link xmlCdata String +hi def link xmlCdataCdata Statement +hi def link xmlCdataStart Type +hi def link xmlCdataEnd Type + +hi def link xmlDocTypeDecl Function +hi def link xmlDocTypeKeyword Statement +hi def link xmlInlineDTD Function + +let b:current_syntax = "xml" + +let &cpo = s:xml_cpo_save +unlet s:xml_cpo_save + +" vim: ts=8 -- cgit v1.2.3-70-g09d2