Skip to content

Commit

Permalink
fix: argument in "vim.foo({bar})"
Browse files Browse the repository at this point in the history
Problem:
In "vim.foo({bar})", {bar} is not recognized as (argument).

Solution:
Add more special-cases for plain (word).

Closes #102
  • Loading branch information
amaanq authored and justinmk committed Jun 25, 2023
1 parent 755b801 commit 69934ed
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2 deletions.
46 changes: 46 additions & 0 deletions corpus/arguments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ list of { uri:string, name: string } tables
(word)
(word)
(word)
(word)
(word))))

================================================================================
Expand All @@ -61,13 +62,58 @@ multiple arguments on the same line
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)
(argument
(word))
(word))
(line
(word)
(argument
(word))
(word)
(argument
(word))
(word))
(line
(word)
(argument
(word))
(word)
(argument
(word))
(word))
(line
(word)
(word)
(argument
(word))
Expand Down
5 changes: 5 additions & 0 deletions corpus/codeblock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ text
(word)
(taglink
(word))
(word)
(word))
(line
(codeblock
Expand Down Expand Up @@ -331,6 +332,7 @@ To test for a non-empty string, use empty(): >
(word)
(word)
(word)
(word)
(word))
(line
(word)
Expand All @@ -352,6 +354,8 @@ To test for a non-empty string, use empty(): >
(word)
(word)
(word)
(word)
(word)
(codeblock
(code
(line))))))
Expand Down Expand Up @@ -393,6 +397,7 @@ codeblock stop and start on same line
(tag
(word)))
(line
(word)
(word)
(word)
(word))
Expand Down
1 change: 1 addition & 0 deletions corpus/line_block.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ li continues
(line))
(line_li
(line
(word)
(word))
(line)
(line
Expand Down
3 changes: 3 additions & 0 deletions corpus/optionlink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Regular / :help /[
(word)
(word))
(line
(word)
(word)
(word)
(word))
Expand All @@ -95,6 +96,7 @@ Regular / :help /[
(word)
(word)
(word)
(word)
(ERROR
(word))
(word)
Expand All @@ -120,6 +122,7 @@ Regular / :help /[
(word)
(word)
(word)
(word)
(word))))

================================================================================
Expand Down
2 changes: 2 additions & 0 deletions corpus/taglink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Hello |world| hello
(taglink
(word))
(word)
(word)
(word)
(word))
(line
(taglink
Expand Down
9 changes: 9 additions & 0 deletions corpus/url.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ markdown: [https://neovim.io/doc/user/#yay](https://neovim.io/doc/user/#yay).
(word)
(url
(word))
(word)
(word))
(line
(word)
(word)
(url
(word))
(word)
(word)
(url
(word))
(word)
(word))))
10 changes: 8 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = grammar({
word: ($) => choice(
// Try the more-restrictive pattern at higher relative precedence, so that things like
// "foo({a})" parse as "(word) (argument)" instead of "(word)".
token(prec(-1, /[^\n\t{ ][^\n\t ]*/)),
token(prec(-1, /[^{,(\[\n\t ][^,(\[\n\t ]*/)),
token(prec(-2, /[^\n\t ]+/)),
$._word_common,
),
Expand All @@ -43,7 +43,7 @@ module.exports = grammar({
),
word_noli: ($) => choice(
// Lines contained by line_li must not start with a listitem symbol.
token(prec(-1, /[^-•\n\t ][^\n\t ]*/)),
token(prec(-1, /[^-•\n\t ][^(\[\n\t ]*/)),
token(prec(-1, /[-•][^\n\t ]+/)),
$._word_common,
),
Expand Down Expand Up @@ -80,10 +80,16 @@ module.exports = grammar({
'{}',
/\{\{+[0-9]*/,
'(',
')',
'[',
']',
"['",
"']",
/\w+\(/,
'~',
// NOT codeblock: random ">" in middle of the motherflippin text.
'>',
',',
),

keycode: () => choice(
Expand Down

0 comments on commit 69934ed

Please sign in to comment.