Skip to content

Commit

Permalink
Check for invalid parselet instances
Browse files Browse the repository at this point in the history
  • Loading branch information
phorward committed Mar 19, 2023
1 parent fe9a1bb commit 2b2d89d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This document describes upcoming changes to achieve with a specific version.
- [x] Implement iterators and `for...in`-syntax (#101)
- [ ] Implement generic parselets (#10, #105)
- [ ] New list syntax `[...]`, redefining sequence/`dict` syntax (#100)
- The character-class token syntax will be replaced by a `Char`-builtin
- The character-class token syntax was replaced by a `Char`-builtin
- List definition `list = []`
- Dict definition `dict = ()`
- Builtins `dict` and `list` should become obsolete, so variables can take their names
11 changes: 10 additions & 1 deletion src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,16 @@ fn traverse_node_value(compiler: &mut Compiler, node: &Dict) -> ImlValue {
);

//println!("parselet = {:#?}", ret);
return ret;
ret
}

"value_generic" => {
let children = List::from(&node["children"]);
for (i, item) in children.iter().enumerate() {
println!("{}: {:?}", i, item);
}

ImlValue::from(value!(void))
}

_ => unimplemented!("unhandled value node {}", emit),
Expand Down
31 changes: 31 additions & 0 deletions src/compiler/iml/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,37 @@ impl ImlOp {
unreachable!("Call to undefined symbol '{}' may not occur", name)
}
ImlTarget::Static(value) => {
if let ImlValue::Parselet {
parselet,
constants,
} = value
{
let parselet = parselet.borrow();

if !parselet.constants.is_empty() {
let mut required = Vec::new();

for (name, default) in &parselet.constants {
if default.is_none() && !constants.contains_key(name) {
required.push(name.to_string());
}
}

if !required.is_empty() {
linker.errors.push(Error::new(
offset.clone(),
format!(
"Missing generic configuration on call to '{}<{}>'",
value,
required.join(", ")
),
));

return 0;
}
}
}

let idx = linker.register(value);

match args {
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/iml/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use std::rc::Rc;
/** Compile-time values */
#[derive(Clone, PartialEq, Eq)]
pub(in crate::compiler) enum ImlValue {
Undefined(String), // Yet undefined value
Undefined(String), // Known but undefined value (used in generic parselets)
Value(RefValue), // Standard value object
Parselet {
// Parselet
parselet: Rc<RefCell<ImlParselet>>,
constants: HashMap<String, ImlValue>,
// Parselet instance
parselet: Rc<RefCell<ImlParselet>>, // The parselet definition
constants: HashMap<String, ImlValue>, // Optional parselet instance configuation
},
}

Expand Down

0 comments on commit 2b2d89d

Please sign in to comment.