diff options
Diffstat (limited to 'syntax/basic')
| -rw-r--r-- | syntax/basic/class.vim | 69 | ||||
| -rw-r--r-- | syntax/basic/cluster.vim | 42 | ||||
| -rw-r--r-- | syntax/basic/decorator.vim | 7 | ||||
| -rw-r--r-- | syntax/basic/doc.vim | 87 | ||||
| -rw-r--r-- | syntax/basic/function.vim | 71 | ||||
| -rw-r--r-- | syntax/basic/identifiers.vim | 33 | ||||
| -rw-r--r-- | syntax/basic/keyword.vim | 95 | ||||
| -rw-r--r-- | syntax/basic/literal.vim | 47 | ||||
| -rw-r--r-- | syntax/basic/members.vim | 50 | ||||
| -rw-r--r-- | syntax/basic/object.vim | 32 | ||||
| -rw-r--r-- | syntax/basic/patch.vim | 9 | ||||
| -rw-r--r-- | syntax/basic/reserved.vim | 35 | ||||
| -rw-r--r-- | syntax/basic/symbols.vim | 42 | ||||
| -rw-r--r-- | syntax/basic/type.vim | 191 | 
14 files changed, 810 insertions, 0 deletions
| diff --git a/syntax/basic/class.vim b/syntax/basic/class.vim new file mode 100644 index 00000000..ab834390 --- /dev/null +++ b/syntax/basic/class.vim @@ -0,0 +1,69 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +"don't add typescriptMembers to nextgroup, let outer scope match it +" so we won't match abstract method outside abstract class +syntax keyword typescriptAbstract              abstract +  \ nextgroup=typescriptClassKeyword +  \ skipwhite skipnl +syntax keyword typescriptClassKeyword          class +  \ nextgroup=typescriptClassName,typescriptClassExtends,typescriptClassBlock +  \ skipwhite + +syntax match   typescriptClassName             contained /\K\k*/ +  \ nextgroup=typescriptClassBlock,typescriptClassExtends,typescriptClassTypeParameter +  \ skipwhite skipnl + +syntax region typescriptClassTypeParameter +  \ start=/</ end=/>/ +  \ contains=typescriptTypeParameter +  \ nextgroup=typescriptClassBlock,typescriptClassExtends +  \ contained skipwhite skipnl + +syntax keyword typescriptClassExtends          contained extends implements nextgroup=typescriptClassHeritage skipwhite skipnl + +syntax match   typescriptClassHeritage         contained /\v(\k|\.|\(|\))+/ +  \ nextgroup=typescriptClassBlock,typescriptClassExtends,typescriptMixinComma,typescriptClassTypeArguments +  \ contains=@typescriptValue +  \ skipwhite skipnl +  \ contained + +syntax region typescriptClassTypeArguments matchgroup=typescriptTypeBrackets +  \ start=/</ end=/>/ +  \ contains=@typescriptType +  \ nextgroup=typescriptClassExtends,typescriptClassBlock,typescriptMixinComma +  \ contained skipwhite skipnl + +syntax match typescriptMixinComma /,/ contained nextgroup=typescriptClassHeritage skipwhite skipnl + +" we need add arrowFunc to class block for high order arrow func +" see test case +syntax region  typescriptClassBlock matchgroup=typescriptBraces start=/{/ end=/}/ +  \ contains=@typescriptPropertyMemberDeclaration,typescriptAbstract,@typescriptComments,typescriptBlock,typescriptAssign,typescriptDecorator,typescriptAsyncFuncKeyword,typescriptArrowFunc +  \ contained fold + +syntax keyword typescriptInterfaceKeyword          interface nextgroup=typescriptInterfaceName skipwhite +syntax match   typescriptInterfaceName             contained /\k\+/ +  \ nextgroup=typescriptObjectType,typescriptInterfaceExtends,typescriptInterfaceTypeParameter +  \ skipwhite skipnl +syntax region typescriptInterfaceTypeParameter +  \ start=/</ end=/>/ +  \ contains=typescriptTypeParameter +  \ nextgroup=typescriptObjectType,typescriptInterfaceExtends +  \ contained +  \ skipwhite skipnl + +syntax keyword typescriptInterfaceExtends          contained extends nextgroup=typescriptInterfaceHeritage skipwhite skipnl + +syntax match typescriptInterfaceHeritage contained /\v(\k|\.)+/ +  \ nextgroup=typescriptObjectType,typescriptInterfaceComma,typescriptInterfaceTypeArguments +  \ skipwhite + +syntax region typescriptInterfaceTypeArguments matchgroup=typescriptTypeBrackets +  \ start=/</ end=/>/ skip=/\s*,\s*/ +  \ contains=@typescriptType +  \ nextgroup=typescriptObjectType,typescriptInterfaceComma +  \ contained skipwhite + +syntax match typescriptInterfaceComma /,/ contained nextgroup=typescriptInterfaceHeritage skipwhite skipnl diff --git a/syntax/basic/cluster.vim b/syntax/basic/cluster.vim new file mode 100644 index 00000000..0188aa98 --- /dev/null +++ b/syntax/basic/cluster.vim @@ -0,0 +1,42 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +"Block VariableStatement EmptyStatement ExpressionStatement IfStatement IterationStatement ContinueStatement BreakStatement ReturnStatement WithStatement LabelledStatement SwitchStatement ThrowStatement TryStatement DebuggerStatement +syntax cluster typescriptStatement +  \ contains=typescriptBlock,typescriptVariable, +  \ @typescriptTopExpression,typescriptAssign, +  \ typescriptConditional,typescriptRepeat,typescriptBranch, +  \ typescriptLabel,typescriptStatementKeyword, +  \ typescriptFuncKeyword, +  \ typescriptTry,typescriptExceptions,typescriptDebugger, +  \ typescriptExport,typescriptInterfaceKeyword,typescriptEnum, +  \ typescriptModule,typescriptAliasKeyword,typescriptImport + +syntax cluster typescriptPrimitive  contains=typescriptString,typescriptTemplate,typescriptRegexpString,typescriptNumber,typescriptBoolean,typescriptNull,typescriptArray + +syntax cluster typescriptEventTypes            contains=typescriptEventString,typescriptTemplate,typescriptNumber,typescriptBoolean,typescriptNull + +" top level expression: no arrow func +" also no func keyword. funcKeyword is contained in statement +" funcKeyword allows overloading (func without body) +" funcImpl requires body +syntax cluster typescriptTopExpression +  \ contains=@typescriptPrimitive, +  \ typescriptIdentifier,typescriptIdentifierName, +  \ typescriptOperator,typescriptUnaryOp, +  \ typescriptParenExp,typescriptRegexpString, +  \ typescriptGlobal,typescriptAsyncFuncKeyword, +  \ typescriptClassKeyword,typescriptTypeCast + +" no object literal, used in type cast and arrow func +" TODO: change func keyword to funcImpl +syntax cluster typescriptExpression +  \ contains=@typescriptTopExpression, +  \ typescriptArrowFuncDef, +  \ typescriptFuncImpl + +syntax cluster typescriptValue +  \ contains=@typescriptExpression,typescriptObjectLiteral + +syntax cluster typescriptEventExpression       contains=typescriptArrowFuncDef,typescriptParenExp,@typescriptValue,typescriptRegexpString,@typescriptEventTypes,typescriptOperator,typescriptGlobal,jsxRegion diff --git a/syntax/basic/decorator.vim b/syntax/basic/decorator.vim new file mode 100644 index 00000000..c27b9b7e --- /dev/null +++ b/syntax/basic/decorator.vim @@ -0,0 +1,7 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +syntax match typescriptDecorator /@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>/ +  \ nextgroup=typescriptArgumentList,typescriptTypeArguments +  \ contains=@_semantic,typescriptDotNotation diff --git a/syntax/basic/doc.vim b/syntax/basic/doc.vim new file mode 100644 index 00000000..d5e43e34 --- /dev/null +++ b/syntax/basic/doc.vim @@ -0,0 +1,87 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +"Syntax coloring for Node.js shebang line +syntax match   shellbang "^#!.*node\>" +syntax match   shellbang "^#!.*iojs\>" + + +"JavaScript comments +syntax keyword typescriptCommentTodo TODO FIXME XXX TBD +syntax match   typescriptLineComment "//.*" +  \ contains=@Spell,typescriptCommentTodo,typescriptRef +syntax region  typescriptComment +  \ start="/\*"  end="\*/" +  \ contains=@Spell,typescriptCommentTodo extend +syntax cluster typescriptComments +  \ contains=typescriptDocComment,typescriptComment,typescriptLineComment + +syntax match   typescriptRef  +///\s*<reference\s\+.*\/>$+ +  \ contains=typescriptString +syntax match   typescriptRef  +///\s*<amd-dependency\s\+.*\/>$+ +  \ contains=typescriptString +syntax match   typescriptRef  +///\s*<amd-module\s\+.*\/>$+ +  \ contains=typescriptString + +"JSDoc +syntax case ignore + +syntax region  typescriptDocComment            matchgroup=typescriptComment +  \ start="/\*\*"  end="\*/" +  \ contains=typescriptDocNotation,typescriptCommentTodo,@Spell +  \ fold keepend +syntax match   typescriptDocNotation           contained /@/ nextgroup=typescriptDocTags + +syntax keyword typescriptDocTags               contained constant constructor constructs function ignore inner private public readonly static +syntax keyword typescriptDocTags               contained const dict expose inheritDoc interface nosideeffects override protected struct internal +syntax keyword typescriptDocTags               contained example global +syntax keyword typescriptDocTags               contained alpha beta defaultValue eventProperty experimental label +syntax keyword typescriptDocTags               contained packageDocumentation privateRemarks remarks sealed typeParam + +" syntax keyword typescriptDocTags               contained ngdoc nextgroup=typescriptDocNGDirective +syntax keyword typescriptDocTags               contained ngdoc scope priority animations +syntax keyword typescriptDocTags               contained ngdoc restrict methodOf propertyOf eventOf eventType nextgroup=typescriptDocParam skipwhite +syntax keyword typescriptDocNGDirective        contained overview service object function method property event directive filter inputType error + +syntax keyword typescriptDocTags               contained abstract virtual access augments + +syntax keyword typescriptDocTags               contained arguments callback lends memberOf name type kind link mixes mixin tutorial nextgroup=typescriptDocParam skipwhite +syntax keyword typescriptDocTags               contained variation nextgroup=typescriptDocNumParam skipwhite + +syntax keyword typescriptDocTags               contained author class classdesc copyright default defaultvalue nextgroup=typescriptDocDesc skipwhite +syntax keyword typescriptDocTags               contained deprecated description external host nextgroup=typescriptDocDesc skipwhite +syntax keyword typescriptDocTags               contained file fileOverview overview namespace requires since version nextgroup=typescriptDocDesc skipwhite +syntax keyword typescriptDocTags               contained summary todo license preserve nextgroup=typescriptDocDesc skipwhite + +syntax keyword typescriptDocTags               contained borrows exports nextgroup=typescriptDocA skipwhite +syntax keyword typescriptDocTags               contained param arg argument property prop module nextgroup=typescriptDocNamedParamType,typescriptDocParamName skipwhite +syntax keyword typescriptDocTags               contained define enum extends implements this typedef nextgroup=typescriptDocParamType skipwhite +syntax keyword typescriptDocTags               contained return returns throws exception nextgroup=typescriptDocParamType,typescriptDocParamName skipwhite +syntax keyword typescriptDocTags               contained see nextgroup=typescriptDocRef skipwhite + +syntax keyword typescriptDocTags               contained function func method nextgroup=typescriptDocName skipwhite +syntax match   typescriptDocName               contained /\h\w*/ + +syntax keyword typescriptDocTags               contained fires event nextgroup=typescriptDocEventRef skipwhite +syntax match   typescriptDocEventRef           contained /\h\w*#\(\h\w*\:\)\?\h\w*/ + +syntax match   typescriptDocNamedParamType     contained /{.\+}/ nextgroup=typescriptDocParamName skipwhite +syntax match   typescriptDocParamName          contained /\[\?0-9a-zA-Z_\.]\+\]\?/ nextgroup=typescriptDocDesc skipwhite +syntax match   typescriptDocParamType          contained /{.\+}/ nextgroup=typescriptDocDesc skipwhite +syntax match   typescriptDocA                  contained /\%(#\|\w\|\.\|:\|\/\)\+/ nextgroup=typescriptDocAs skipwhite +syntax match   typescriptDocAs                 contained /\s*as\s*/ nextgroup=typescriptDocB skipwhite +syntax match   typescriptDocB                  contained /\%(#\|\w\|\.\|:\|\/\)\+/ +syntax match   typescriptDocParam              contained /\%(#\|\w\|\.\|:\|\/\|-\)\+/ +syntax match   typescriptDocNumParam           contained /\d\+/ +syntax match   typescriptDocRef                contained /\%(#\|\w\|\.\|:\|\/\)\+/ +syntax region  typescriptDocLinkTag            contained matchgroup=typescriptDocLinkTag start=/{/ end=/}/ contains=typescriptDocTags + +syntax cluster typescriptDocs                  contains=typescriptDocParamType,typescriptDocNamedParamType,typescriptDocParam + +if main_syntax == "typescript" +  syntax sync clear +  syntax sync ccomment typescriptComment minlines=200 +endif + +syntax case match diff --git a/syntax/basic/function.vim b/syntax/basic/function.vim new file mode 100644 index 00000000..db93b368 --- /dev/null +++ b/syntax/basic/function.vim @@ -0,0 +1,71 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +syntax keyword typescriptAsyncFuncKeyword      async +  \ nextgroup=typescriptFuncKeyword,typescriptArrowFuncDef +  \ skipwhite + +syntax keyword typescriptAsyncFuncKeyword      await +  \ nextgroup=@typescriptValue +  \ skipwhite + +syntax keyword typescriptFuncKeyword           function +  \ nextgroup=typescriptAsyncFunc,typescriptFuncName,@typescriptCallSignature +  \ skipwhite skipempty + +syntax match   typescriptAsyncFunc             contained /*/ +  \ nextgroup=typescriptFuncName,@typescriptCallSignature +  \ skipwhite skipempty + +syntax match   typescriptFuncName              contained /\K\k*/ +  \ nextgroup=@typescriptCallSignature +  \ skipwhite + +" destructuring ({ a: ee }) => +syntax match   typescriptArrowFuncDef          contained /({\_[^}]*}\(:\_[^)]\)\?)\s*=>/ +  \ contains=typescriptArrowFuncArg,typescriptArrowFunc +  \ nextgroup=@typescriptExpression,typescriptBlock +  \ skipwhite skipempty + +" matches `(a) =>` or `([a]) =>` or +" `( +"  a) =>` +syntax match   typescriptArrowFuncDef          contained /(\(\_s*[a-zA-Z\$_\[.]\_[^)]*\)*)\s*=>/ +  \ contains=typescriptArrowFuncArg,typescriptArrowFunc +  \ nextgroup=@typescriptExpression,typescriptBlock +  \ skipwhite skipempty + +syntax match   typescriptArrowFuncDef          contained /\K\k*\s*=>/ +  \ contains=typescriptArrowFuncArg,typescriptArrowFunc +  \ nextgroup=@typescriptExpression,typescriptBlock +  \ skipwhite skipempty + +" TODO: optimize this pattern +syntax region   typescriptArrowFuncDef          contained start=/(\_[^)]*):/ end=/=>/ +  \ contains=typescriptArrowFuncArg,typescriptArrowFunc,typescriptTypeAnnotation +  \ nextgroup=@typescriptExpression,typescriptBlock +  \ skipwhite skipempty keepend + +syntax match   typescriptArrowFunc             /=>/ +syntax match   typescriptArrowFuncArg          contained /\K\k*/ +syntax region  typescriptArrowFuncArg          contained start=/<\|(/ end=/\ze=>/ contains=@typescriptCallSignature + +syntax region typescriptReturnAnnotation contained start=/:/ end=/{/me=e-1 contains=@typescriptType nextgroup=typescriptBlock + + +syntax region typescriptFuncImpl contained start=/function/ end=/{/me=e-1 +  \ contains=typescriptFuncKeyword +  \ nextgroup=typescriptBlock + +syntax cluster typescriptCallImpl contains=typescriptGenericImpl,typescriptParamImpl +syntax region typescriptGenericImpl matchgroup=typescriptTypeBrackets +  \ start=/</ end=/>/ skip=/\s*,\s*/ +  \ contains=typescriptTypeParameter +  \ nextgroup=typescriptParamImpl +  \ contained skipwhite +syntax region typescriptParamImpl matchgroup=typescriptParens +  \ start=/(/ end=/)/ +  \ contains=typescriptDecorator,@typescriptParameterList,@typescriptComments +  \ nextgroup=typescriptReturnAnnotation,typescriptBlock +  \ contained skipwhite skipnl diff --git a/syntax/basic/identifiers.vim b/syntax/basic/identifiers.vim new file mode 100644 index 00000000..2a88102c --- /dev/null +++ b/syntax/basic/identifiers.vim @@ -0,0 +1,33 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +syntax cluster afterIdentifier contains= +  \ typescriptDotNotation, +  \ typescriptFuncCallArg, +  \ typescriptTemplate, +  \ typescriptIndexExpr, +  \ @typescriptSymbols, +  \ typescriptTypeArguments + +syntax match   typescriptIdentifierName        /\<\K\k*/ +  \ nextgroup=@afterIdentifier +  \ transparent +  \ contains=@_semantic +  \ skipnl skipwhite + +syntax match   typescriptProp contained /\K\k*!\?/ +  \ transparent +  \ contains=@props +  \ nextgroup=@afterIdentifier +  \ skipwhite skipempty + +syntax region  typescriptIndexExpr      contained matchgroup=typescriptProperty start=/\[/rs=s+1 end=/]/he=e-1 contains=@typescriptValue nextgroup=@typescriptSymbols,typescriptDotNotation,typescriptFuncCallArg skipwhite skipempty + +syntax match   typescriptDotNotation           /\./ nextgroup=typescriptProp skipnl +syntax match   typescriptDotStyleNotation      /\.style\./ nextgroup=typescriptDOMStyle transparent +" syntax match   typescriptFuncCall              contained /[a-zA-Z]\k*\ze(/ nextgroup=typescriptFuncCallArg +syntax region  typescriptParenExp              matchgroup=typescriptParens start=/(/ end=/)/ contains=@typescriptComments,@typescriptValue,typescriptCastKeyword nextgroup=@typescriptSymbols skipwhite skipempty +syntax region  typescriptFuncCallArg           contained matchgroup=typescriptParens start=/(/ end=/)/ contains=@typescriptValue,@typescriptComments nextgroup=@typescriptSymbols,typescriptDotNotation skipwhite skipempty skipnl +syntax region  typescriptEventFuncCallArg      contained matchgroup=typescriptParens start=/(/ end=/)/ contains=@typescriptEventExpression +syntax region  typescriptEventString           contained start=/\z(["']\)/  skip=/\\\\\|\\\z1\|\\\n/  end=/\z1\|$/ contains=typescriptASCII,@events diff --git a/syntax/basic/keyword.vim b/syntax/basic/keyword.vim new file mode 100644 index 00000000..999dca07 --- /dev/null +++ b/syntax/basic/keyword.vim @@ -0,0 +1,95 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +"Import +syntax keyword typescriptImport                from as import +syntax keyword typescriptExport                export +syntax keyword typescriptModule                namespace module + +"this + +"JavaScript Prototype +syntax keyword typescriptPrototype             prototype +  \ nextgroup=@afterIdentifier + +syntax keyword typescriptCastKeyword           as +  \ nextgroup=@typescriptType +  \ skipwhite + +"Program Keywords +syntax keyword typescriptIdentifier            arguments this super +  \ nextgroup=@afterIdentifier + +syntax keyword typescriptVariable              let var +  \ nextgroup=typescriptVariableDeclaration +  \ skipwhite skipempty skipnl + +syntax keyword typescriptVariable const +  \ nextgroup=typescriptEnum,typescriptVariableDeclaration +  \ skipwhite + +syntax match typescriptVariableDeclaration /[A-Za-z_$]\k*/ +  \ nextgroup=typescriptTypeAnnotation,typescriptAssign +  \ contained skipwhite skipempty skipnl + +syntax region typescriptEnum matchgroup=typescriptEnumKeyword start=/enum / end=/\ze{/ +  \ nextgroup=typescriptBlock +  \ skipwhite + +syntax keyword typescriptKeywordOp +  \ contained in instanceof nextgroup=@typescriptValue +syntax keyword typescriptOperator              delete new typeof void +  \ nextgroup=@typescriptValue +  \ skipwhite skipempty + +syntax keyword typescriptForOperator           contained in of +syntax keyword typescriptBoolean               true false nextgroup=@typescriptSymbols skipwhite skipempty +syntax keyword typescriptNull                  null undefined nextgroup=@typescriptSymbols skipwhite skipempty +syntax keyword typescriptMessage               alert confirm prompt status +  \ nextgroup=typescriptDotNotation,typescriptFuncCallArg +syntax keyword typescriptGlobal                self top parent +  \ nextgroup=@afterIdentifier + +"Statement Keywords +syntax keyword typescriptConditional           if else switch +  \ nextgroup=typescriptConditionalParen +  \ skipwhite skipempty skipnl +syntax keyword typescriptConditionalElse       else +syntax keyword typescriptRepeat                do while for nextgroup=typescriptLoopParen skipwhite skipempty +syntax keyword typescriptRepeat                for nextgroup=typescriptLoopParen,typescriptAsyncFor skipwhite skipempty +syntax keyword typescriptBranch                break continue containedin=typescriptBlock +syntax keyword typescriptCase                  case nextgroup=@typescriptPrimitive skipwhite containedin=typescriptBlock +syntax keyword typescriptDefault               default containedin=typescriptBlock nextgroup=@typescriptValue,typescriptClassKeyword,typescriptInterfaceKeyword skipwhite oneline +syntax keyword typescriptStatementKeyword      with +syntax keyword typescriptStatementKeyword      yield skipwhite nextgroup=@typescriptValue containedin=typescriptBlock +syntax keyword typescriptStatementKeyword      return skipwhite contained nextgroup=@typescriptValue containedin=typescriptBlock + +syntax keyword typescriptTry                   try +syntax keyword typescriptExceptions            catch throw finally +syntax keyword typescriptDebugger              debugger + +syntax keyword typescriptAsyncFor              await nextgroup=typescriptLoopParen skipwhite skipempty contained + +syntax region  typescriptLoopParen             contained matchgroup=typescriptParens +  \ start=/(/ end=/)/ +  \ contains=typescriptVariable,typescriptForOperator,typescriptEndColons,@typescriptValue,@typescriptComments +  \ nextgroup=typescriptBlock +  \ skipwhite skipempty +syntax region  typescriptConditionalParen             contained matchgroup=typescriptParens +  \ start=/(/ end=/)/ +  \ contains=@typescriptValue,@typescriptComments +  \ nextgroup=typescriptBlock +  \ skipwhite skipempty +syntax match   typescriptEndColons             /[;,]/ contained + +syntax keyword typescriptAmbientDeclaration declare nextgroup=@typescriptAmbients +  \ skipwhite skipempty + +syntax cluster typescriptAmbients contains= +  \ typescriptVariable, +  \ typescriptFuncKeyword, +  \ typescriptClassKeyword, +  \ typescriptAbstract, +  \ typescriptEnumKeyword,typescriptEnum, +  \ typescriptModule diff --git a/syntax/basic/literal.vim b/syntax/basic/literal.vim new file mode 100644 index 00000000..315d6123 --- /dev/null +++ b/syntax/basic/literal.vim @@ -0,0 +1,47 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +"Syntax in the JavaScript code + +" String +syntax match   typescriptASCII                 contained /\\\d\d\d/ + +syntax region  typescriptTemplateSubstitution matchgroup=typescriptTemplateSB +  \ start=/\${/ end=/}/ +  \ contains=@typescriptValue +  \ contained + + +syntax region  typescriptString  +  \ start=+\z(["']\)+  skip=+\\\%(\z1\|$\)+  end=+\z1+ end=+$+ +  \ contains=typescriptSpecial,@Spell +  \ extend + +syntax match   typescriptSpecial            contained "\v\\%(x\x\x|u%(\x{4}|\{\x{4,5}})|c\u|.)" + +" From vim runtime +" <https://github.com/vim/vim/blob/master/runtime/syntax/javascript.vim#L48> +syntax region  typescriptRegexpString          start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gimuy]\{0,5\}\s*$+ end=+/[gimuy]\{0,5\}\s*[;.,)\]}]+me=e-1 nextgroup=typescriptDotNotation oneline + +syntax region  typescriptTemplate +  \ start=/`/  skip=/\\\\\|\\`\|\n/  end=/`\|$/ +  \ contains=typescriptTemplateSubstitution +  \ nextgroup=@typescriptSymbols +  \ skipwhite skipempty + +"Array +syntax region  typescriptArray matchgroup=typescriptBraces +  \ start=/\[/ end=/]/ +  \ contains=@typescriptValue,@typescriptComments +  \ nextgroup=@typescriptSymbols,typescriptDotNotation +  \ skipwhite skipempty fold + +" Number +syntax match typescriptNumber /\<0[bB][01][01_]*\>/        nextgroup=@typescriptSymbols skipwhite skipempty +syntax match typescriptNumber /\<0[oO][0-7][0-7_]*\>/       nextgroup=@typescriptSymbols skipwhite skipempty +syntax match typescriptNumber /\<0[xX][0-9a-fA-F][0-9a-fA-F_]*\>/ nextgroup=@typescriptSymbols skipwhite skipempty +syntax match typescriptNumber /\d[0-9_]*\.\d[0-9_]*\|\d[0-9_]*\|\.\d[0-9]*/ +  \ nextgroup=typescriptExponent,@typescriptSymbols skipwhite skipempty +syntax match typescriptExponent /[eE][+-]\=\d[0-9]*\>/ +  \ nextgroup=@typescriptSymbols skipwhite skipempty contained diff --git a/syntax/basic/members.vim b/syntax/basic/members.vim new file mode 100644 index 00000000..45fafbcc --- /dev/null +++ b/syntax/basic/members.vim @@ -0,0 +1,50 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +syntax keyword typescriptConstructor           contained constructor +  \ nextgroup=@typescriptCallSignature +  \ skipwhite skipempty + + +syntax cluster memberNextGroup contains=typescriptMemberOptionality,typescriptTypeAnnotation,@typescriptCallSignature + +syntax match typescriptMember /\K\k*/ +  \ nextgroup=@memberNextGroup +  \ contained skipwhite + +syntax match typescriptMethodAccessor contained /\v(get|set)\s\K/me=e-1 +  \ nextgroup=@typescriptMembers + +syntax cluster typescriptPropertyMemberDeclaration contains= +  \ typescriptClassStatic, +  \ typescriptAccessibilityModifier, +  \ typescriptReadonlyModifier, +  \ typescriptMethodAccessor, +  \ @typescriptMembers +  " \ typescriptMemberVariableDeclaration + +syntax match typescriptMemberOptionality /?\|!/ contained +  \ nextgroup=typescriptTypeAnnotation,@typescriptCallSignature +  \ skipwhite skipempty + +syntax cluster typescriptMembers contains=typescriptMember,typescriptStringMember,typescriptComputedMember + +syntax keyword typescriptClassStatic static +  \ nextgroup=@typescriptMembers,typescriptAsyncFuncKeyword,typescriptReadonlyModifier +  \ skipwhite contained + +syntax keyword typescriptAccessibilityModifier public private protected contained + +syntax keyword typescriptReadonlyModifier readonly contained + +syntax region  typescriptStringMember   contained +  \ start=/\z(["']\)/  skip=/\\\\\|\\\z1\|\\\n/  end=/\z1/ +  \ nextgroup=@memberNextGroup +  \ skipwhite skipempty + +syntax region  typescriptComputedMember   contained matchgroup=typescriptProperty +  \ start=/\[/rs=s+1 end=/]/ +  \ contains=@typescriptValue,typescriptMember,typescriptMappedIn +  \ nextgroup=@memberNextGroup +  \ skipwhite skipempty diff --git a/syntax/basic/object.vim b/syntax/basic/object.vim new file mode 100644 index 00000000..533201c3 --- /dev/null +++ b/syntax/basic/object.vim @@ -0,0 +1,32 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +syntax region  typescriptObjectLiteral         matchgroup=typescriptBraces +  \ start=/{/ end=/}/ +  \ contains=@typescriptComments,typescriptObjectLabel,typescriptStringProperty,typescriptComputedPropertyName +  \ fold contained + +syntax match   typescriptObjectLabel  contained /\k\+\_s*/ +  \ nextgroup=typescriptObjectColon,@typescriptCallImpl +  \ skipwhite skipempty + +syntax region  typescriptStringProperty   contained +  \ start=/\z(["']\)/  skip=/\\\\\|\\\z1\|\\\n/  end=/\z1/ +  \ nextgroup=typescriptObjectColon,@typescriptCallImpl +  \ skipwhite skipempty + +" syntax region  typescriptPropertyName    contained start=/\z(["']\)/  skip=/\\\\\|\\\z1\|\\\n/  end=/\z1(/me=e-1 nextgroup=@typescriptCallSignature skipwhite skipempty oneline +syntax region  typescriptComputedPropertyName  contained matchgroup=typescriptBraces +  \ start=/\[/rs=s+1 end=/]/ +  \ contains=@typescriptValue +  \ nextgroup=typescriptObjectColon,@typescriptCallImpl +  \ skipwhite skipempty + +" syntax region  typescriptComputedPropertyName  contained matchgroup=typescriptPropertyName start=/\[/rs=s+1 end=/]\_s*:/he=e-1 contains=@typescriptValue nextgroup=@typescriptValue skipwhite skipempty +" syntax region  typescriptComputedPropertyName  contained matchgroup=typescriptPropertyName start=/\[/rs=s+1 end=/]\_s*(/me=e-1 contains=@typescriptValue nextgroup=@typescriptCallSignature skipwhite skipempty +" Value for object, statement for label statement +syntax match typescriptRestOrSpread /\.\.\./ contained +syntax match typescriptObjectSpread /\.\.\./ contained containedin=typescriptObjectLiteral,typescriptArray nextgroup=@typescriptValue + +syntax match typescriptObjectColon contained /:/ nextgroup=@typescriptValue skipwhite skipempty diff --git a/syntax/basic/patch.vim b/syntax/basic/patch.vim new file mode 100644 index 00000000..ea4adfa2 --- /dev/null +++ b/syntax/basic/patch.vim @@ -0,0 +1,9 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +" patch for generated code +syntax keyword typescriptGlobal Promise +  \ nextgroup=typescriptGlobalPromiseDot,typescriptFuncCallArg,typescriptTypeArguments oneline +syntax keyword typescriptGlobal Map WeakMap +  \ nextgroup=typescriptGlobalPromiseDot,typescriptFuncCallArg,typescriptTypeArguments oneline diff --git a/syntax/basic/reserved.vim b/syntax/basic/reserved.vim new file mode 100644 index 00000000..cf6467c2 --- /dev/null +++ b/syntax/basic/reserved.vim @@ -0,0 +1,35 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +syntax cluster typescriptStrings               contains=typescriptProp,typescriptString,typescriptTemplate,@typescriptComments,typescriptDocComment,typescriptRegexpString,typescriptPropertyName + +syntax cluster typescriptNoReserved contains= +  \ @typescriptStrings, +  \ @typescriptDocs, +  \ @typescriptComments, +  \ shellbang, +  \ typescriptObjectLiteral, +  \ typescriptObjectLabel, +  \ typescriptClassBlock, +  \ @typescriptType, +  \ typescriptCall + +"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved break case catch const continue +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved debugger delete do else export +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved extends finally for if +"import,typescriptRegexpString,typescriptPropertyName +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved in instanceof let new return super +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved static switch throw try typeof +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved void while with yield + +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved implements package protected +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved interface private public readonly abstract +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved byte char double final float goto int +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved long native short synchronized transient +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved volatile + +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved class +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved var +syntax keyword typescriptReserved containedin=ALLBUT,@typescriptNoReserved function diff --git a/syntax/basic/symbols.vim b/syntax/basic/symbols.vim new file mode 100644 index 00000000..978694e1 --- /dev/null +++ b/syntax/basic/symbols.vim @@ -0,0 +1,42 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +" + - ^ ~ +syntax match typescriptUnaryOp /[+\-~!]/ + \ nextgroup=@typescriptValue + \ skipwhite + +syntax region typescriptTernary matchgroup=typescriptTernaryOp start=/?/ end=/:/ contained contains=@typescriptValue,@typescriptComments nextgroup=@typescriptValue skipwhite skipempty + +syntax match   typescriptAssign  /=/ nextgroup=@typescriptValue +  \ skipwhite skipempty + +" 2: ==, === +syntax match   typescriptBinaryOp contained /===\?/ nextgroup=@typescriptValue skipwhite skipempty +" 6: >>>=, >>>, >>=, >>, >=, > +syntax match   typescriptBinaryOp contained />\(>>=\|>>\|>=\|>\|=\)\?/ nextgroup=@typescriptValue skipwhite skipempty +" 4: <<=, <<, <=, < +syntax match   typescriptBinaryOp contained /<\(<=\|<\|=\)\?/ nextgroup=@typescriptValue skipwhite skipempty +" 3: ||, |=, | +syntax match   typescriptBinaryOp contained /|\(|\|=\)\?/ nextgroup=@typescriptValue skipwhite skipempty +" 3: &&, &=, & +syntax match   typescriptBinaryOp contained /&\(&\|=\)\?/ nextgroup=@typescriptValue skipwhite skipempty +" 2: *=, * +syntax match   typescriptBinaryOp contained /\*=\?/ nextgroup=@typescriptValue skipwhite skipempty +" 2: %=, % +syntax match   typescriptBinaryOp contained /%=\?/ nextgroup=@typescriptValue skipwhite skipempty +" 2: /=, / +syntax match   typescriptBinaryOp contained +/\(=\|[^\*/]\@=\)+ nextgroup=@typescriptValue skipwhite skipempty +syntax match   typescriptBinaryOp contained /!==\?/ nextgroup=@typescriptValue skipwhite skipempty +" 2: !=, !== +syntax match   typescriptBinaryOp contained /+\(+\|=\)\?/ nextgroup=@typescriptValue skipwhite skipempty +" 3: +, ++, += +syntax match   typescriptBinaryOp contained /-\(-\|=\)\?/ nextgroup=@typescriptValue skipwhite skipempty +" 3: -, --, -= + +" exponentiation operator +" 2: **, **= +syntax match typescriptBinaryOp contained /\*\*=\?/ nextgroup=@typescriptValue + +syntax cluster typescriptSymbols               contains=typescriptBinaryOp,typescriptKeywordOp,typescriptTernary,typescriptAssign,typescriptCastKeyword diff --git a/syntax/basic/type.vim b/syntax/basic/type.vim new file mode 100644 index 00000000..6f9097b0 --- /dev/null +++ b/syntax/basic/type.vim @@ -0,0 +1,191 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'typescript') != -1 +  finish +endif + +" Types +syntax match typescriptOptionalMark /?/ contained + +syntax region typescriptTypeParameters matchgroup=typescriptTypeBrackets +  \ start=/</ end=/>/ +  \ contains=typescriptTypeParameter +  \ contained + +syntax match typescriptTypeParameter /\K\k*/ +  \ nextgroup=typescriptConstraint,typescriptGenericDefault +  \ contained skipwhite skipnl + +syntax keyword typescriptConstraint extends +  \ nextgroup=@typescriptType +  \ contained skipwhite skipnl + +syntax match typescriptGenericDefault /=/ +  \ nextgroup=@typescriptType +  \ contained skipwhite + +">< +" class A extend B<T> {} // ClassBlock +" func<T>() // FuncCallArg +syntax region typescriptTypeArguments matchgroup=typescriptTypeBrackets +  \ start=/\></ end=/>/ +  \ contains=@typescriptType +  \ nextgroup=typescriptFuncCallArg,@typescriptTypeOperator +  \ contained skipwhite + + +syntax cluster typescriptType contains= +  \ @typescriptPrimaryType, +  \ typescriptUnion, +  \ @typescriptFunctionType, +  \ typescriptConstructorType + +" array type: A[] +" type indexing A['key'] +syntax region typescriptTypeBracket contained +  \ start=/\[/ end=/\]/ +  \ contains=typescriptString,typescriptNumber +  \ nextgroup=@typescriptTypeOperator +  \ skipwhite skipempty + +syntax cluster typescriptPrimaryType contains= +  \ typescriptParenthesizedType, +  \ typescriptPredefinedType, +  \ typescriptTypeReference, +  \ typescriptObjectType, +  \ typescriptTupleType, +  \ typescriptTypeQuery, +  \ typescriptStringLiteralType, +  \ typescriptReadonlyArrayKeyword + +syntax region  typescriptStringLiteralType contained +  \ start=/\z(["']\)/  skip=/\\\\\|\\\z1\|\\\n/  end=/\z1\|$/ +  \ nextgroup=typescriptUnion +  \ skipwhite skipempty + +syntax region typescriptParenthesizedType matchgroup=typescriptParens +  \ start=/(/ end=/)/ +  \ contains=@typescriptType +  \ nextgroup=@typescriptTypeOperator +  \ contained skipwhite skipempty fold + +syntax match typescriptTypeReference /\K\k*\(\.\K\k*\)*/ +  \ nextgroup=typescriptTypeArguments,@typescriptTypeOperator,typescriptUserDefinedType +  \ skipwhite contained skipempty + +syntax keyword typescriptPredefinedType any number boolean string void never undefined null object unknown +  \ nextgroup=@typescriptTypeOperator +  \ contained skipwhite skipempty + +syntax match typescriptPredefinedType /unique symbol/ +  \ nextgroup=@typescriptTypeOperator +  \ contained skipwhite skipempty + +syntax region typescriptObjectType matchgroup=typescriptBraces +  \ start=/{/ end=/}/ +  \ contains=@typescriptTypeMember,typescriptEndColons,@typescriptComments,typescriptAccessibilityModifier,typescriptReadonlyModifier +  \ nextgroup=@typescriptTypeOperator +  \ contained skipwhite fold + +syntax cluster typescriptTypeMember contains= +  \ @typescriptCallSignature, +  \ typescriptConstructSignature, +  \ typescriptIndexSignature, +  \ @typescriptMembers + +syntax region typescriptTupleType matchgroup=typescriptBraces +  \ start=/\[/ end=/\]/ +  \ contains=@typescriptType +  \ contained skipwhite oneline + +syntax cluster typescriptTypeOperator +  \ contains=typescriptUnion,typescriptTypeBracket + +syntax match typescriptUnion /|\|&/ contained nextgroup=@typescriptPrimaryType skipwhite skipempty + +syntax cluster typescriptFunctionType contains=typescriptGenericFunc,typescriptFuncType +syntax region typescriptGenericFunc matchgroup=typescriptTypeBrackets +  \ start=/</ end=/>/ +  \ contains=typescriptTypeParameter +  \ nextgroup=typescriptFuncType +  \ containedin=typescriptFunctionType +  \ contained skipwhite skipnl + +syntax region typescriptFuncType matchgroup=typescriptParens +  \ start=/(/ end=/)\s*=>/me=e-2 +  \ contains=@typescriptParameterList +  \ nextgroup=typescriptFuncTypeArrow +  \ contained skipwhite skipnl oneline + +syntax match typescriptFuncTypeArrow /=>/ +  \ nextgroup=@typescriptType +  \ containedin=typescriptFuncType +  \ contained skipwhite skipnl + + +syntax keyword typescriptConstructorType new +  \ nextgroup=@typescriptFunctionType +  \ contained skipwhite skipnl + +syntax keyword typescriptUserDefinedType is +  \ contained nextgroup=@typescriptType skipwhite skipempty + +syntax keyword typescriptTypeQuery typeof keyof +  \ nextgroup=typescriptTypeReference +  \ contained skipwhite skipnl + +syntax cluster typescriptCallSignature contains=typescriptGenericCall,typescriptCall +syntax region typescriptGenericCall matchgroup=typescriptTypeBrackets +  \ start=/</ end=/>/ +  \ contains=typescriptTypeParameter +  \ nextgroup=typescriptCall +  \ contained skipwhite skipnl +syntax region typescriptCall matchgroup=typescriptParens +  \ start=/(/ end=/)/ +  \ contains=typescriptDecorator,@typescriptParameterList,@typescriptComments +  \ nextgroup=typescriptTypeAnnotation,typescriptBlock +  \ contained skipwhite skipnl + +syntax match typescriptTypeAnnotation /:/ +  \ nextgroup=@typescriptType +  \ contained skipwhite skipnl + +syntax cluster typescriptParameterList contains= +  \ typescriptTypeAnnotation, +  \ typescriptAccessibilityModifier, +  \ typescriptOptionalMark, +  \ typescriptRestOrSpread, +  \ typescriptFuncComma, +  \ typescriptDefaultParam + +syntax match typescriptFuncComma /,/ contained + +syntax match typescriptDefaultParam /=/ +  \ nextgroup=@typescriptValue +  \ contained skipwhite + +syntax keyword typescriptConstructSignature new +  \ nextgroup=@typescriptCallSignature +  \ contained skipwhite + +syntax region typescriptIndexSignature matchgroup=typescriptBraces +  \ start=/\[/ end=/\]/ +  \ contains=typescriptPredefinedType,typescriptMappedIn,typescriptString +  \ nextgroup=typescriptTypeAnnotation +  \ contained skipwhite oneline + +syntax keyword typescriptMappedIn in +  \ nextgroup=@typescriptType +  \ contained skipwhite skipnl skipempty + +syntax keyword typescriptAliasKeyword type +  \ nextgroup=typescriptAliasDeclaration +  \ skipwhite skipnl skipempty + +syntax region typescriptAliasDeclaration matchgroup=typescriptUnion +  \ start=/ / end=/=/ +  \ nextgroup=@typescriptType +  \ contains=typescriptConstraint,typescriptTypeParameters +  \ contained skipwhite skipempty + +syntax keyword typescriptReadonlyArrayKeyword readonly +  \ nextgroup=@typescriptPrimaryType +  \ skipwhite | 
