neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

typescriptreact.vim (4095B)


      1 " Vim syntax file
      2 " Language:     TypeScript with React (JSX)
      3 " Maintainer:   The Vim Project <https://github.com/vim/vim>
      4 " Last Change:  2024 May 26
      5 " Based On:     Herrington Darkholme's yats.vim
      6 " Changes:      See https://github.com/HerringtonDarkholme/yats.vim
      7 " Credits:      See yats.vim on github
      8 
      9 if !exists("main_syntax")
     10  if exists("b:current_syntax")
     11    finish
     12  endif
     13  let main_syntax = 'typescriptreact'
     14 endif
     15 
     16 let s:cpo_save = &cpo
     17 set cpo&vim
     18 
     19 syntax region tsxTag
     20      \ start=+<\([^/!?<>="':]\+\)\@=+
     21      \ skip=+</[^ /!?<>"']\+>+
     22      \ end=+/\@<!>+
     23      \ end=+\(/>\)\@=+
     24      \ contained
     25      \ contains=tsxTagName,tsxIntrinsicTagName,tsxAttrib,tsxEscJs,
     26                \tsxCloseString,@tsxComment
     27 
     28 syntax match tsxTag /<>/ contained
     29 
     30 
     31 " <tag></tag>
     32 " s~~~~~~~~~e
     33 " and self close tag
     34 " <tag/>
     35 " s~~~~e
     36 " A big start regexp borrowed from https://git.io/vDyxc
     37 syntax region tsxRegion
     38      \ start=+<\_s*\z([a-zA-Z1-9\$_-]\+\(\.\k\+\)*\)+
     39      \ skip=+<!--\_.\{-}-->+
     40      \ end=+</\_s*\z1>+
     41      \ matchgroup=tsxCloseString end=+/>+
     42      \ fold
     43      \ contains=tsxRegion,tsxCloseString,tsxCloseTag,tsxTag,tsxCommentInvalid,tsxFragment,tsxEscJs,@Spell
     44      \ keepend
     45      \ extend
     46 
     47 " <>   </>
     48 " s~~~~~~e
     49 " A big start regexp borrowed from https://git.io/vDyxc
     50 syntax region tsxFragment
     51      \ start=+\(\((\|{\|}\|\[\|,\|&&\|||\|?\|:\|=\|=>\|\Wreturn\|^return\|\Wdefault\|^\|>\)\_s*\)\@<=<>+
     52      \ skip=+<!--\_.\{-}-->+
     53      \ end=+</>+
     54      \ fold
     55      \ contains=tsxRegion,tsxCloseString,tsxCloseTag,tsxTag,tsxCommentInvalid,tsxFragment,tsxEscJs,@Spell
     56      \ keepend
     57      \ extend
     58 
     59 " </tag>
     60 " ~~~~~~
     61 syntax match tsxCloseTag
     62      \ +</\_s*[^/!?<>"']\+>+
     63      \ contained
     64      \ contains=tsxTagName,tsxIntrinsicTagName
     65 
     66 syntax match tsxCloseTag +</>+ contained
     67 
     68 syntax match tsxCloseString
     69      \ +/>+
     70      \ contained
     71 
     72 " <!-- -->
     73 " ~~~~~~~~
     74 syntax match tsxCommentInvalid /<!--\_.\{-}-->/ display
     75 
     76 syntax region tsxBlockComment
     77    \ contained
     78    \ start="/\*"
     79    \ end="\*/"
     80 
     81 syntax match tsxLineComment
     82    \ "//.*$"
     83    \ contained
     84    \ display
     85 
     86 syntax cluster tsxComment contains=tsxBlockComment,tsxLineComment
     87 
     88 syntax match tsxEntity "&[^; \t]*;" contains=tsxEntityPunct
     89 syntax match tsxEntityPunct contained "[&.;]"
     90 
     91 " <tag key={this.props.key}>
     92 "  ~~~
     93 syntax match tsxTagName
     94    \ +[</]\_s*[^/!?<>"'* ]\++hs=s+1
     95    \ contained
     96    \ nextgroup=tsxAttrib
     97    \ skipwhite
     98    \ display
     99 syntax match tsxIntrinsicTagName
    100    \ +[</]\_s*[a-z1-9-]\++hs=s+1
    101    \ contained
    102    \ nextgroup=tsxAttrib
    103    \ skipwhite
    104    \ display
    105 
    106 " <tag key={this.props.key}>
    107 "      ~~~
    108 syntax match tsxAttrib
    109    \ +[a-zA-Z_][-0-9a-zA-Z_]*+
    110    \ nextgroup=tsxEqual skipwhite
    111    \ contained
    112    \ display
    113 
    114 " <tag id="sample">
    115 "        ~
    116 syntax match tsxEqual +=+ display contained
    117  \ nextgroup=tsxString skipwhite
    118 
    119 " <tag id="sample">
    120 "         s~~~~~~e
    121 syntax region tsxString contained start=+"+ skip=+\\"+ end=+"+ contains=tsxEntity,@Spell display
    122 syntax region tsxString contained start=+'+ skip=+\\'+ end=+'+ contains=tsxEntity,@Spell display
    123 
    124 " <tag key={this.props.key}>
    125 "          s~~~~~~~~~~~~~~e
    126 syntax region tsxEscJs
    127    \ contained
    128    \ contains=@typescriptValue,@tsxComment,typescriptObjectSpread
    129    \ matchgroup=typescriptBraces
    130    \ start=+{+
    131    \ end=+}+
    132    \ extend
    133 
    134 
    135 """""""""""""""""""""""""""""""""""""""""""""""""""
    136 " Source the part common with typescriptreact.vim
    137 source <sfile>:h/shared/typescriptcommon.vim
    138 
    139 
    140 syntax cluster typescriptExpression add=tsxRegion,tsxFragment
    141 
    142 hi def link tsxTag htmlTag
    143 hi def link tsxTagName Function
    144 hi def link tsxIntrinsicTagName htmlTagName
    145 hi def link tsxString String
    146 hi def link tsxNameSpace Function
    147 hi def link tsxCommentInvalid Error
    148 hi def link tsxBlockComment Comment
    149 hi def link tsxLineComment Comment
    150 hi def link tsxAttrib Type
    151 hi def link tsxEscJs tsxEscapeJs
    152 hi def link tsxCloseTag htmlTag
    153 hi def link tsxCloseString Identifier
    154 
    155 let b:current_syntax = "typescriptreact"
    156 if main_syntax == 'typescriptreact'
    157  unlet main_syntax
    158 endif
    159 
    160 let &cpo = s:cpo_save
    161 unlet s:cpo_save