-
Notifications
You must be signed in to change notification settings - Fork 1
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
Recursive formats #100
base: main
Are you sure you want to change the base?
Recursive formats #100
Conversation
f218a7d
to
6decc60
Compare
@@ -1288,6 +1341,93 @@ impl Format { | |||
} | |||
MatchTree::build(module, &fs, Rc::new(Next::Empty)).is_none() | |||
} | |||
|
|||
fn recursion_check(&self, module: &FormatModule, format_ref: FormatRef) -> Result<bool, ()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method name recursion_check
and the return value do not have an intuitive semantics as far as what each possible return value of Ok(true)
, Ok(false)
, and Err(())
might signify. Either a bespoke enum, a doc-comment, or a rename of the method would make things clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more complex type might be useful than a simple enum if we want to capture more information than ternary classification of the form 'yes'/'no'/'failure'
// Allomorph of Option representing the possibly-unknown/unknowable answer to a question
pub enum Questionable<T> {
Known(T), // can be resolved consistently without external context or runtime information
Unknown // cannot be resolved in the absence of runtime information, missing context, or complex logic
}
// For possible branches, alternations, variable or dynamic formats, represents under what conditions a particular property is true
pub enum Consistency {
Always,
Never,
Sometimes, // Definitely not 'Never', strongly suggests not 'Always'
}
pub struct RecursionDiagnostic {
is_auto_recursive: Questionable<bool>, // indicates whether there is a verbatim reference back to the format in question embedded in its definition
is_cyclic: Questionable<bool>, // indicates whether any evaluation of the format in question will form a cycle back to itself, even if not directly (e.g. through mutual recursion)
will_advance_offset: Questionable<Consistency>, // indicates whether a successful decode of the format in question will always result in the offset being advanced by at least one byte
accepts_end_of_input: Questionable<bool>, // Indicates whether, if there was no input left to consume, whether the format would potentially yield a viable parse
}
/* appropriate methods to combine Diagnostics across branches and terms */
No description provided.