Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[optional] argument #109

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]/],

Expand Down Expand Up @@ -57,6 +57,7 @@ module.exports = grammar({
$.taglink,
$.codespan,
$.argument,
$.optional,
$.keycode,
$.note,
),
Expand Down Expand Up @@ -90,7 +91,7 @@ module.exports = grammar({
),

note: () => choice(
'Note:', 'NOTE:', 'Notes:',
'The', 'the', 'Notes:',
'Warning:', 'WARNING:',
'Deprecated', 'DEPRECATED:'
),
Expand All @@ -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.
Expand Down Expand Up @@ -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('?'))),
},
});
Expand Down
2 changes: 2 additions & 0 deletions queries/vimdoc/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

(argument) @variable.parameter

(optional) @variable.parameter

(keycode) @string.special

(url) @string.special.url
Expand Down
8 changes: 4 additions & 4 deletions test/corpus/arguments.txt → test/corpus/argument.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions test/corpus/argument_optional.txt
Original file line number Diff line number Diff line change
@@ -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))))
3 changes: 1 addition & 2 deletions test/corpus/codeblock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ codeblock stop and start on same line
(line
(word)
(word)
(word)
(word))
(optional))
(line
(argument
(word))))
Expand Down
3 changes: 1 addition & 2 deletions test/corpus/taglink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ Hello |world| hello
(taglink
(word))
(word)
(word)
(word)
(optional)
(word))
(line
(taglink
Expand Down
5 changes: 1 addition & 4 deletions test/corpus/url.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down