Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attributes for components and implement counter_fsm attribute #453

Merged
merged 13 commits into from
Sep 4, 2024
Prev Previous commit
Next Next commit
add better error message
  • Loading branch information
UnsignedByte committed Sep 4, 2024
commit 1d1124825e32a808a486d51c4042ca375405a82a
16 changes: 10 additions & 6 deletions crates/ast/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,18 @@ impl FilamentParser {
}

fn attr_bind(input: Node) -> ParseResult<Vec<ast::Attr>> {
Ok(match_nodes!(
input.into_children();
match_nodes!(
input.clone().into_children();
[identifier(name)] =>
vec![ast::Attr::Bool(ast::BoolAttr::from_str(name.as_ref()).unwrap_or_else(|_| panic!("Found unknown attribute flag \"{name}\"")))]
,
ast::BoolAttr::from_str(name.as_ref()).map(
|attr| vec![ast::Attr::Bool(attr)]).map_err(
|_| input.error(format!("Found unknown attribute flag \"{name}\""))),

[identifier(name), bitwidth(val)] =>
vec![ast::Attr::Num(ast::NumAttr::from_str(name.as_ref()).unwrap_or_else(|_| panic!("Found unknown numeric attribute \"{name}\"")), val)]
))
ast::NumAttr::from_str(name.as_ref()).map(
|attr| vec![ast::Attr::Num(attr, val)]).map_err(
|_| input.error(format!("Found unknown numeric attribute \"{name}\""))),
)
}

fn attributes(input: Node) -> ParseResult<Attributes> {
Expand Down
2 changes: 0 additions & 2 deletions crates/filament/src/ir_passes/fsm_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use fil_ir::TimeSub;
#[derive(Default)]
pub struct FSMAttributes;

impl FSMAttributes {}

impl Visitor for FSMAttributes {
fn name() -> &'static str {
"fsm-attributes"
Expand Down
13 changes: 9 additions & 4 deletions tests/errors/well-formed/invalid-attributes.expect
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---CODE---
101
1
---STDERR---
thread 'main' panicked at crates/ast/src/parser.rs:828:96:
Found unknown attribute flag "invalid_attribute"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: Failed to parse --> tests/errors/well-formed/invalid-attributes.fil:1:3
|
1 | #[invalid_attribute]
| ^---------------^
|
= Found unknown attribute flag "invalid_attribute":
Compilation failed with 1 errors.
Run with --show-models to generate assignments for failing constraints.