From 84ec4eedcdd2892249b5369f91a6dd1d12fef2fc Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Fri, 6 Sep 2019 14:32:07 +0200 Subject: Switch typescript provider, closes #428 --- syntax/tsx.vim | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 syntax/tsx.vim (limited to 'syntax/tsx.vim') diff --git a/syntax/tsx.vim b/syntax/tsx.vim new file mode 100644 index 00000000..c73e1bfc --- /dev/null +++ b/syntax/tsx.vim @@ -0,0 +1,144 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 + finish +endif + +if !exists("main_syntax") + if exists("b:current_syntax") && b:current_syntax != 'typescript' + finish + endif + let main_syntax = 'typescript.tsx' +endif + +syntax region tsxTag + \ start=+<\([^/!?<>="':]\+\)\@=+ + \ skip=+"']\+>+ + \ end=+/\@+ + \ end=+\(/>\)\@=+ + \ contained + \ contains=tsxTagName,tsxIntrinsicTagName,tsxAttrib,tsxEscJs, + \tsxCloseString,@tsxComment + +syntax match tsxTag /<>/ contained + + +" +" s~~~~~~~~~e +" and self close tag +" +" s~~~~e +" A big start regexp borrowed from https://git.io/vDyxc +syntax region tsxRegion + \ start=+<\_s*\z([a-zA-Z1-9\$_-]\+\(\.\k\+\)*\)+ + \ skip=++ + \ end=++ + \ matchgroup=tsxCloseString end=+/>+ + \ fold + \ contains=tsxRegion,tsxCloseString,tsxCloseTag,tsxTag,tsxCommentInvalid,tsxFragment,tsxEscJs,@Spell + \ keepend + \ extend + +" <> +" s~~~~~~e +" A big start regexp borrowed from https://git.io/vDyxc +syntax region tsxFragment + \ start=+\(\((\|{\|}\|\[\|,\|&&\|||\|?\|:\|=\|=>\|\Wreturn\|^return\|\Wdefault\|^\|>\)\_s*\)\@<=<>+ + \ skip=++ + \ end=++ + \ fold + \ contains=tsxRegion,tsxCloseString,tsxCloseTag,tsxTag,tsxCommentInvalid,tsxFragment,tsxEscJs,@Spell + \ keepend + \ extend + +" +" ~~~~~~ +syntax match tsxCloseTag + \ +"']\+>+ + \ contained + \ contains=tsxTagName,tsxIntrinsicTagName + +syntax match tsxCloseTag ++ contained + +syntax match tsxCloseString + \ +/>+ + \ contained + +" +" ~~~~~~~~ +syntax match tsxCommentInvalid // display + +syntax region tsxBlockComment + \ contained + \ start="/\*" + \ end="\*/" + +syntax match tsxLineComment + \ "//.*$" + \ contained + \ display + +syntax cluster tsxComment contains=tsxBlockComment,tsxLineComment + +syntax match tsxEntity "&[^; \t]*;" contains=tsxEntityPunct +syntax match tsxEntityPunct contained "[&.;]" + +" +" ~~~ +syntax match tsxTagName + \ +["'* ]\++hs=s+1 + \ contained + \ nextgroup=tsxAttrib + \ skipwhite + \ display +syntax match tsxIntrinsicTagName + \ +[ +" ~~~ +syntax match tsxAttrib + \ +[a-zA-Z_][-0-9a-zA-Z_]*+ + \ nextgroup=tsxEqual skipwhite + \ contained + \ display + +" +" ~ +syntax match tsxEqual +=+ display contained + \ nextgroup=tsxString skipwhite + +" +" s~~~~~~e +syntax region tsxString contained start=+"+ end=+"+ contains=tsxEntity,@Spell display + +" +" s~~~~~~~~~~~~~~e +syntax region tsxEscJs + \ contained + \ contains=@typescriptValue,@tsxComment + \ matchgroup=typescriptBraces + \ start=+{+ + \ end=+}+ + \ extend + +syntax cluster typescriptExpression add=tsxRegion,tsxFragment + +highlight def link tsxTag htmlTag +highlight def link tsxTagName Function +highlight def link tsxIntrinsicTagName htmlTagName +highlight def link tsxString String +highlight def link tsxNameSpace Function +highlight def link tsxCommentInvalid Error +highlight def link tsxBlockComment Comment +highlight def link tsxLineComment Comment +highlight def link tsxAttrib Type +highlight def link tsxEscJs tsxEscapeJs +highlight def link tsxCloseTag htmlTag +highlight def link tsxCloseString Identifier + +let b:current_syntax = "typescript.tsx" +if main_syntax == 'typescript.tsx' + unlet main_syntax +endif -- cgit v1.2.3