Skip to content

Commit

Permalink
[optional_arg]
Browse files Browse the repository at this point in the history
fix #1
  • Loading branch information
justinmk committed Jun 19, 2024
1 parent a75a932 commit d76e6b7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
5 changes: 4 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = grammar({
$.taglink,
$.codespan,
$.argument,
$.optional_arg,
$.keycode,
$.note,
),
Expand Down Expand Up @@ -222,8 +223,10 @@ 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}? for LuaLS-style optional args.
argument: ($) => seq(_word($, /[^}\n\t ]+/, '{', '}'), optional(token.immediate('?'))),
// Optional argument: [arg] (no whitespace allowed)
optional_arg: ($) => _word($, /[^\]\n\t ]+/, '[', ']'),
},
});

Expand Down
14 changes: 6 additions & 8 deletions test/corpus/arguments.txt → test/corpus/argument.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,20 @@ nvim_buf_detach_event[{buf}]
(word))
(line
(word)
(word)
(argument
(word))
(word))))
(optional_arg
(word)))))

================================================================================
NOT an argument
================================================================================
a '{' '}' block
{foo "{bar}" `{baz}` |{baz| } {}
foo { bar
foo { bar
{ {} foo{{ foo{{{
{{
{{{
{{
{{{
{ } foo
, inside { }:
, inside { }:
\} literal } x
\{ literal { x

Expand Down
40 changes: 40 additions & 0 deletions test/corpus/argument_optional.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
================================================================================
optional [argument]
================================================================================
:ar[gs]! [++opt] [+cmd] {arglist} *:args_f!*
:[count]arge[dit][!] [++opt] [+cmd] {name} ..


--------------------------------------------------------------------------------

(help_file
(block
(line
(word)
(optional_arg
(word))
(word)
(optional_arg
(word))
(optional_arg
(word))
(argument
(word))
(tag
(word)))
(line
(word)
(optional_arg
(word))
(word)
(optional_arg
(word))
(optional_arg
(word))
(optional_arg
(word))
(optional_arg
(word))
(argument
(word))
(word))))
4 changes: 2 additions & 2 deletions test/corpus/codeblock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ codeblock stop and start on same line
(line
(word)
(word)
(word)
(word))
(optional_arg
(word)))
(line
(argument
(word))))
Expand Down
4 changes: 2 additions & 2 deletions test/corpus/taglink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ Hello |world| hello
(taglink
(word))
(word)
(word)
(word)
(optional_arg
(word))
(word))
(line
(taglink
Expand Down
4 changes: 1 addition & 3 deletions test/corpus/url.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ markdown: [https://neovim.io/doc/user/#yay](https://neovim.io/doc/user/#yay).
(word))
(line
(word)
(word)
(url
(optional_arg
(word))
(word)
(word)
(url
(word))
(word))))

0 comments on commit d76e6b7

Please sign in to comment.