Skip to content

Commit 40a5aed

Browse files
committed
Update
1 parent ab09ef8 commit 40a5aed

File tree

3 files changed

+58
-44
lines changed

3 files changed

+58
-44
lines changed

crates/parser/parser/parser.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4466,6 +4466,7 @@ impl<'input> Parser<'input> {
44664466
let mut building_content_tag_name: Option<(String, Location)> = None;
44674467
let mut building_content: Vec<(String, Location)> = vec![];
44684468
let mut inside_code_block = false;
4469+
let mut backticks: Option<Regex> = None;
44694470

44704471
while i < line_count {
44714472
let line = &lines[i];
@@ -4479,8 +4480,9 @@ impl<'input> Parser<'input> {
44794480
&mut main_body,
44804481
&mut tags,
44814482
);
4482-
if regex_is_match!(r"^[\s\t]*```([^`]|$)", &tag_content) {
4483+
if let Some((_, new_backticks)) = regex_captures!(r"^[\s\t]*(```(?:`*|$))", &tag_content) {
44834484
inside_code_block = true;
4485+
backticks = Some(Regex::new(&(r"^[\s\t]*".to_owned() + &new_backticks.to_owned() + &r"(?:$)?".to_owned())).unwrap());
44844486
}
44854487
let tag_name_location = Location::with_offsets(self.compilation_unit(), line.location.first_offset() + tag_prefix.len() - 1, line.location.first_offset() + tag_prefix.len() + tag_name.len());
44864488
building_content_tag_name = Some((tag_name.into(), tag_name_location));
@@ -4498,8 +4500,15 @@ impl<'input> Parser<'input> {
44984500
building_content.clear();
44994501
}
45004502
} else {
4501-
if regex_is_match!(r"^[\s\t]*```([^`]|$)", &line.content) {
4502-
inside_code_block = !inside_code_block;
4503+
if inside_code_block {
4504+
if backticks.as_ref().unwrap().is_match(&line.content) {
4505+
inside_code_block = false;
4506+
}
4507+
} else {
4508+
if let Some((_, new_backticks)) = regex_captures!(r"^[\s\t]*(```(?:`*|$))", &line.content) {
4509+
inside_code_block = true;
4510+
backticks = Some(Regex::new(&(r"^[\s\t]*".to_owned() + &new_backticks.to_owned() + &r"([^`]|$)".to_owned())).unwrap());
4511+
}
45034512
}
45044513
building_content.push((line.content.clone(), line.location.clone()));
45054514
}

tests/parser/ASDoc.as

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/**
22
* Main body.
3+
*
4+
* `````
5+
* trace("hi");
6+
* `````
7+
*
38
* @copy C1#x
49
* @inheritDoc
510
* @see C1#x X description

tests/parser/ASDoc.tree

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
11
{
2-
"location": "7:1-24:2",
2+
"location": "12:1-29:2",
33
"packages": [],
44
"directives": [
55
{
66
"VariableDefinition": {
7-
"location": "7:1-7:6",
7+
"location": "12:1-12:6",
88
"asdoc": {
9-
"location": "1:1-6:4",
9+
"location": "1:1-11:4",
1010
"main_body": [
11-
"Main body.",
12-
"2:4-2:14"
11+
"Main body.\n\n`````\ntrace(\"hi\");\n`````",
12+
"2:4-6:9"
1313
],
1414
"tags": [
1515
[
1616
{
1717
"Copy": {
1818
"base": {
1919
"QualifiedIdentifier": {
20-
"location": "3:10-3:12",
20+
"location": "8:10-8:12",
2121
"attribute": false,
2222
"qualifier": null,
2323
"id": {
2424
"Id": [
2525
"C1",
26-
"3:10-3:12"
26+
"8:10-8:12"
2727
]
2828
}
2929
}
3030
},
3131
"instance_property": {
32-
"location": "3:13-3:14",
32+
"location": "8:13-8:14",
3333
"attribute": false,
3434
"qualifier": null,
3535
"id": {
3636
"Id": [
3737
"x",
38-
"3:13-3:14"
38+
"8:13-8:14"
3939
]
4040
}
4141
}
4242
}
4343
},
44-
"3:4-3:14"
44+
"8:4-8:14"
4545
],
4646
[
4747
"InheritDoc",
48-
"4:4-4:15"
48+
"9:4-9:15"
4949
],
5050
[
5151
{
5252
"See": {
5353
"reference": {
5454
"base": {
5555
"QualifiedIdentifier": {
56-
"location": "5:9-5:11",
56+
"location": "10:9-10:11",
5757
"attribute": false,
5858
"qualifier": null,
5959
"id": {
6060
"Id": [
6161
"C1",
62-
"5:9-5:11"
62+
"10:9-10:11"
6363
]
6464
}
6565
}
6666
},
6767
"instance_property": {
68-
"location": "5:12-5:13",
68+
"location": "10:12-10:13",
6969
"attribute": false,
7070
"qualifier": null,
7171
"id": {
7272
"Id": [
7373
"x",
74-
"5:12-5:13"
74+
"10:12-10:13"
7575
]
7676
}
7777
}
7878
},
7979
"display_text": "X description"
8080
}
8181
},
82-
"5:4-5:27"
82+
"10:4-10:27"
8383
]
8484
]
8585
},
8686
"attributes": [],
8787
"kind": [
8888
"Var",
89-
"7:1-7:4"
89+
"12:1-12:4"
9090
],
9191
"bindings": [
9292
{
9393
"destructuring": {
94-
"location": "7:5-7:6",
94+
"location": "12:5-12:6",
9595
"destructuring": {
9696
"QualifiedIdentifier": {
97-
"location": "7:5-7:6",
97+
"location": "12:5-12:6",
9898
"attribute": false,
9999
"qualifier": null,
100100
"id": {
101101
"Id": [
102102
"x",
103-
"7:5-7:6"
103+
"12:5-12:6"
104104
]
105105
}
106106
}
@@ -114,56 +114,56 @@
114114
},
115115
{
116116
"VariableDefinition": {
117-
"location": "12:1-18:6",
117+
"location": "17:1-23:6",
118118
"asdoc": {
119-
"location": "13:1-16:4",
119+
"location": "18:1-21:4",
120120
"main_body": [
121121
"N2. Lorem\nipsum.",
122-
"14:4-15:10"
122+
"19:4-20:10"
123123
],
124124
"tags": []
125125
},
126126
"attributes": [
127127
{
128128
"Metadata": {
129-
"location": "12:2-12:4",
129+
"location": "17:2-17:4",
130130
"asdoc": null,
131131
"name": [
132132
"N1",
133-
"12:2-12:4"
133+
"17:2-17:4"
134134
],
135135
"entries": null
136136
}
137137
},
138138
{
139139
"Metadata": {
140-
"location": "17:2-17:4",
140+
"location": "22:2-22:4",
141141
"asdoc": null,
142142
"name": [
143143
"N2",
144-
"17:2-17:4"
144+
"22:2-22:4"
145145
],
146146
"entries": null
147147
}
148148
}
149149
],
150150
"kind": [
151151
"Var",
152-
"18:1-18:4"
152+
"23:1-23:4"
153153
],
154154
"bindings": [
155155
{
156156
"destructuring": {
157-
"location": "18:5-18:6",
157+
"location": "23:5-23:6",
158158
"destructuring": {
159159
"QualifiedIdentifier": {
160-
"location": "18:5-18:6",
160+
"location": "23:5-23:6",
161161
"attribute": false,
162162
"qualifier": null,
163163
"id": {
164164
"Id": [
165165
"y",
166-
"18:5-18:6"
166+
"23:5-23:6"
167167
]
168168
}
169169
}
@@ -177,54 +177,54 @@
177177
},
178178
{
179179
"FunctionDefinition": {
180-
"location": "23:1-24:2",
180+
"location": "28:1-29:2",
181181
"asdoc": {
182-
"location": "20:1-22:4",
182+
"location": "25:1-27:4",
183183
"main_body": null,
184184
"tags": [
185185
[
186186
{
187187
"Throws": {
188188
"class_reference": {
189189
"QualifiedIdentifier": {
190-
"location": "21:12-21:23",
190+
"location": "26:12-26:23",
191191
"attribute": false,
192192
"qualifier": null,
193193
"id": {
194194
"Id": [
195195
"SyntaxError",
196-
"21:12-21:23"
196+
"26:12-26:23"
197197
]
198198
}
199199
}
200200
},
201201
"description": "If a syntax error occurs."
202202
}
203203
},
204-
"21:4-21:49"
204+
"26:4-26:49"
205205
]
206206
]
207207
},
208208
"attributes": [],
209209
"name": {
210210
"Identifier": [
211211
"m",
212-
"23:10-23:11"
212+
"28:10-28:11"
213213
]
214214
},
215215
"common": {
216-
"location": "23:11-24:2",
216+
"location": "28:11-29:2",
217217
"contains_yield": false,
218218
"contains_await": false,
219219
"signature": {
220-
"location": "23:11-23:13",
220+
"location": "28:11-28:13",
221+
"this_parameter": null,
221222
"parameters": [],
222223
"result_type": null
223224
},
224225
"body": {
225226
"Block": {
226-
"location": "23:14-24:2",
227-
"metadata": null,
227+
"location": "28:14-29:2",
228228
"directives": []
229229
}
230230
}

0 commit comments

Comments
 (0)