Skip to content

Commit 9d65db2

Browse files
updates
1 parent 3ebf698 commit 9d65db2

File tree

21 files changed

+998
-6
lines changed

21 files changed

+998
-6
lines changed

crates/djls-template-ast/src/parser.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl Parser {
162162
bits,
163163
children: Some(branch_children),
164164
span: branch_span,
165-
tag_span: tag_span.clone(),
165+
tag_span,
166166
});
167167
}
168168
let closing_token = self.peek_previous()?;
@@ -171,7 +171,6 @@ impl Parser {
171171
_ => 0,
172172
};
173173
total_length = (closing_token.start().unwrap_or(0) + closing_content)
174-
as usize
175174
- start_pos as usize;
176175
children.push(Node::Block {
177176
block_type: BlockType::Closing,
@@ -182,7 +181,7 @@ impl Parser {
182181
closing_token.start().unwrap_or(0) as u32,
183182
closing_content as u16,
184183
),
185-
tag_span: tag_span.clone(),
184+
tag_span,
186185
});
187186
found_closing_tag = true;
188187
break;
@@ -199,7 +198,7 @@ impl Parser {
199198
bits,
200199
children: Some(branch_children),
201200
span: branch_span,
202-
tag_span: tag_span.clone(),
201+
tag_span,
203202
});
204203
}
205204
// Create new branch node
@@ -227,7 +226,7 @@ impl Parser {
227226
bits: bits.clone(),
228227
children: Some(children.clone()),
229228
span: Span::new(start_pos, total_length as u16),
230-
tag_span: tag_span.clone(),
229+
tag_span,
231230
};
232231
return Err(ParserError::Ast(AstError::UnexpectedTag(tag), Some(node)));
233232
}
@@ -268,6 +267,9 @@ impl Parser {
268267
let parts: Vec<&str> = s.split('|').collect();
269268
let bits: Vec<String> = parts[0].trim().split('.').map(String::from).collect();
270269

270+
// Track position in the string for filter spans
271+
let mut current_pos = parts[0].len() + 1; // +1 for the pipe
272+
271273
let filters: Vec<DjangoFilter> = parts[1..]
272274
.iter()
273275
.map(|filter_str| {
@@ -284,7 +286,11 @@ impl Parser {
284286
Vec::new()
285287
};
286288

287-
DjangoFilter::new(name, arguments)
289+
let filter_span =
290+
Span::new(start_pos + current_pos as u32, filter_str.len() as u16);
291+
current_pos += filter_str.len() + 1; // +1 for the pipe
292+
293+
DjangoFilter::new(name, arguments, filter_span)
288294
})
289295
.collect();
290296

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
source: crates/djls-template-ast/src/parser.rs
3+
assertion_line: 605
4+
expression: ast
5+
snapshot_kind: text
6+
---
7+
nodes:
8+
- Text:
9+
content: "<!-- HTML comment -->"
10+
span:
11+
start: 0
12+
length: 21
13+
- Comment:
14+
content: Django comment
15+
span:
16+
start: 21
17+
length: 18
18+
line_offsets: []
19+
errors: []
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
source: crates/djls-template-ast/src/parser.rs
3+
assertion_line: 524
4+
expression: ast
5+
snapshot_kind: text
6+
---
7+
nodes:
8+
- Block:
9+
block_type: Standard
10+
name: if
11+
bits:
12+
- if
13+
- x
14+
- ">"
15+
- "0"
16+
children:
17+
- Text:
18+
content: Positive
19+
span:
20+
start: 14
21+
length: 8
22+
- Block:
23+
block_type: Branch
24+
name: elif
25+
bits:
26+
- x
27+
- "<"
28+
- "0"
29+
children:
30+
- Text:
31+
content: Negative
32+
span:
33+
start: 38
34+
length: 8
35+
span:
36+
start: 0
37+
length: 8
38+
tag_span:
39+
start: 0
40+
length: 8
41+
- Block:
42+
block_type: Branch
43+
name: else
44+
bits: []
45+
children:
46+
- Text:
47+
content: Zero
48+
span:
49+
start: 56
50+
length: 4
51+
span:
52+
start: 0
53+
length: 8
54+
tag_span:
55+
start: 0
56+
length: 8
57+
- Block:
58+
block_type: Closing
59+
name: endif
60+
bits: []
61+
children: ~
62+
span:
63+
start: 60
64+
length: 5
65+
tag_span:
66+
start: 0
67+
length: 8
68+
span:
69+
start: 0
70+
length: 65
71+
tag_span:
72+
start: 0
73+
length: 8
74+
line_offsets: []
75+
errors: []
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
source: crates/djls-template-ast/src/parser.rs
3+
assertion_line: 515
4+
expression: ast
5+
snapshot_kind: text
6+
---
7+
nodes:
8+
- Block:
9+
block_type: Standard
10+
name: for
11+
bits:
12+
- for
13+
- item
14+
- in
15+
- items
16+
children:
17+
- Variable:
18+
bits:
19+
- item
20+
filters: []
21+
span:
22+
start: 23
23+
length: 4
24+
- Block:
25+
block_type: Branch
26+
name: empty
27+
bits: []
28+
children:
29+
- Text:
30+
content: No items
31+
span:
32+
start: 44
33+
length: 8
34+
span:
35+
start: 0
36+
length: 17
37+
tag_span:
38+
start: 0
39+
length: 17
40+
- Block:
41+
block_type: Closing
42+
name: endfor
43+
bits: []
44+
children: ~
45+
span:
46+
start: 52
47+
length: 6
48+
tag_span:
49+
start: 0
50+
length: 17
51+
span:
52+
start: 0
53+
length: 58
54+
tag_span:
55+
start: 0
56+
length: 17
57+
line_offsets: []
58+
errors: []
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
source: crates/djls-template-ast/src/parser.rs
3+
assertion_line: 506
4+
expression: ast
5+
snapshot_kind: text
6+
---
7+
nodes:
8+
- Block:
9+
block_type: Standard
10+
name: if
11+
bits:
12+
- if
13+
- user.is_authenticated
14+
children:
15+
- Text:
16+
content: Welcome
17+
span:
18+
start: 30
19+
length: 7
20+
- Block:
21+
block_type: Closing
22+
name: endif
23+
bits: []
24+
children: ~
25+
span:
26+
start: 37
27+
length: 5
28+
tag_span:
29+
start: 0
30+
length: 24
31+
span:
32+
start: 0
33+
length: 42
34+
tag_span:
35+
start: 0
36+
length: 24
37+
line_offsets: []
38+
errors: []
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: crates/djls-template-ast/src/parser.rs
3+
assertion_line: 488
4+
expression: ast
5+
snapshot_kind: text
6+
---
7+
nodes:
8+
- Variable:
9+
bits:
10+
- user
11+
- name
12+
filters:
13+
- name: title
14+
arguments: []
15+
span:
16+
start: 10
17+
length: 5
18+
span:
19+
start: 0
20+
length: 15
21+
line_offsets: []
22+
errors: []
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
source: crates/djls-template-ast/src/parser.rs
3+
assertion_line: 497
4+
expression: ast
5+
snapshot_kind: text
6+
---
7+
nodes:
8+
- Variable:
9+
bits:
10+
- value
11+
filters:
12+
- name: default
13+
arguments:
14+
- "'nothing'"
15+
span:
16+
start: 6
17+
length: 17
18+
- name: title
19+
arguments: []
20+
span:
21+
start: 24
22+
length: 5
23+
- name: upper
24+
arguments: []
25+
span:
26+
start: 30
27+
length: 5
28+
span:
29+
start: 0
30+
length: 35
31+
line_offsets: []
32+
errors: []

0 commit comments

Comments
 (0)