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

Improve on support for ... and ..i in odd places #157

Merged
merged 12 commits into from
Nov 22, 2024
Merged
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
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"editor.tabSize": 2,
"editor.insertSpaces": true
},
"[javascript]": {
"editor.tabSize": 2,
"editor.insertSpaces": true
},
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## devel

- `...` and `..1` are now supported in more places, such as `x$...` and `[email protected]` (#148).

- `parenthesized_expression` has been simplified to better align with R's parser. Specifically, it now expects exactly 1 required `body` expression, rather than allowing zero or more optional expressions (#144).

- `fn(a b)` is now correctly parsed as an error rather than as two sequential arguments (#140).
Expand Down
201 changes: 184 additions & 17 deletions bindings/r/tests/testthat/_snaps/calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,38 +640,205 @@
f("x"=,)

S-Expression
(call [(17, 0), (17, 10)]
(call [(17, 0), (17, 6)]
function: (identifier [(17, 0), (17, 1)])
arguments: (arguments [(17, 1), (17, 10)]
arguments: (arguments [(17, 1), (17, 6)]
open: "(" [(17, 1), (17, 2)]
argument: (argument [(17, 2), (17, 7)]
name: (dots [(17, 2), (17, 5)])
"=" [(17, 6), (17, 7)]
(comma [(17, 2), (17, 3)])
argument: (argument [(17, 3), (17, 5)]
name: (identifier [(17, 3), (17, 4)])
"=" [(17, 4), (17, 5)]
)
(comma [(17, 8), (17, 9)])
close: ")" [(17, 9), (17, 10)]
close: ")" [(17, 5), (17, 6)]
)
)

Text
f(,y=)

S-Expression
(comment [(19, 0), (19, 36)])

Text
# Dots as unnamed and named argument

S-Expression
(call [(20, 0), (20, 6)]
function: (identifier [(20, 0), (20, 1)])
arguments: (arguments [(20, 1), (20, 6)]
open: "(" [(20, 1), (20, 2)]
argument: (argument [(20, 2), (20, 5)]
value: (dots [(20, 2), (20, 5)])
)
close: ")" [(20, 5), (20, 6)]
)
)

Text
f(...)

S-Expression
(call [(21, 0), (21, 11)]
function: (identifier [(21, 0), (21, 1)])
arguments: (arguments [(21, 1), (21, 11)]
open: "(" [(21, 1), (21, 2)]
(comma [(21, 2), (21, 3)])
argument: (argument [(21, 4), (21, 7)]
value: (dots [(21, 4), (21, 7)])
)
(comma [(21, 7), (21, 8)])
argument: (argument [(21, 9), (21, 10)]
value: (float [(21, 9), (21, 10)])
)
close: ")" [(21, 10), (21, 11)]
)
)

Text
f(, ..., 1)

S-Expression
(call [(22, 0), (22, 10)]
function: (identifier [(22, 0), (22, 1)])
arguments: (arguments [(22, 1), (22, 10)]
open: "(" [(22, 1), (22, 2)]
argument: (argument [(22, 2), (22, 9)]
name: (dots [(22, 2), (22, 5)])
"=" [(22, 6), (22, 7)]
value: (float [(22, 8), (22, 9)])
)
close: ")" [(22, 9), (22, 10)]
)
)

Text
f(... = 1)

S-Expression
(call [(23, 0), (23, 10)]
function: (identifier [(23, 0), (23, 1)])
arguments: (arguments [(23, 1), (23, 10)]
open: "(" [(23, 1), (23, 2)]
argument: (argument [(23, 2), (23, 7)]
name: (dots [(23, 2), (23, 5)])
"=" [(23, 6), (23, 7)]
)
(comma [(23, 8), (23, 9)])
close: ")" [(23, 9), (23, 10)]
)
)

Text
f(... = ,)

S-Expression
(call [(18, 0), (18, 6)]
function: (identifier [(18, 0), (18, 1)])
arguments: (arguments [(18, 1), (18, 6)]
open: "(" [(18, 1), (18, 2)]
(comma [(18, 2), (18, 3)])
argument: (argument [(18, 3), (18, 5)]
name: (identifier [(18, 3), (18, 4)])
"=" [(18, 4), (18, 5)]
(call [(24, 0), (24, 12)]
function: (identifier [(24, 0), (24, 1)])
arguments: (arguments [(24, 1), (24, 12)]
open: "(" [(24, 1), (24, 2)]
argument: (argument [(24, 2), (24, 11)]
name: (dots [(24, 2), (24, 5)])
"=" [(24, 6), (24, 7)]
value: (dots [(24, 8), (24, 11)])
)
close: ")" [(18, 5), (18, 6)]
close: ")" [(24, 11), (24, 12)]
)
)

Text
f(,y=)
f(... = ...)

S-Expression
(comment [(26, 0), (26, 37)])

Text
# `..i` as unnamed and named argument

S-Expression
(call [(27, 0), (27, 6)]
function: (identifier [(27, 0), (27, 1)])
arguments: (arguments [(27, 1), (27, 6)]
open: "(" [(27, 1), (27, 2)]
argument: (argument [(27, 2), (27, 5)]
value: (dot_dot_i [(27, 2), (27, 5)])
)
close: ")" [(27, 5), (27, 6)]
)
)

Text
f(..1)

S-Expression
(call [(28, 0), (28, 11)]
function: (identifier [(28, 0), (28, 1)])
arguments: (arguments [(28, 1), (28, 11)]
open: "(" [(28, 1), (28, 2)]
(comma [(28, 2), (28, 3)])
argument: (argument [(28, 4), (28, 7)]
value: (dot_dot_i [(28, 4), (28, 7)])
)
(comma [(28, 7), (28, 8)])
argument: (argument [(28, 9), (28, 10)]
value: (float [(28, 9), (28, 10)])
)
close: ")" [(28, 10), (28, 11)]
)
)

Text
f(, ..1, 1)

S-Expression
(call [(29, 0), (29, 10)]
function: (identifier [(29, 0), (29, 1)])
arguments: (arguments [(29, 1), (29, 10)]
open: "(" [(29, 1), (29, 2)]
argument: (argument [(29, 2), (29, 9)]
name: (dot_dot_i [(29, 2), (29, 5)])
"=" [(29, 6), (29, 7)]
value: (float [(29, 8), (29, 9)])
)
close: ")" [(29, 9), (29, 10)]
)
)

Text
f(..1 = 1)

S-Expression
(call [(30, 0), (30, 10)]
function: (identifier [(30, 0), (30, 1)])
arguments: (arguments [(30, 1), (30, 10)]
open: "(" [(30, 1), (30, 2)]
argument: (argument [(30, 2), (30, 7)]
name: (dot_dot_i [(30, 2), (30, 5)])
"=" [(30, 6), (30, 7)]
)
(comma [(30, 8), (30, 9)])
close: ")" [(30, 9), (30, 10)]
)
)

Text
f(..1 = ,)

S-Expression
(call [(31, 0), (31, 12)]
function: (identifier [(31, 0), (31, 1)])
arguments: (arguments [(31, 1), (31, 12)]
open: "(" [(31, 1), (31, 2)]
argument: (argument [(31, 2), (31, 11)]
name: (dot_dot_i [(31, 2), (31, 5)])
"=" [(31, 6), (31, 7)]
value: (dot_dot_i [(31, 8), (31, 11)])
)
close: ")" [(31, 11), (31, 12)]
)
)

Text
f(..1 = ..1)


# not a call, subset, or subset2
Expand Down
92 changes: 92 additions & 0 deletions bindings/r/tests/testthat/_snaps/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,98 @@
Text
for (x in y) for (y in z) x + y

S-Expression
(comment [(12, 0), (12, 25)])

Text
# `...` as the `variable`

S-Expression
(for_statement [(13, 0), (13, 34)]
"for" [(13, 0), (13, 3)]
open: "(" [(13, 4), (13, 5)]
variable: (dots [(13, 5), (13, 8)])
"in" [(13, 9), (13, 11)]
sequence: (binary_operator [(13, 12), (13, 15)]
lhs: (float [(13, 12), (13, 13)])
operator: ":" [(13, 13), (13, 14)]
rhs: (float [(13, 14), (13, 15)])
)
close: ")" [(13, 15), (13, 16)]
body: (call [(13, 17), (13, 34)]
function: (identifier [(13, 17), (13, 22)])
arguments: (arguments [(13, 22), (13, 34)]
open: "(" [(13, 22), (13, 23)]
argument: (argument [(13, 23), (13, 33)]
value: (call [(13, 23), (13, 33)]
function: (identifier [(13, 23), (13, 26)])
arguments: (arguments [(13, 26), (13, 33)]
open: "(" [(13, 26), (13, 27)]
argument: (argument [(13, 27), (13, 32)]
value: (string [(13, 27), (13, 32)]
"\"" [(13, 27), (13, 28)]
content: (string_content [(13, 28), (13, 31)])
"\"" [(13, 31), (13, 32)]
)
)
close: ")" [(13, 32), (13, 33)]
)
)
)
close: ")" [(13, 33), (13, 34)]
)
)
)

Text
for (... in 1:2) print(get("..."))

S-Expression
(comment [(15, 0), (15, 25)])

Text
# `..i` as the `variable`

S-Expression
(for_statement [(16, 0), (16, 34)]
"for" [(16, 0), (16, 3)]
open: "(" [(16, 4), (16, 5)]
variable: (dot_dot_i [(16, 5), (16, 8)])
"in" [(16, 9), (16, 11)]
sequence: (binary_operator [(16, 12), (16, 15)]
lhs: (float [(16, 12), (16, 13)])
operator: ":" [(16, 13), (16, 14)]
rhs: (float [(16, 14), (16, 15)])
)
close: ")" [(16, 15), (16, 16)]
body: (call [(16, 17), (16, 34)]
function: (identifier [(16, 17), (16, 22)])
arguments: (arguments [(16, 22), (16, 34)]
open: "(" [(16, 22), (16, 23)]
argument: (argument [(16, 23), (16, 33)]
value: (call [(16, 23), (16, 33)]
function: (identifier [(16, 23), (16, 26)])
arguments: (arguments [(16, 26), (16, 33)]
open: "(" [(16, 26), (16, 27)]
argument: (argument [(16, 27), (16, 32)]
value: (string [(16, 27), (16, 32)]
"\"" [(16, 27), (16, 28)]
content: (string_content [(16, 28), (16, 31)])
"\"" [(16, 31), (16, 32)]
)
)
close: ")" [(16, 32), (16, 33)]
)
)
)
close: ")" [(16, 33), (16, 34)]
)
)
)

Text
for (..1 in 1:2) print(get("..1"))


# for no body

Expand Down
40 changes: 40 additions & 0 deletions bindings/r/tests/testthat/_snaps/extract.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@
Text
foo$bar()$baz[[1]]$bam

S-Expression
(extract_operator [(7, 0), (7, 7)]
lhs: (identifier [(7, 0), (7, 3)])
operator: "$" [(7, 3), (7, 4)]
rhs: (dots [(7, 4), (7, 7)])
)

Text
foo$...

S-Expression
(extract_operator [(8, 0), (8, 7)]
lhs: (identifier [(8, 0), (8, 3)])
operator: "$" [(8, 3), (8, 4)]
rhs: (dot_dot_i [(8, 4), (8, 7)])
)

Text
foo$..1


# dollar no rhs

Expand Down Expand Up @@ -180,6 +200,26 @@
Text
foo@"bar"

S-Expression
(extract_operator [(5, 0), (5, 7)]
lhs: (identifier [(5, 0), (5, 3)])
operator: "@" [(5, 3), (5, 4)]
rhs: (dots [(5, 4), (5, 7)])
)

Text
foo@...

S-Expression
(extract_operator [(6, 0), (6, 7)]
lhs: (identifier [(6, 0), (6, 3)])
operator: "@" [(6, 3), (6, 4)]
rhs: (dot_dot_i [(6, 4), (6, 7)])
)

Text
[email protected]


# slot no rhs

Expand Down
Loading