Skip to content

Commit be2f692

Browse files
committed
refactor: expose string_content
1 parent 56144af commit be2f692

File tree

7 files changed

+116
-55
lines changed

7 files changed

+116
-55
lines changed

grammar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = grammar({
7171
],
7272

7373
externals: $ => [
74-
$._string_content,
74+
$.string_content,
7575
$.raw_string_literal,
7676
$.float_literal,
7777
$._outer_block_doc_comment_marker,
@@ -1464,7 +1464,7 @@ module.exports = grammar({
14641464
alias(/[bc]?"/, '"'),
14651465
repeat(choice(
14661466
$.escape_sequence,
1467-
$._string_content,
1467+
$.string_content,
14681468
)),
14691469
token.immediate('"'),
14701470
),

test/corpus/declarations.txt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ fn foo(bar: impl for<'a> Baz<Quux<'a>>) {}
126126
(macro_invocation
127127
macro: (identifier)
128128
(token_tree
129-
(string_literal)
129+
(string_literal
130+
(string_content))
130131
(identifier))))))
131132
(function_item
132133
name: (identifier)
@@ -296,14 +297,16 @@ extern "C" fn printf(
296297
(function_item
297298
(function_modifiers
298299
(extern_modifier
299-
(string_literal)))
300+
(string_literal
301+
(string_content))))
300302
(identifier)
301303
(parameters)
302304
(block))
303305
(function_item
304306
(function_modifiers
305307
(extern_modifier
306-
(string_literal)))
308+
(string_literal
309+
(string_content))))
307310
(identifier)
308311
(parameters
309312
(pointer_type
@@ -1076,7 +1079,8 @@ mod macos_only {}
10761079
(identifier)
10771080
arguments: (token_tree
10781081
(identifier)
1079-
(string_literal))))
1082+
(string_literal
1083+
(string_content)))))
10801084
(mod_item
10811085
name: (identifier)
10821086
body: (declaration_list))
@@ -1091,7 +1095,8 @@ mod macos_only {}
10911095
(scoped_identifier
10921096
path: (identifier)
10931097
name: (identifier))
1094-
value: (string_literal))))
1098+
value: (string_literal
1099+
(string_content)))))
10951100

10961101
================================================================================
10971102
Inner attributes
@@ -1172,7 +1177,8 @@ fn baz() {}
11721177
(macro_invocation
11731178
(identifier)
11741179
(token_tree
1175-
(string_literal)))))
1180+
(string_literal
1181+
(string_content))))))
11761182
(function_item
11771183
(identifier)
11781184
(parameters)
@@ -1268,7 +1274,8 @@ pub enum Error {
12681274
(attribute
12691275
(identifier)
12701276
(token_tree
1271-
(string_literal)
1277+
(string_literal
1278+
(string_content))
12721279
(identifier)
12731280
(token_tree
12741281
(integer_literal)))))
@@ -1280,7 +1287,8 @@ pub enum Error {
12801287
(attribute
12811288
(identifier)
12821289
(token_tree
1283-
(string_literal)
1290+
(string_literal
1291+
(string_content))
12841292
(identifier)
12851293
(identifier)
12861294
(identifier)
@@ -1324,7 +1332,8 @@ fn foo() {
13241332
(identifier)
13251333
arguments: (token_tree
13261334
(identifier)
1327-
(string_literal))))
1335+
(string_literal
1336+
(string_content)))))
13281337
(identifier))))
13291338
(let_declaration
13301339
pattern: (identifier)
@@ -2169,7 +2178,8 @@ extern "C" {}
21692178
(type_identifier)))))))
21702179
(foreign_mod_item
21712180
(extern_modifier
2172-
(string_literal))
2181+
(string_literal
2182+
(string_content)))
21732183
(declaration_list)))
21742184

21752185
================================================================================
@@ -2242,7 +2252,7 @@ Array Constraint in Where Clause
22422252
================================================================================
22432253

22442254
fn foo<D>(val: D)
2245-
where
2255+
where
22462256
[u8; 32]: From<D>,
22472257

22482258
{}

test/corpus/expressions.txt

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,12 @@ Array expressions
377377
(integer_literal)))
378378
(expression_statement
379379
(array_expression
380-
(string_literal)
381-
(string_literal)
382-
(string_literal)))
380+
(string_literal
381+
(string_content))
382+
(string_literal
383+
(string_content))
384+
(string_literal
385+
(string_content))))
383386
(expression_statement
384387
(array_expression
385388
(integer_literal)
@@ -389,13 +392,17 @@ Array expressions
389392
(attribute_item
390393
(attribute
391394
(identifier)
392-
arguments: (token_tree (identifier))))
393-
(string_literal)
395+
arguments: (token_tree
396+
(identifier))))
397+
(string_literal
398+
(string_content))
394399
(attribute_item
395400
(attribute
396401
(identifier)
397-
arguments: (token_tree (identifier))))
398-
(string_literal))))
402+
arguments: (token_tree
403+
(identifier))))
404+
(string_literal
405+
(string_content)))))
399406

400407
================================================================================
401408
Tuple expressions
@@ -470,7 +477,8 @@ let u = game::User {name: "Joe", age: 35, score: 100_000};
470477
(field_initializer_list
471478
(field_initializer
472479
(field_identifier)
473-
(string_literal))
480+
(string_literal
481+
(string_content)))
474482
(field_initializer
475483
(field_identifier)
476484
(integer_literal))
@@ -615,7 +623,8 @@ if a && let b = || c || d && e {}
615623
(if_expression
616624
condition: (let_condition
617625
pattern: (tuple_pattern
618-
(string_literal)
626+
(string_literal
627+
(string_content))
619628
(identifier))
620629
value: (identifier))
621630
consequence: (block)))
@@ -625,7 +634,8 @@ if a && let b = || c || d && e {}
625634
(let_condition
626635
pattern: (tuple_struct_pattern
627636
type: (identifier)
628-
(string_literal))
637+
(string_literal
638+
(string_content)))
629639
value: (identifier))
630640
(identifier)
631641
(let_condition
@@ -675,7 +685,8 @@ while let ("Bacon", b) = dish {
675685
(while_expression
676686
(let_condition
677687
(tuple_pattern
678-
(string_literal)
688+
(string_literal
689+
(string_content))
679690
(identifier))
680691
(identifier))
681692
(block))))
@@ -718,11 +729,13 @@ let msg = match x {
718729
pattern: (match_pattern
719730
(integer_literal))
720731
value: (block
721-
(string_literal)))
732+
(string_literal
733+
(string_content))))
722734
(match_arm
723735
pattern: (match_pattern
724736
(integer_literal))
725-
value: (string_literal))
737+
value: (string_literal
738+
(string_content)))
726739
(match_arm
727740
pattern: (match_pattern
728741
(negative_literal
@@ -739,17 +752,20 @@ let msg = match x {
739752
(identifier)))
740753
pattern: (match_pattern
741754
(integer_literal))
742-
value: (string_literal))
755+
value: (string_literal
756+
(string_content)))
743757
(match_arm
744758
pattern: (match_pattern
745759
(macro_invocation
746760
macro: (identifier)
747761
(token_tree
748762
(integer_literal))))
749-
value: (string_literal))
763+
value: (string_literal
764+
(string_content)))
750765
(match_arm
751766
pattern: (match_pattern)
752-
value: (string_literal)))))
767+
value: (string_literal
768+
(string_content))))))
753769
(let_declaration
754770
pattern: (identifier)
755771
value: (match_expression
@@ -762,14 +778,16 @@ let msg = match x {
762778
(integer_literal)
763779
(integer_literal))
764780
(integer_literal)))
765-
value: (string_literal))
781+
value: (string_literal
782+
(string_content)))
766783
(match_arm
767784
pattern: (match_pattern
768785
(identifier)
769786
condition: (binary_expression
770787
left: (identifier)
771788
right: (integer_literal)))
772-
value: (string_literal))
789+
value: (string_literal
790+
(string_content)))
773791
(match_arm
774792
pattern: (match_pattern
775793
(identifier)
@@ -779,7 +797,8 @@ let msg = match x {
779797
value: (if_expression
780798
condition: (identifier)
781799
consequence: (block
782-
(string_literal))))
800+
(string_literal
801+
(string_content)))))
783802
(match_arm
784803
pattern: (match_pattern
785804
(identifier)
@@ -795,10 +814,12 @@ let msg = match x {
795814
type: (identifier)
796815
(identifier))
797816
value: (identifier))))
798-
value: (string_literal))
817+
value: (string_literal
818+
(string_content)))
799819
(match_arm
800820
pattern: (match_pattern)
801-
value: (string_literal))))))
821+
value: (string_literal
822+
(string_content)))))))
802823

803824
================================================================================
804825
While expressions

test/corpus/literals.txt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,42 @@ b"foo\nbar";
8888
(expression_statement
8989
(string_literal))
9090
(expression_statement
91-
(string_literal))
91+
(string_literal
92+
(string_content)))
9293
(expression_statement
93-
(string_literal))
94+
(string_literal
95+
(string_content)))
9496
(expression_statement
9597
(string_literal
96-
(escape_sequence)))
98+
(string_content)
99+
(escape_sequence)
100+
(string_content)))
97101
(expression_statement
98102
(string_literal
99-
(escape_sequence)))
103+
(string_content)
104+
(escape_sequence)
105+
(string_content)))
100106
(expression_statement
101107
(string_literal
102108
(escape_sequence)
109+
(string_content)
103110
(escape_sequence)))
104111
(expression_statement
105-
(string_literal))
112+
(string_literal
113+
(string_content)))
106114
(expression_statement
107115
(string_literal
116+
(string_content)
108117
(escape_sequence)
109-
(escape_sequence)))
118+
(escape_sequence)
119+
(string_content)))
110120
(expression_statement
111121
(string_literal
122+
(string_content)
123+
(escape_sequence)
124+
(string_content)
112125
(escape_sequence)
113-
(escape_sequence))))
126+
(string_content))))
114127

115128
================================================================================
116129
Raw string literals

test/corpus/macros.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,21 @@ a!($a $a:ident $($a);*);
114114
(expression_statement
115115
(macro_invocation
116116
(identifier)
117-
(token_tree (token_tree))))
117+
(token_tree
118+
(token_tree))))
118119
(expression_statement
119120
(macro_invocation
120121
(identifier)
121-
(token_tree (identifier))))
122+
(token_tree
123+
(identifier))))
122124
(expression_statement
123125
(macro_invocation
124126
(identifier)
125-
(token_tree (token_tree (token_tree (token_tree (identifier)))))))
127+
(token_tree
128+
(token_tree
129+
(token_tree
130+
(token_tree
131+
(identifier)))))))
126132
(expression_statement
127133
(macro_invocation
128134
(identifier)
@@ -198,7 +204,8 @@ macro_rules! empty [
198204
right: (token_tree
199205
(identifier)
200206
(token_tree
201-
(string_literal)))))
207+
(string_literal
208+
(string_content))))))
202209
(macro_definition
203210
name: (identifier)
204211
(macro_rule
@@ -217,7 +224,8 @@ macro_rules! empty [
217224
right: (token_tree
218225
(identifier)
219226
(token_tree
220-
(string_literal)
227+
(string_literal
228+
(string_content))
221229
(metavariable))))
222230
(macro_rule
223231
left: (token_tree_pattern
@@ -228,7 +236,8 @@ macro_rules! empty [
228236
right: (token_tree
229237
(identifier)
230238
(token_tree
231-
(string_literal)
239+
(string_literal
240+
(string_content))
232241
(metavariable)))))
233242
(macro_definition
234243
name: (identifier)

0 commit comments

Comments
 (0)