From a4e9c504041138253fc846cc9a1ac56615a6baf4 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/argument_optional.txt | 211 +++++++++++++++++++++++++++++++++++ corpus/arguments.txt | 201 +++------------------------------ corpus/codeblock.txt | 4 +- corpus/taglink.txt | 4 +- corpus/url.txt | 4 +- grammar.js | 3 + 6 files changed, 233 insertions(+), 194 deletions(-) create mode 100644 corpus/argument_optional.txt diff --git a/corpus/argument_optional.txt b/corpus/argument_optional.txt new file mode 100644 index 0000000..87b293d --- /dev/null +++ b/corpus/argument_optional.txt @@ -0,0 +1,211 @@ +================================================================================ +argument +================================================================================ +argument: {arg} +tuple: {arg,arg} +keycode: CTRL-R {CTRL-R} {register CTRL-F} +list of { uri:string, name: string } tables + + +-------------------------------------------------------------------------------- + +(help_file + (block + (line + (word) + (argument + (word))) + (line + (word) + (argument + (word))) + (line + (word) + (keycode) + (argument + (word)) + (word) + (ERROR + (word)) + (keycode) + (word)) + (line + (word) + (word) + (word) + (word) + (word) + (word) + (word) + (word) + (word)))) + +================================================================================ +multiple arguments on the same line +================================================================================ +{foo} {bar} {baz} + + +-------------------------------------------------------------------------------- + +(help_file + (block + (line + (argument + (word)) + (argument + (word)) + (argument + (word))))) + +================================================================================ +argument in parentheses +================================================================================ +({aaa}) +vim.foo({bar}) +vim.foo( {bar}) +nvim_foo({bar}) +nvim_foo({bar},{baz}) +nvim_foo({bar}, {baz}) +nvim_buf_detach_event[{buf}] + + +-------------------------------------------------------------------------------- + +(help_file + (block + (line + (word) + (argument + (word)) + (word)) + (line + (word) + (word) + (argument + (word)) + (word)) + (line + (word) + (word) + (argument + (word)) + (word)) + (line + (word) + (word) + (argument + (word)) + (word)) + (line + (word) + (word) + (argument + (word)) + (word) + (argument + (word)) + (word)) + (line + (word) + (word) + (argument + (word)) + (word) + (argument + (word)) + (word)) + (line + (word) + (optional_arg + (word))))) + +================================================================================ +NOT an argument +================================================================================ +a '{' '}' block +{foo "{bar}" `{baz}` |{baz| } {} +foo { bar +{ {} foo{{ foo{{{ + {{ + {{{ +{ } foo +, inside { }: +\} literal } x +\{ literal { x + +=============== +3. Netrw *netrw-ref* {{{1 + +EXTERNAL *netrw-externapp* {{{2 + + +-------------------------------------------------------------------------------- + +(help_file + (block + (line + (word) + (word) + (word) + (word) + (word) + (word)) + (line + (word) + (ERROR + (word)) + (word) + (codespan + (word)) + (taglink + (word)) + (word) + (word)) + (line + (word) + (word) + (word)) + (line + (word) + (word) + (word) + (word)) + (line + (word)) + (line + (word)) + (line + (word) + (word) + (word)) + (line + (word) + (word) + (word) + (word)) + (line + (word) + (word) + (word) + (word)) + (line + (word) + (word) + (word) + (word))) + (block + (line + (h1 + (word) + (word) + (tag + (word)) + (word)))) + (block + (line + (h3 + (uppercase_name) + (tag + (word)) + (word))))) diff --git a/corpus/arguments.txt b/corpus/arguments.txt index 0abb389..65c2fc6 100644 --- a/corpus/arguments.txt +++ b/corpus/arguments.txt @@ -1,11 +1,8 @@ ================================================================================ -argument +optional [argument] ================================================================================ -argument: {arg} -tuple: {arg,arg} -keycode: CTRL-R {CTRL-R} {register CTRL-F} -list of { uri:string, name: string } tables - +:ar[gs]! [++opt] [+cmd] {arglist} *:args_f!* +:[count]arge[dit][!] [++opt] [+cmd] {name} .. -------------------------------------------------------------------------------- @@ -13,201 +10,31 @@ list of { uri:string, name: string } tables (block (line (word) - (argument - (word))) - (line - (word) - (argument - (word))) - (line - (word) - (keycode) - (argument + (optional_arg (word)) (word) - (ERROR + (optional_arg (word)) - (keycode) - (word)) - (line - (word) - (word) - (word) - (word) - (word) - (word) - (word) - (word) - (word)))) - -================================================================================ -multiple arguments on the same line -================================================================================ -{foo} {bar} {baz} - - --------------------------------------------------------------------------------- - -(help_file - (block - (line - (argument + (optional_arg (word)) (argument (word)) - (argument - (word))))) - -================================================================================ -argument in parentheses -================================================================================ -({aaa}) -vim.foo({bar}) -vim.foo( {bar}) -nvim_foo({bar}) -nvim_foo({bar},{baz}) -nvim_foo({bar}, {baz}) -nvim_buf_detach_event[{buf}] - - --------------------------------------------------------------------------------- - -(help_file - (block - (line - (word) - (argument - (word)) - (word)) - (line - (word) - (word) - (argument - (word)) - (word)) + (tag + (word))) (line (word) - (word) - (argument + (optional_arg (word)) - (word)) - (line (word) - (word) - (argument + (optional_arg (word)) - (word)) - (line - (word) - (word) - (argument - (word)) - (word) - (argument + (optional_arg (word)) - (word)) - (line - (word) - (word) - (argument + (optional_arg (word)) - (word) - (argument + (optional_arg (word)) - (word)) - (line - (word) - (word) (argument (word)) - (word)))) - -================================================================================ -NOT an argument -================================================================================ -a '{' '}' block -{foo "{bar}" `{baz}` |{baz| } {} -foo { bar -{ {} foo{{ foo{{{ - {{ - {{{ -{ } foo -, inside { }: -\} literal } x -\{ literal { x - -=============== -3. Netrw *netrw-ref* {{{1 - -EXTERNAL *netrw-externapp* {{{2 - - --------------------------------------------------------------------------------- - -(help_file - (block - (line - (word) - (word) - (word) - (word) - (word) (word)) - (line - (word) - (ERROR - (word)) - (word) - (codespan - (word)) - (taglink - (word)) - (word) - (word)) - (line - (word) - (word) - (word)) - (line - (word) - (word) - (word) - (word)) - (line - (word)) - (line - (word)) - (line - (word) - (word) - (word)) - (line - (word) - (word) - (word) - (word)) - (line - (word) - (word) - (word) - (word)) - (line - (word) - (word) - (word) - (word))) - (block - (line - (h1 - (word) - (word) - (tag - (word)) - (word)))) - (block - (line - (h3 - (uppercase_name) - (tag - (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 ]+/, '[', ']'), }, });