Skip to content

Commit d3ef512

Browse files
committed
fix(parser): fix incorrect span of instruction args when arg list is empty
1 parent a923194 commit d3ef512

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/parser.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ where
148148
.map_with(|token, e| (token, e.span()))
149149
.repeated()
150150
.collect()
151-
.map_with(|args, e| (args, e.span())),
151+
.map_with(|args: Vec<_>, e| {
152+
// Fix the span being wrong when there are no arguments (when sub-parser doesn't
153+
// consume input). SEE: <https://github.com/zesterer/chumsky/issues/870>
154+
let mut s: Span = e.span();
155+
if args.is_empty() {
156+
s.start = s.end;
157+
}
158+
(args, s)
159+
}),
152160
)
153161
.map(|(name, args)| Statement::Instruction(InstructionNode { name, args }))
154162
.labelled("instruction");
@@ -408,7 +416,17 @@ mod test {
408416
("name\n", empty.clone()),
409417
("name\r", empty.clone()),
410418
("name\r\n", empty.clone()),
419+
("name \n", empty.clone()),
411420
("name", empty),
421+
(
422+
"name a ",
423+
vec![instruction(
424+
vec![],
425+
("name", 0..4),
426+
(vec![(Token::Identifier("a".into()), 5..6)], 5..6),
427+
0..6,
428+
)],
429+
),
412430
(
413431
"name a\n",
414432
vec![instruction(

0 commit comments

Comments
 (0)