diff --git a/grammar.js b/grammar.js index 832ff34..bbfb7bb 100644 --- a/grammar.js +++ b/grammar.js @@ -14,7 +14,7 @@ const _uppercase_word = /[A-Z0-9.()][-A-Z0-9.()_]+/; const _li_token = /[-•][ ]+/; module.exports = grammar({ - name: 'vimdoc', + name: 'vimdoc2', extras: () => [/[\t ]/], @@ -57,6 +57,7 @@ module.exports = grammar({ $.taglink, $.codespan, $.argument, + $.optional, $.keycode, $.note, ), @@ -90,7 +91,7 @@ module.exports = grammar({ ), note: () => choice( - 'Note:', 'NOTE:', 'Notes:', + 'The', 'the', 'Notes:', 'Warning:', 'WARNING:', 'Deprecated', 'DEPRECATED:' ), @@ -106,6 +107,10 @@ module.exports = grammar({ /ALT-./, ), + // Optional argument: [arg] (no whitespace allowed). + // This is the vimdoc style optional arg, as opposed to {arg}? (LuaLS style). + optional: () => /\[[^\]{\n\t ]+\]/, + // First part (minus tags) of h3 or column_heading. uppercase_name: () => seq( token.immediate(_uppercase_word), // No whitespace before heading. @@ -222,7 +227,7 @@ module.exports = grammar({ taglink: ($) => _word($, prec(1, /[^|\n\t ]+/), '|', '|'), // Inline code (may contain whitespace!): `foo bar` codespan: ($) => _word($, /[^``\n]+/, '`', '`'), - // Argument: {arg} (no whitespace allowed) + // Argument: {arg} (no whitespace allowed), also {arg}? (LuaLS style "optional arg"). argument: ($) => seq(_word($, /[^}\n\t ]+/, '{', '}'), optional(token.immediate('?'))), }, }); diff --git a/queries/vimdoc/highlights.scm b/queries/vimdoc/highlights.scm index 0bb48cf..2de1b1a 100644 --- a/queries/vimdoc/highlights.scm +++ b/queries/vimdoc/highlights.scm @@ -44,6 +44,8 @@ (argument) @variable.parameter +(optional) @variable.parameter + (keycode) @string.special (url) @string.special.url diff --git a/test/corpus/arguments.txt b/test/corpus/argument.txt similarity index 99% rename from test/corpus/arguments.txt rename to test/corpus/argument.txt index 05351f7..a5c5715 100644 --- a/test/corpus/arguments.txt +++ b/test/corpus/argument.txt @@ -133,12 +133,12 @@ NOT an argument ================================================================================ a '{' '}' block {foo "{bar}" `{baz}` |{baz| } {} -foo { bar +foo { bar { {} foo{{ foo{{{ - {{ - {{{ + {{ + {{{ { } foo -, inside { }: +, inside { }: \} literal } x \{ literal { x diff --git a/test/corpus/argument_optional.txt b/test/corpus/argument_optional.txt new file mode 100644 index 0000000..7b5cc6f --- /dev/null +++ b/test/corpus/argument_optional.txt @@ -0,0 +1,32 @@ +================================================================================ +optional [argument] +================================================================================ +:ar[gs]! [++opt] [+cmd] {arglist} *:args_f!* +:[count]arge[dit][!] [++opt] [+cmd] {name} .. + + +-------------------------------------------------------------------------------- + +(help_file + (block + (line + (word) + (optional) + (word) + (optional) + (optional) + (argument + (word)) + (tag + (word))) + (line + (word) + (optional) + (word) + (optional) + (optional) + (optional) + (optional) + (argument + (word)) + (word)))) diff --git a/test/corpus/codeblock.txt b/test/corpus/codeblock.txt index 0a9c9a9..f1c655b 100644 --- a/test/corpus/codeblock.txt +++ b/test/corpus/codeblock.txt @@ -398,8 +398,7 @@ codeblock stop and start on same line (line (word) (word) - (word) - (word)) + (optional)) (line (argument (word)))) diff --git a/test/corpus/taglink.txt b/test/corpus/taglink.txt index 4e0440d..799489f 100644 --- a/test/corpus/taglink.txt +++ b/test/corpus/taglink.txt @@ -56,8 +56,7 @@ Hello |world| hello (taglink (word)) (word) - (word) - (word) + (optional) (word)) (line (taglink diff --git a/test/corpus/url.txt b/test/corpus/url.txt index ea53720..53e0ef2 100644 --- a/test/corpus/url.txt +++ b/test/corpus/url.txt @@ -54,10 +54,7 @@ markdown: [https://neovim.io/doc/user/#yay](https://neovim.io/doc/user/#yay). (word)) (line (word) - (word) - (url - (word)) - (word) + (optional) (word) (url (word))