Skip to content

Commit 608ffda

Browse files
authored
Sync with tree-sitter-r main (#357)
* Update to r-lib/tree-sitter-r@b92b2cf * Update to r-lib/tree-sitter-r@f6f60a5 * Update to r-lib/tree-sitter-r@a90d569 In particular for support for `NULL` in argument name position * Update to r-lib/tree-sitter-r@bc8b477 For better hexadecimal support * Update to r-lib/tree-sitter-r@daa26a2 Just to get current * Use tree-sitter 0.24.7 This is the version tree-sitter-r is synced with now * More changelog bullet tweaking
1 parent 78086c4 commit 608ffda

17 files changed

Lines changed: 545 additions & 37 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
# Development version
44

5+
- Binary exponents are now supported in hexadecimal constants (#357).
6+
7+
- `NULL` is now allowed in function call argument name position (#357).
8+
9+
- Fixed a case where some valid raw strings would cause a parse error (#255).
10+
511
- Empty `{}` are no longer ever expanded (#43).
612

713
This allows for syntax like:

Cargo.lock

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ toml = "0.8.19"
8080
tower-lsp = { git = "https://github.com/lionel-/tower-lsp", branch = "bugfix/patches" }
8181
tracing = { version = "0.1.40", default-features = false, features = ["std"] }
8282
tracing-subscriber = "0.3.19"
83-
tree-sitter = "0.23.0"
84-
tree-sitter-r = { git = "https://github.com/r-lib/tree-sitter-r", rev = "a0d3e3307489c3ca54da8c7b5b4e0c5f5fd6953a" }
83+
tree-sitter = "0.24.7"
84+
tree-sitter-r = { git = "https://github.com/r-lib/tree-sitter-r", rev = "daa26a2ff0d9546e9125c7d8bcec046027f02070" }
8585
triomphe = "0.1.14"
8686
url = "2.5.3"
8787
uuid = { version = "1.11.0", features = ["v4"] }

crates/air_r_formatter/src/r/any/argument_name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ impl FormatRule<AnyRArgumentName> for FormatAnyRArgumentName {
1111
AnyRArgumentName::RDotDotI(node) => node.format().fmt(f),
1212
AnyRArgumentName::RDots(node) => node.format().fmt(f),
1313
AnyRArgumentName::RIdentifier(node) => node.format().fmt(f),
14+
AnyRArgumentName::RNullExpression(node) => node.format().fmt(f),
1415
AnyRArgumentName::RStringValue(node) => node.format().fmt(f),
1516
}
1617
}

crates/air_r_formatter/tests/specs/r/call.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ fn(a = 1, another_really_really_long_argument_to_test_this_feature, a_really_lon
3030
fn(..1, ..2)
3131
fn(..1 = 1, ..2 = 2)
3232

33+
# ------------------------------------------------------------------------
34+
# `NULL` argument name (r-lib/tree-sitter-r#164)
35+
36+
fn(NULL = 1)
37+
fn(NULL = 1,)
38+
fn(NULL = )
39+
fn(NULL = ,)
40+
3341
# ------------------------------------------------------------------------
3442
# User requested line break
3543

crates/air_r_formatter/tests/specs/r/call.R.snap

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ fn(a = 1, another_really_really_long_argument_to_test_this_feature, a_really_lon
3737
fn(..1, ..2)
3838
fn(..1 = 1, ..2 = 2)
3939
40+
# ------------------------------------------------------------------------
41+
# `NULL` argument name (r-lib/tree-sitter-r#164)
42+
43+
fn(NULL = 1)
44+
fn(NULL = 1,)
45+
fn(NULL = )
46+
fn(NULL = ,)
47+
4048
# ------------------------------------------------------------------------
4149
# User requested line break
4250
@@ -926,6 +934,14 @@ fn(
926934
fn(..1, ..2)
927935
fn(..1 = 1, ..2 = 2)
928936
937+
# ------------------------------------------------------------------------
938+
# `NULL` argument name (r-lib/tree-sitter-r#164)
939+
940+
fn(NULL = 1)
941+
fn(NULL = 1, )
942+
fn(NULL = )
943+
fn(NULL = , )
944+
929945
# ------------------------------------------------------------------------
930946
# User requested line break
931947
@@ -1832,9 +1848,9 @@ foo(bar[
18321848

18331849
# Lines exceeding max width of 80 characters
18341850
```
1835-
308: my_long_list_my_long_list_my_long_list_my_long_list_long_long_long_long_long_list,
1836-
781: foobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbazzzzzzzzzfoobarbaz
1837-
785: c(list(foobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbazzzzzzzzzfoobarbaz()))
1838-
788: c(list(foobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbazzzzzzzzzfoobarbaz(
1839-
801: name = foobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbazzzzzzzzzfoobarbaz(
1851+
316: my_long_list_my_long_list_my_long_list_my_long_list_long_long_long_long_long_list,
1852+
789: foobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbazzzzzzzzzfoobarbaz
1853+
793: c(list(foobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbazzzzzzzzzfoobarbaz()))
1854+
796: c(list(foobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbazzzzzzzzzfoobarbaz(
1855+
809: name = foobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbafoobarbazzzzzzzzzfoobarbaz(
18401856
```

crates/air_r_parser/src/parse.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ impl<'src> RWalk<'src> {
955955

956956
// A complication with arguments is that tree-sitter-r doesn't differentiate
957957
// between named and unnamed arguments at the node level. Named arguments
958-
// have a `"name"` field node (identifier/string/dots/dotdoti) followed
958+
// have a `"name"` field node (identifier/string/dots/dotdoti/null) followed
959959
// by an `=` sign. If we see that `"name"` field, we open the name clause
960960
// node and close it after we see the `=`.
961961
let mut seen_equal = false;
@@ -966,7 +966,8 @@ impl<'src> RWalk<'src> {
966966
RSyntaxKind::R_IDENTIFIER
967967
| RSyntaxKind::R_STRING_VALUE
968968
| RSyntaxKind::R_DOTS
969-
| RSyntaxKind::R_DOT_DOT_I => {
969+
| RSyntaxKind::R_DOT_DOT_I
970+
| RSyntaxKind::R_NULL_EXPRESSION => {
970971
if !seen_equal {
971972
if let Some(next_field_name) = iter.peek_field_name() {
972973
if next_field_name == "name" {

crates/air_r_parser/tests/snapshots/ok/calls.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,14 @@ fn(
4242
)
4343

4444
{expr}(a = 1)
45+
46+
# `NULL` argument name (r-lib/tree-sitter-r#164)
47+
fn(
48+
NULL = 1
49+
)
50+
fn(
51+
NULL =
52+
)
53+
fn(
54+
NULL = ,
55+
)

crates/air_r_parser/tests/snapshots/ok/calls.R.snap

Lines changed: 125 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ fn(
5050
5151
{expr}(a = 1)
5252
53+
# `NULL` argument name (r-lib/tree-sitter-r#164)
54+
fn(
55+
NULL = 1
56+
)
57+
fn(
58+
NULL =
59+
)
60+
fn(
61+
NULL = ,
62+
)
5363
```
5464

5565

@@ -600,17 +610,84 @@ RRoot {
600610
r_paren_token: R_PAREN@367..368 ")" [] [],
601611
},
602612
},
613+
RCall {
614+
function: RIdentifier {
615+
name_token: IDENT@368..421 "fn" [Newline("\n"), Newline("\n"), Comments("# `NULL` argument nam ..."), Newline("\n")] [],
616+
},
617+
arguments: RCallArguments {
618+
l_paren_token: L_PAREN@421..422 "(" [] [],
619+
items: RArgumentList [
620+
RArgument {
621+
name_clause: RArgumentNameClause {
622+
name: RNullExpression {
623+
null_token: NULL_KW@422..429 "NULL" [Newline("\n"), Whitespace(" ")] [],
624+
},
625+
eq_token: EQUAL@429..431 "=" [Whitespace(" ")] [],
626+
},
627+
value: RDoubleValue {
628+
value_token: R_DOUBLE_LITERAL@431..433 "1" [Whitespace(" ")] [],
629+
},
630+
},
631+
],
632+
r_paren_token: R_PAREN@433..435 ")" [Newline("\n")] [],
633+
},
634+
},
635+
RCall {
636+
function: RIdentifier {
637+
name_token: IDENT@435..438 "fn" [Newline("\n")] [],
638+
},
639+
arguments: RCallArguments {
640+
l_paren_token: L_PAREN@438..439 "(" [] [],
641+
items: RArgumentList [
642+
RArgument {
643+
name_clause: RArgumentNameClause {
644+
name: RNullExpression {
645+
null_token: NULL_KW@439..446 "NULL" [Newline("\n"), Whitespace(" ")] [],
646+
},
647+
eq_token: EQUAL@446..449 "=" [Whitespace(" ")] [Whitespace(" ")],
648+
},
649+
value: missing (optional),
650+
},
651+
],
652+
r_paren_token: R_PAREN@449..451 ")" [Newline("\n")] [],
653+
},
654+
},
655+
RCall {
656+
function: RIdentifier {
657+
name_token: IDENT@451..454 "fn" [Newline("\n")] [],
658+
},
659+
arguments: RCallArguments {
660+
l_paren_token: L_PAREN@454..455 "(" [] [],
661+
items: RArgumentList [
662+
RArgument {
663+
name_clause: RArgumentNameClause {
664+
name: RNullExpression {
665+
null_token: NULL_KW@455..462 "NULL" [Newline("\n"), Whitespace(" ")] [],
666+
},
667+
eq_token: EQUAL@462..464 "=" [Whitespace(" ")] [],
668+
},
669+
value: missing (optional),
670+
},
671+
COMMA@464..466 "," [Whitespace(" ")] [],
672+
RArgument {
673+
name_clause: missing (optional),
674+
value: missing (optional),
675+
},
676+
],
677+
r_paren_token: R_PAREN@466..468 ")" [Newline("\n")] [],
678+
},
679+
},
603680
],
604-
eof_token: EOF@368..369 "" [Newline("\n")] [],
681+
eof_token: EOF@468..468 "" [] [],
605682
}
606683
```
607684

608685
## CST
609686

610687
```
611-
0: R_ROOT@0..369
688+
0: R_ROOT@0..468
612689
0: (empty)
613-
1: R_EXPRESSION_LIST@0..368
690+
1: R_EXPRESSION_LIST@0..468
614691
0: R_CALL@0..4
615692
0: R_IDENTIFIER@0..2
616693
0: IDENT@0..2 "fn" [] []
@@ -973,6 +1050,50 @@ RRoot {
9731050
1: R_DOUBLE_VALUE@365..367
9741051
0: R_DOUBLE_LITERAL@365..367 "1" [Whitespace(" ")] []
9751052
2: R_PAREN@367..368 ")" [] []
976-
2: EOF@368..369 "" [Newline("\n")] []
1053+
23: R_CALL@368..435
1054+
0: R_IDENTIFIER@368..421
1055+
0: IDENT@368..421 "fn" [Newline("\n"), Newline("\n"), Comments("# `NULL` argument nam ..."), Newline("\n")] []
1056+
1: R_CALL_ARGUMENTS@421..435
1057+
0: L_PAREN@421..422 "(" [] []
1058+
1: R_ARGUMENT_LIST@422..433
1059+
0: R_ARGUMENT@422..433
1060+
0: R_ARGUMENT_NAME_CLAUSE@422..431
1061+
0: R_NULL_EXPRESSION@422..429
1062+
0: NULL_KW@422..429 "NULL" [Newline("\n"), Whitespace(" ")] []
1063+
1: EQUAL@429..431 "=" [Whitespace(" ")] []
1064+
1: R_DOUBLE_VALUE@431..433
1065+
0: R_DOUBLE_LITERAL@431..433 "1" [Whitespace(" ")] []
1066+
2: R_PAREN@433..435 ")" [Newline("\n")] []
1067+
24: R_CALL@435..451
1068+
0: R_IDENTIFIER@435..438
1069+
0: IDENT@435..438 "fn" [Newline("\n")] []
1070+
1: R_CALL_ARGUMENTS@438..451
1071+
0: L_PAREN@438..439 "(" [] []
1072+
1: R_ARGUMENT_LIST@439..449
1073+
0: R_ARGUMENT@439..449
1074+
0: R_ARGUMENT_NAME_CLAUSE@439..449
1075+
0: R_NULL_EXPRESSION@439..446
1076+
0: NULL_KW@439..446 "NULL" [Newline("\n"), Whitespace(" ")] []
1077+
1: EQUAL@446..449 "=" [Whitespace(" ")] [Whitespace(" ")]
1078+
1: (empty)
1079+
2: R_PAREN@449..451 ")" [Newline("\n")] []
1080+
25: R_CALL@451..468
1081+
0: R_IDENTIFIER@451..454
1082+
0: IDENT@451..454 "fn" [Newline("\n")] []
1083+
1: R_CALL_ARGUMENTS@454..468
1084+
0: L_PAREN@454..455 "(" [] []
1085+
1: R_ARGUMENT_LIST@455..466
1086+
0: R_ARGUMENT@455..464
1087+
0: R_ARGUMENT_NAME_CLAUSE@455..464
1088+
0: R_NULL_EXPRESSION@455..462
1089+
0: NULL_KW@455..462 "NULL" [Newline("\n"), Whitespace(" ")] []
1090+
1: EQUAL@462..464 "=" [Whitespace(" ")] []
1091+
1: (empty)
1092+
1: COMMA@464..466 "," [Whitespace(" ")] []
1093+
2: R_ARGUMENT@466..466
1094+
0: (empty)
1095+
1: (empty)
1096+
2: R_PAREN@466..468 ")" [Newline("\n")] []
1097+
2: EOF@468..468 "" [] []
9771098
9781099
```

crates/air_r_parser/tests/snapshots/ok/value/double_value.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,23 @@
22
2.5
33
1e6
44
0x123F
5+
6+
# Hexadecimal
7+
# `x` vs `X`
8+
0x123
9+
0X123
10+
# Numbers and letters
11+
0xDEAD
12+
0XDEAD
13+
0x1f2F3
14+
0X1f2F3
15+
# `p` vs `P`
16+
0x0p0
17+
0x0P0
18+
0x0p123
19+
0x0P123
20+
# `+` and `-`
21+
0x0p+0
22+
0x0p-0
23+
0x0p+123
24+
0x0p-123

0 commit comments

Comments
 (0)