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

Recursive formats #100

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Recursive formats #100

wants to merge 4 commits into from

Conversation

mikeday
Copy link
Contributor

@mikeday mikeday commented Nov 6, 2023

No description provided.

@@ -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, ()> {
Copy link
Contributor

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.

Copy link
Contributor

@archaephyrryx archaephyrryx Nov 9, 2023

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 */

@mikeday mikeday marked this pull request as draft November 15, 2023 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants