From eeca99fa40374167981cec0df5dc080844262ae2 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 26 Jun 2023 00:25:04 +0200 Subject: [PATCH] optional [argument] fix #1 --- corpus/{arguments.txt => argument.txt} | 6 ++-- corpus/argument_optional.txt | 40 ++++++++++++++++++++++++++ corpus/codeblock.txt | 4 +-- corpus/taglink.txt | 4 +-- corpus/url.txt | 4 +-- grammar.js | 3 ++ 6 files changed, 50 insertions(+), 11 deletions(-) rename corpus/{arguments.txt => argument.txt} (98%) create mode 100644 corpus/argument_optional.txt diff --git a/corpus/arguments.txt b/corpus/argument.txt similarity index 98% rename from corpus/arguments.txt rename to corpus/argument.txt index 0abb389..87b293d 100644 --- a/corpus/arguments.txt +++ b/corpus/argument.txt @@ -117,10 +117,8 @@ nvim_buf_detach_event[{buf}] (word)) (line (word) - (word) - (argument - (word)) - (word)))) + (optional_arg + (word))))) ================================================================================ NOT an argument diff --git a/corpus/argument_optional.txt b/corpus/argument_optional.txt new file mode 100644 index 0000000..65c2fc6 --- /dev/null +++ b/corpus/argument_optional.txt @@ -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)) + (MISSING "<"))) diff --git a/corpus/codeblock.txt b/corpus/codeblock.txt index 0a9c9a9..a138078 100644 --- a/corpus/codeblock.txt +++ b/corpus/codeblock.txt @@ -398,8 +398,8 @@ codeblock stop and start on same line (line (word) (word) - (word) - (word)) + (optional_arg + (word))) (line (argument (word)))) diff --git a/corpus/taglink.txt b/corpus/taglink.txt index 894eeb3..8bdea96 100644 --- a/corpus/taglink.txt +++ b/corpus/taglink.txt @@ -56,8 +56,8 @@ Hello |world| hello (taglink (word)) (word) - (word) - (word) + (optional_arg + (word)) (word)) (line (taglink diff --git a/corpus/url.txt b/corpus/url.txt index ea53720..8e7f4b1 100644 --- a/corpus/url.txt +++ b/corpus/url.txt @@ -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)))) diff --git a/grammar.js b/grammar.js index aff66e2..919d505 100644 --- a/grammar.js +++ b/grammar.js @@ -53,6 +53,7 @@ module.exports = grammar({ $.taglink, $.codespan, $.argument, + $.optional_arg, $.keycode, ), @@ -210,6 +211,8 @@ module.exports = grammar({ codespan: ($) => _word($, /[^``\n]+/, '`', '`'), // Argument: {arg} (no whitespace allowed) argument: ($) => _word($, /[^}\n\t ]+/, '{', '}'), + // Optional argument: [arg] + optional_arg: ($) => _word($, /[^\]\n\t ]+/, '[', ']'), }, });