diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-06-06 20:39:55 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-06-06 20:39:55 +0200 |
commit | 773a97c254d02784079fb3b20447620412588850 (patch) | |
tree | 0028f4ee956a7ba3a69b3850ca23be484f40ab80 | |
parent | c07f67ad0e9c48a07d49f2d67eb63e183a22386a (diff) |
Update runtime files - Add typescript syntax and indent.
-rw-r--r-- | runtime/doc/eval.txt | 14 | ||||
-rw-r--r-- | runtime/doc/todo.txt | 11 | ||||
-rw-r--r-- | runtime/indent/typescript.vim | 503 | ||||
-rw-r--r-- | runtime/syntax/ocaml.vim | 138 | ||||
-rw-r--r-- | runtime/syntax/typescript.vim | 2071 |
5 files changed, 2680 insertions, 57 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 82e2093f02..0b44e58e24 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 8.1. Last change: 2019 Jun 04 +*eval.txt* For Vim version 8.1. Last change: 2019 Jun 06 VIM REFERENCE MANUAL by Bram Moolenaar @@ -13063,8 +13063,16 @@ missing: > : echo "You will _never_ see this message" :endif -To execute a command only when the |+eval| feature is disabled requires a trick, -as this example shows: > +To execute a command only when the |+eval| feature is disabled can be done in +two ways. The simplest is to exit the script (or Vim) prematurely: > + if 1 + echo "commands executed with +eval" + finish + endif + args " command executed without +eval + +If you do not want to abort loading the script you can use a trick, as this +example shows: > silent! while 0 set history=111 diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index 5e7b33d13d..b03633fab8 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -44,9 +44,6 @@ Popup windows are being implemented, see |popup-window|. Listener causes extra } to be inserted. (Paul Jolly, #4455) -Patch to beautify the output of a test run. (Christian Brabandt, #4391) -can be improved. - Patch to fix session file when using multiple tabs. (Jason Franklin, 2019 May 20) Also put :argadd commands at the start for all buffers, so that their order @@ -54,14 +51,9 @@ remains equal? Then %argdel to clean it up. Do try this with 'hidden' set. Patch for Chinese translations for nsis. (#4407) Comments handled? -Add test that does ":set t_k1&" to cover add_termcap_entry(). - Patch to add v:searchstat. (Takuya Fujiwara, #4446) Should be independent of 'shortmess', filled on demand and cached until search changes. -Problem with resolve() improvement. (Ken Takata, #4492) -Yasuhiro will check it. - listener callback is invoked while another is still busy? (Paul Jolly) Should not happen because of text lock. @@ -175,9 +167,6 @@ Improve fallback for menu translations, to avoid having to create lots of files that source the actual file. E.g. menu_da_de -> menu_da Include part of #3242? -Add typescript syntax, but as one file: -- https://github.com/HerringtonDarkholme/yats.vim - When a terminal exit_cb closes the window, a following typed key is lost, if it's in a mapping. (2018 Oct 6, #2302, #3522) diff --git a/runtime/indent/typescript.vim b/runtime/indent/typescript.vim new file mode 100644 index 0000000000..69accaa054 --- /dev/null +++ b/runtime/indent/typescript.vim @@ -0,0 +1,503 @@ +" Vim indent file +" Language: TypeScript +" Maintainer: See https://github.com/HerringtonDarkholme/yats.vim +" Last Change: 2019 Jun 06 +" Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org + +" 0. Initialization {{{1 +" ================= + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal nosmartindent + +" Now, set up our indentation expression and keys that trigger it. +setlocal indentexpr=GetTypescriptIndent() +setlocal formatexpr=Fixedgq(v:lnum,v:count) +setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e + +" Only define the function once. +if exists("*GetTypescriptIndent") + finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +" 1. Variables {{{1 +" ============ + +let s:js_keywords = '^\s*\(break\|case\|catch\|continue\|debugger\|default\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)' + +" Regex of syntax group names that are or delimit string or are comments. +let s:syng_strcom = 'string\|regex\|comment\c' + +" Regex of syntax group names that are strings. +let s:syng_string = 'regex\c' + +" Regex of syntax group names that are strings or documentation. +let s:syng_multiline = 'comment\c' + +" Regex of syntax group names that are line comment. +let s:syng_linecom = 'linecomment\c' + +" Expression used to check whether we should skip a match with searchpair(). +let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" + +let s:line_term = '\s*\%(\%(\/\/\).*\)\=$' + +" Regex that defines continuation lines, not including (, {, or [. +let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]=[^=].*,\)' . s:line_term + +" Regex that defines continuation lines. +" TODO: this needs to deal with if ...: and so on +let s:msl_regex = s:continuation_regex + +let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term + +" Regex that defines blocks. +let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term + +let s:var_stmt = '^\s*var' + +let s:comma_first = '^\s*,' +let s:comma_last = ',\s*$' + +let s:ternary = '^\s\+[?|:]' +let s:ternary_q = '^\s\+?' + +" 2. Auxiliary Functions {{{1 +" ====================== + +" Check if the character at lnum:col is inside a string, comment, or is ascii. +function s:IsInStringOrComment(lnum, col) + return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom +endfunction + +" Check if the character at lnum:col is inside a string. +function s:IsInString(lnum, col) + return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string +endfunction + +" Check if the character at lnum:col is inside a multi-line comment. +function s:IsInMultilineComment(lnum, col) + return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline +endfunction + +" Check if the character at lnum:col is a line comment. +function s:IsLineComment(lnum, col) + return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_linecom +endfunction + +" Find line above 'lnum' that isn't empty, in a comment, or in a string. +function s:PrevNonBlankNonString(lnum) + let in_block = 0 + let lnum = prevnonblank(a:lnum) + while lnum > 0 + " Go in and out of blocks comments as necessary. + " If the line isn't empty (with opt. comment) or in a string, end search. + let line = getline(lnum) + if line =~ '/\*' + if in_block + let in_block = 0 + else + break + endif + elseif !in_block && line =~ '\*/' + let in_block = 1 + elseif !in_block && line !~ '^\s*\%(//\).*$' && !(s:IsInStringOrComment(lnum, 1) && s:IsInStringOrComment(lnum, strlen(line))) + break + endif + let lnum = prevnonblank(lnum - 1) + endwhile + return lnum +endfunction + +" Find line above 'lnum' that started the continuation 'lnum' may be part of. +function s:GetMSL(lnum, in_one_line_scope) + " Start on the line we're at and use its indent. + let msl = a:lnum + let lnum = s:PrevNonBlankNonString(a:lnum - 1) + while lnum > 0 + " If we have a continuation line, or we're in a string, use line as MSL. + " Otherwise, terminate search as we have found our MSL already. + let line = getline(lnum) + let col = match(line, s:msl_regex) + 1 + if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line)) + let msl = lnum + else + " Don't use lines that are part of a one line scope as msl unless the + " flag in_one_line_scope is set to 1 + " + if a:in_one_line_scope + break + end + let msl_one_line = s:Match(lnum, s:one_line_scope_regex) + if msl_one_line == 0 + break + endif + endif + let lnum = s:PrevNonBlankNonString(lnum - 1) + endwhile + return msl +endfunction + +function s:RemoveTrailingComments(content) + let single = '\/\/\(.*\)\s*$' + let multi = '\/\*\(.*\)\*\/\s*$' + return substitute(substitute(a:content, single, '', ''), multi, '', '') +endfunction + +" Find if the string is inside var statement (but not the first string) +function s:InMultiVarStatement(lnum) + let lnum = s:PrevNonBlankNonString(a:lnum - 1) + +" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name') + + " loop through previous expressions to find a var statement + while lnum > 0 + let line = getline(lnum) + + " if the line is a js keyword + if (line =~ s:js_keywords) + " check if the line is a var stmt + " if the line has a comma first or comma last then we can assume that we + " are in a multiple var statement + if (line =~ s:var_stmt) + return lnum + endif + + " other js keywords, not a var + return 0 + endif + + let lnum = s:PrevNonBlankNonString(lnum - 1) + endwhile + + " beginning of program, not a var + return 0 +endfunction + +" Find line above with beginning of the var statement or returns 0 if it's not +" this statement +function s:GetVarIndent(lnum) + let lvar = s:InMultiVarStatement(a:lnum) + let prev_lnum = s:PrevNonBlankNonString(a:lnum - 1) + + if lvar + let line = s:RemoveTrailingComments(getline(prev_lnum)) + + " if the previous line doesn't end in a comma, return to regular indent + if (line !~ s:comma_last) + return indent(prev_lnum) - shiftwidth() + else + return indent(lvar) + shiftwidth() + endif + endif + + return -1 +endfunction + + +" Check if line 'lnum' has more opening brackets than closing ones. +function s:LineHasOpeningBrackets(lnum) + let open_0 = 0 + let open_2 = 0 + let open_4 = 0 + let line = getline(a:lnum) + let pos = match(line, '[][(){}]', 0) + while pos != -1 + if !s:IsInStringOrComment(a:lnum, pos + 1) + let idx = stridx('(){}[]', line[pos]) + if idx % 2 == 0 + let open_{idx} = open_{idx} + 1 + else + let open_{idx - 1} = open_{idx - 1} - 1 + endif + endif + let pos = match(line, '[][(){}]', pos + 1) + endwhile + return (open_0 > 0) . (open_2 > 0) . (open_4 > 0) +endfunction + +function s:Match(lnum, regex) + let col = match(getline(a:lnum), a:regex) + 1 + return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0 +endfunction + +function s:IndentWithContinuation(lnum, ind, width) + " Set up variables to use and search for MSL to the previous line. + let p_lnum = a:lnum + let lnum = s:GetMSL(a:lnum, 1) + let line = getline(lnum) + + " If the previous line wasn't a MSL and is continuation return its indent. + " TODO: the || s:IsInString() thing worries me a bit. + if p_lnum != lnum + if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line)) + return a:ind + endif + endif + + " Set up more variables now that we know we aren't continuation bound. + let msl_ind = indent(lnum) + + " If the previous line ended with [*+/.-=], start a continuation that + " indents an extra level. + if s:Match(lnum, s:continuation_regex) + if lnum == p_lnum + return msl_ind + a:width + else + return msl_ind + endif + endif + + return a:ind +endfunction + +function s:InOneLineScope(lnum) + let msl = s:GetMSL(a:lnum, 1) + if msl > 0 && s:Match(msl, s:one_line_scope_regex) + return msl + endif + return 0 +endfunction + +function s:ExitingOneLineScope(lnum) + let msl = s:GetMSL(a:lnum, 1) + if msl > 0 + " if the current line is in a one line scope .. + if s:Match(msl, s:one_line_scope_regex) + return 0 + else + let prev_msl = s:GetMSL(msl - 1, 1) + if s:Match(prev_msl, s:one_line_scope_regex) + return prev_msl + endif + endif + endif + return 0 +endfunction + +" 3. GetTypescriptIndent Function {{{1 +" ========================= + +function GetTypescriptIndent() + " 3.1. Setup {{{2 + " ---------- + + " Set up variables for restoring position in file. Could use v:lnum here. + let vcol = col('.') + + " 3.2. Work on the current line {{{2 + " ----------------------------- + + let ind = -1 + " Get the current line. + let line = getline(v:lnum) + " previous nonblank line number + let prevline = prevnonblank(v:lnum - 1) + + " If we got a closing bracket on an empty line, find its match and indent + " according to it. For parentheses we indent to its column - 1, for the + " others we indent to the containing line's MSL's level. Return -1 if fail. + let col = matchend(line, '^\s*[],})]') + if col > 0 && !s:IsInStringOrComment(v:lnum, col) + call cursor(v:lnum, col) + + let lvar = s:InMultiVarStatement(v:lnum) + if lvar + let prevline_contents = s:RemoveTrailingComments(getline(prevline)) + + " check for comma first + if (line[col - 1] =~ ',') + " if the previous line ends in comma or semicolon don't indent + if (prevline_contents =~ '[;,]\s*$') + return indent(s:GetMSL(line('.'), 0)) + " get previous line indent, if it's comma first return prevline indent + elseif (prevline_contents =~ s:comma_first) + return indent(prevline) + " otherwise we indent 1 level + else + return indent(lvar) + shiftwidth() + endif + endif + endif + + + let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2) + if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0 + if line[col-1]==')' && col('.') != col('$') - 1 + let ind = virtcol('.')-1 + else + let ind = indent(s:GetMSL(line('.'), 0)) + endif + endif + return ind + endif + + " If the line is comma first, dedent 1 level + if (getline(prevline) =~ s:comma_first) + return indent(prevline) - shiftwidth() + endif + + if (line =~ s:ternary) + if (getline(prevline) =~ s:ternary_q) + return indent(prevline) + else + return indent(prevline) + shiftwidth() + endif + endif + + " If we are in a multi-line comment, cindent does the right thing. + if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1) + return cindent(v:lnum) + endif + + " Check for multiple var assignments +" let var_indent = s:GetVarIndent(v:lnum) +" if var_indent >= 0 +" return var_indent +" endif + + " 3.3. Work on the previous line. {{{2 + " ------------------------------- + + " If the line is empty and the previous nonblank line was a multi-line + " comment, use that comment's indent. Deduct one char to account for the + " space in ' */'. + if line =~ '^\s*$' && s:IsInMultilineComment(prevline, 1) + return indent(prevline) - 1 + endif + + " Find a non-blank, non-multi-line string line above the current line. + let lnum = s:PrevNonBlankNonString(v:lnum - 1) + + " If the line is empty and inside a string, use the previous line. + if line =~ '^\s*$' && lnum != prevline + return indent(prevnonblank(v:lnum)) + endif + + " At the start of the file use zero indent. + if lnum == 0 + return 0 + endif + + " Set up variables for current line. + let line = getline(lnum) + let ind = indent(lnum) + + " If the previous line ended with a block opening, add a level of indent. + if s:Match(lnum, s:block_regex) + return indent(s:GetMSL(lnum, 0)) + shiftwidth() + endif + + " If the previous line contained an opening bracket, and we are still in it, + " add indent depending on the bracket type. + if line =~ '[[({]' + let counts = s:LineHasOpeningBrackets(lnum) + if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0 + if col('.') + 1 == col('$') + return ind + shiftwidth() + else + return virtcol('.') + endif + elseif counts[1] == '1' || counts[2] == '1' + return ind + shiftwidth() + else + call cursor(v:lnum, vcol) + end + endif + + " 3.4. Work on the MSL line. {{{2 + " -------------------------- + + let ind_con = ind + let ind = s:IndentWithContinuation(lnum, ind_con, shiftwidth()) + + " }}}2 + " + " + let ols = s:InOneLineScope(lnum) + if ols > 0 + let ind = ind + shiftwidth() + else + let ols = s:ExitingOneLineScope(lnum) + while ols > 0 && ind > 0 + let ind = ind - shiftwidth() + let ols = s:InOneLineScope(ols - 1) + endwhile + endif + + return ind +endfunction + +" }}}1 + +let &cpo = s:cpo_save +unlet s:cpo_save + +function! Fixedgq(lnum, count) + let l:tw = &tw ? &tw : 80; + + let l:count = a:count + let l:first_char = indent(a:lnum) + 1 + + if mode() == 'i' " gq was not pressed, but tw was set + return 1 + endif + + " This gq is only meant to do code with strings, not comments + if s:IsLineComment(a:lnum, l:first_char) || s:IsInMultilineComment(a:lnum, l:first_char) + return 1 + endif + + if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq + return 1 + endif + + " Put all the lines on one line and do normal spliting after that + if l:count > 1 + while l:count > 1 + let l:count -= 1 + normal J + endwhile + endif + + let l:winview = winsaveview() + + call cursor(a:lnum, l:tw + 1) + let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum) + call cursor(a:lnum, l:tw + 1) + let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum) + + " No need for special treatment, normal gq handles edgecases better + if breakpoint[1] == orig_breakpoint[1] + call winrestview(l:winview) + return 1 + endif + + " Try breaking after string + if breakpoint[1] <= indent(a:lnum) + call cursor(a:lnum, l:tw + 1) + let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum) + endif + + + if breakpoint[1] != 0 + call feedkeys("r\<CR>") + else + let l:count = l:count - 1 + endif + + " run gq on new lines + if l:count == 1 + call feedkeys("gqq") + endif + + return 0 +endfunction diff --git a/runtime/syntax/ocaml.vim b/runtime/syntax/ocaml.vim index 68c1feddae..6ac8cab57f 100644 --- a/runtime/syntax/ocaml.vim +++ b/runtime/syntax/ocaml.vim @@ -5,9 +5,14 @@ " Karl-Heinz Sylla <Karl-Heinz.Sylla@gmd.de> " Issac Trotts <ijtrotts@ucdavis.edu> " URL: http://www.ocaml.info/vim/syntax/ocaml.vim -" Last Change: 2012 May 12 - Added Dominique Pellé's spell checking patch (MM) -" 2012 Feb 01 - Improved module path highlighting (MM) -" 2010 Oct 11 - Added highlighting of lnot (MM, thanks to Erick Matsen) +" Last Change: +" 2018 Nov 08 - Improved highlighting of operators (Maëlan) +" 2018 Apr 22 - Improved support for PPX (Andrey Popp) +" 2018 Mar 16 - Remove raise, lnot and not from keywords (Étienne Millon, "copy") +" 2017 Apr 11 - Improved matching of negative numbers (MM) +" 2016 Mar 11 - Improved support for quoted strings (Glen Mével) +" 2015 Aug 13 - Allow apostrophes in identifiers (Jonathan Chan, Einar Lielmanis) +" 2015 Jun 17 - Added new "nonrec" keyword (MM) " A minor patch was applied to the official version so that object/end " can be distinguished from begin/end, which is used for indentation, @@ -18,6 +23,9 @@ if exists("b:current_syntax") && b:current_syntax == "ocaml" finish endif +" ' can be used in OCaml identifiers +setlocal iskeyword+=' + " OCaml is case sensitive. syn case match @@ -28,7 +36,7 @@ syn match ocamlMethod "#" syn match ocamlComment "^#!.*" contains=@Spell " Scripting directives -syn match ocamlScript "^#\<\(quit\|labels\|warnings\|directory\|cd\|load\|use\|install_printer\|remove_printer\|require\|thread\|trace\|untrace\|untrace_all\|print_depth\|print_length\|camlp4o\)\>" +syn match ocamlScript "^#\<\(quit\|labels\|warnings\|warn_error\|directory\|remove_directory\|cd\|load\|load_rec\|use\|mod_use\|install_printer\|remove_printer\|require\|list\|ppx\|principal\|predicates\|rectypes\|thread\|trace\|untrace\|untrace_all\|print_depth\|print_length\|camlp4o\|camlp4r\|topfind_log\|topfind_verbose\)\>" " lowercase identifier - the standard way to match syn match ocamlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/ @@ -66,7 +74,7 @@ syn cluster ocamlAllErrs contains=ocamlBraceErr,ocamlBrackErr,ocamlParenErr,oca syn cluster ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr -syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlPreMPRestr,ocamlMPRestr,ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal +syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal " Enclosing delimiters @@ -103,11 +111,15 @@ endif " "if" syn region ocamlNone matchgroup=ocamlKeyword start="\<if\>" matchgroup=ocamlKeyword end="\<then\>" contains=ALLBUT,@ocamlContained,ocamlThenErr +"" PPX nodes + +syn match ocamlPpxIdentifier /\(\[@\{1,3\}\)\@<=\w\+\(\.\w\+\)*/ +syn region ocamlPpx matchgroup=ocamlPpxEncl start="\[@\{1,3\}" contains=TOP end="\]" "" Modules " "sig" -syn region ocamlSig matchgroup=ocamlModule start="\<sig\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule +syn region ocamlSig matchgroup=ocamlSigEncl start="\<sig\>" matchgroup=ocamlSigEncl end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule syn region ocamlModSpec matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr " "open" @@ -118,15 +130,14 @@ syn match ocamlKeyword "\<include\>" skipwhite skipempty nextgroup=ocamlModPa " "module" - somewhat complicated stuff ;-) syn region ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef -syn region ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|=\|)"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS -syn region ocamlModParam start="([^*]" end=")" contained contains=@ocamlAENoParen,ocamlModParam1,ocamlVal -syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlPreMPRestr - -syn region ocamlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlMPRestr,ocamlModTypeRestr +syn region ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|=\|)"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS +syn region ocamlModParam start="([^*]" end=")" contained contains=ocamlGenMod,ocamlModParam1,ocamlSig,ocamlVal +syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty +syn match ocamlGenMod "()" contained skipwhite skipempty syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3 -syn region ocamlMPRestr1 matchgroup=ocamlModule start="\ssig\s\=" matchgroup=ocamlModule end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule -syn region ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 +syn region ocamlMPRestr1 matchgroup=ocamlSigEncl start="\ssig\s\=" matchgroup=ocamlSigEncl end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule +syn region ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 syn match ocamlMPRestr3 "\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*" contained syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn keyword ocamlKeyword val @@ -134,8 +145,8 @@ syn region ocamlVal matchgroup=ocamlKeyword start="\<val\>" matchgroup=ocamlLC syn region ocamlModRHS start="." end=". *\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn match ocamlFullMod "\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith -syn region ocamlFuncWith start="([^*]"me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith -syn region ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr +syn region ocamlFuncWith start="([^*)]"me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith +syn region ocamlFuncStruct matchgroup=ocamlStructEncl start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlStructEncl end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contained syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith @@ -143,20 +154,23 @@ syn match ocamlWith "\<\(\u\(\w\|'\)* *\. *\)*\w\(\w\|'\)*\>" contained skipw syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained " "struct" -syn region ocamlStruct matchgroup=ocamlModule start="\<\(module\s\+\)\=struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr +syn region ocamlStruct matchgroup=ocamlStructEncl start="\<\(module\s\+\)\=struct\>" matchgroup=ocamlStructEncl end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr " "module type" syn region ocamlKeyword start="\<module\>\s*\<type\>\(\s*\<of\>\)\=" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s+1 skipwhite skipempty nextgroup=ocamlFullMod +" Quoted strings +syn region ocamlString matchgroup=ocamlQuotedStringDelim start="{\z\([a-z_]*\)|" end="|\z1}" contains=@Spell + syn keyword ocamlKeyword and as assert class syn keyword ocamlKeyword constraint else syn keyword ocamlKeyword exception external fun syn keyword ocamlKeyword in inherit initializer -syn keyword ocamlKeyword land lazy let match -syn keyword ocamlKeyword method mutable new of -syn keyword ocamlKeyword parser private raise rec +syn keyword ocamlKeyword lazy let match +syn keyword ocamlKeyword method mutable new nonrec of +syn keyword ocamlKeyword parser private rec syn keyword ocamlKeyword try type syn keyword ocamlKeyword virtual when while with @@ -166,14 +180,11 @@ if exists("ocaml_revised") else syn keyword ocamlKeyword function syn keyword ocamlBoolean true false - syn match ocamlKeyChar "!" endif syn keyword ocamlType array bool char exn float format format4 syn keyword ocamlType int int32 int64 lazy_t list nativeint option -syn keyword ocamlType string unit - -syn keyword ocamlOperator asr lnot lor lsl lsr lxor mod not +syn keyword ocamlType bytes string unit syn match ocamlConstructor "(\s*)" syn match ocamlConstructor "\[\s*\]" @@ -193,39 +204,61 @@ syn match ocamlCharErr "'\\\d\d'\|'\\\d'" syn match ocamlCharErr "'\\[^\'ntbr]'" syn region ocamlString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell -syn match ocamlFunDef "->" -syn match ocamlRefAssign ":=" syn match ocamlTopStop ";;" -syn match ocamlOperator "\^" -syn match ocamlOperator "::" -syn match ocamlOperator "&&" -syn match ocamlOperator "<" -syn match ocamlOperator ">" syn match ocamlAnyVar "\<_\>" syn match ocamlKeyChar "|[^\]]"me=e-1 syn match ocamlKeyChar ";" syn match ocamlKeyChar "\~" syn match ocamlKeyChar "?" -syn match ocamlKeyChar "\*" -syn match ocamlKeyChar "=" +"" Operators + +" The grammar of operators is found there: +" https://caml.inria.fr/pub/docs/manual-ocaml/names.html#operator-name +" https://caml.inria.fr/pub/docs/manual-ocaml/extn.html#s:ext-ops +" https://caml.inria.fr/pub/docs/manual-ocaml/extn.html#s:index-operators +" =, *, < and > are both operator names and keywords, we let the user choose how +" to display them (has to be declared before regular infix operators): +syn match ocamlEqual "=" +syn match ocamlStar "*" +syn match ocamlAngle "<" +syn match ocamlAngle ">" +" Custom indexing operators: +syn match ocamlIndexingOp "\.[~?!:|&$%=>@^/*+-][~?!.:|&$%<=>@^*/+-]*\(()\|\[]\|{}\)\(<-\)\?" +" Extension operators (has to be declared before regular infix operators): +syn match ocamlExtensionOp "#[#~?!.:|&$%<=>@^*/+-]\+" +" Infix and prefix operators: +syn match ocamlPrefixOp "![~?!.:|&$%<=>@^*/+-]*" +syn match ocamlPrefixOp "[~?][~?!.:|&$%<=>@^*/+-]\+" +syn match ocamlInfixOp "[&$%@^/+-][~?!.:|&$%<=>@^*/+-]*" +syn match ocamlInfixOp "[|<=>*][~?!.:|&$%<=>@^*/+-]\+" +syn match ocamlInfixOp "#[~?!.:|&$%<=>@^*/+-]\+#\@!" +syn match ocamlInfixOp "!=[~?!.:|&$%<=>@^*/+-]\@!" +syn keyword ocamlInfixOpKeyword asr land lor lsl lsr lxor mod or +" := is technically an infix operator, but we may want to show it as a keyword +" (somewhat analogously to = for let‐bindings and <- for assignations): +syn match ocamlRefAssign ":=" +" :: is technically not an operator, but we may want to show it as such: +syn match ocamlCons "::" +" -> and <- are keywords, not operators (but can appear in longer operators): +syn match ocamlArrow "->[~?!.:|&$%<=>@^*/+-]\@!" if exists("ocaml_revised") - syn match ocamlErr "<-" + syn match ocamlErr "<-[~?!.:|&$%<=>@^*/+-]\@!" else - syn match ocamlOperator "<-" + syn match ocamlKeyChar "<-[~?!.:|&$%<=>@^*/+-]\@!" endif -syn match ocamlNumber "\<-\=\d\(_\|\d\)*[l|L|n]\?\>" -syn match ocamlNumber "\<-\=0[x|X]\(\x\|_\)\+[l|L|n]\?\>" -syn match ocamlNumber "\<-\=0[o|O]\(\o\|_\)\+[l|L|n]\?\>" -syn match ocamlNumber "\<-\=0[b|B]\([01]\|_\)\+[l|L|n]\?\>" -syn match ocamlFloat "\<-\=\d\(_\|\d\)*\.\?\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>" +syn match ocamlNumber "-\=\<\d\(_\|\d\)*[l|L|n]\?\>" +syn match ocamlNumber "-\=\<0[x|X]\(\x\|_\)\+[l|L|n]\?\>" +syn match ocamlNumber "-\=\<0[o|O]\(\o\|_\)\+[l|L|n]\?\>" +syn match ocamlNumber "-\=\<0[b|B]\([01]\|_\)\+[l|L|n]\?\>" +syn match ocamlFloat "-\=\<\d\(_\|\d\)*\.\?\(_\|\d\)*\([eE][-+]\=\d\(_\|\d\)*\)\=\>" " Labels syn match ocamlLabel "\~\(\l\|_\)\(\w\|'\)*"lc=1 syn match ocamlLabel "?\(\l\|_\)\(\w\|'\)*"lc=1 -syn region ocamlLabel transparent matchgroup=ocamlLabel start="?(\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@ocamlContained,ocamlParenErr +syn region ocamlLabel transparent matchgroup=ocamlLabel start="[~?](\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@ocamlContained,ocamlParenErr " Synchronization @@ -281,6 +314,8 @@ hi def link ocamlFullMod Include hi def link ocamlModTypeRestr Include hi def link ocamlWith Include hi def link ocamlMTDef Include +hi def link ocamlSigEncl ocamlModule +hi def link ocamlStructEncl ocamlModule hi def link ocamlScript Include @@ -291,18 +326,34 @@ hi def link ocamlModPreRHS Keyword hi def link ocamlMPRestr2 Keyword hi def link ocamlKeyword Keyword hi def link ocamlMethod Include -hi def link ocamlFunDef Keyword -hi def link ocamlRefAssign Keyword hi def link ocamlKeyChar Keyword hi def link ocamlAnyVar Keyword hi def link ocamlTopStop Keyword -hi def link ocamlOperator Keyword + +hi def link ocamlRefAssign ocamlKeyChar +hi def link ocamlEqual ocamlKeyChar +hi def link ocamlStar ocamlInfixOp +hi def link ocamlAngle ocamlInfixOp +hi def link ocamlCons ocamlInfixOp + +hi def link ocamlPrefixOp ocamlOperator +hi def link ocamlInfixOp ocamlOperator +hi def link ocamlExtensionOp ocamlOperator +hi def link ocamlIndexingOp ocamlOperator + +if exists("ocaml_highlight_operators") + hi def link ocamlInfixOpKeyword ocamlOperator + hi def link ocamlOperator Operator +else + hi def link ocamlInfixOpKeyword Keyword +endif hi def link ocamlBoolean Boolean hi def link ocamlCharacter Character hi def link ocamlNumber Number hi def link ocamlFloat Float hi def link ocamlString String +hi def link ocamlQuotedStringDelim Identifier hi def link ocamlLabel Identifier @@ -312,6 +363,7 @@ hi def link ocamlTodo Todo hi def link ocamlEncl Keyword +hi def link ocamlPpxEncl ocamlEncl let b:current_syntax = "ocaml" diff --git a/runtime/syntax/typescript.vim b/runtime/syntax/typescript.vim new file mode 100644 index 0000000000..3ce30f8b6d --- /dev/null +++ b/runtime/syntax/typescript.vim @@ -0,0 +1,2071 @@ +" Vim syntax file +" Language: TypeScript +" Maintainer: Bram Moolenaar +" Last Change: 2019 Jun 06 +" Based On: Herrington Darkholme's yats.vim +" Changes: See https:github.com/HerringtonDarkholme/yats.vim +" Credits: See yats.vim + +" This is the same syntax that is in yats.vim, but: +" - flattened into one file +" - HiLink commands changed to "hi def link" +" - Setting 'cpo' to the Vim value + +if !exists("main_syntax") + if exists("b:current_syntax") + finish + endif + let main_syntax = 'typescript' +endif + +let s:cpo_save = &cpo +set cpo&vim + +" nextgroup doesn't contain objectLiteral, let outer region contains it +syntax region typescriptTypeCast matchgroup=typescriptTypeBrackets + \ start=/< \@!/ end=/>/ + \ contains=@typescriptType + \ nextgroup=@typescriptExpression + \ contained skipwhite oneline + +" runtime syntax/common.vim + +" NOTE: this results in accurate highlighting, but can be slow. +syntax sync fromstart + +"Dollar sign is permitted anywhere in an identifier +setlocal iskeyword-=$ +if main_syntax == 'typescript' || main_syntax == 'typescript.tsx' + setlocal iskeyword+=$ + " syntax cluster htmlJavaScript contains=TOP +endif + +" lowest priority on least used feature +syntax match typescriptLabel /[a-zA-Z_$]\k*:/he=e-1 contains=typescriptReserved nextgroup=@typescriptStatement skipwhite skipempty + +" other keywords like return,case,yield uses containedin +syntax region typescriptBlock matchgroup=typescriptBraces start=/{/ end=/}/ contains=@typescriptStatement,@typescriptComments fold + + +"runtime syntax/basic/identifiers.vim +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 |