Handle else block without body (#155)

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2024-02-22 21:04:20 -08:00
committed by GitHub
parent 10f2caf0c0
commit f51731e584
2 changed files with 33 additions and 1 deletions

View File

@@ -1426,7 +1426,21 @@ impl<'source> Parser<'source> {
"expected assignment or query after `else`",
));
}
_ => break,
_ => {
let mut query_span = span.clone();
query_span.end = query_span.start;
let query = Ref::new(Query {
span: query_span,
stmts: vec![],
});
span.end = self.end;
bodies.push(RuleBody {
span,
assign,
query,
});
break;
}
}
}
Ok(())

View File

@@ -0,0 +1,18 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: else without body
data: {}
modules:
- |
package test
x = 4 {
false
} else = 5
y = 6
query: data.test
want_result:
x: 5
y: 6