cenotelie / hime

Apache License 2.0
27 stars 4 forks source link

Tree felling for SPPF #97

Open stevefan1999-personal opened 1 year ago

stevefan1999-personal commented 1 year ago

For #96, we need to delete invalid tree in case if current node is illegal for now and obviously in the future (hence felling a tree -- We generate a bunch of spanning trees from SPPF and then we fell the ones that are illegal)

stevefan1999-personal commented 1 year ago

API design draft:

pub fn visit_sppf_version_node(node: SppfNodeVersion, visitor: &Box<dyn SppfVisitor>) -> Result<(), Error>

pub fn visit_sppf_node(node: SppfNode, visitor: &Box<dyn SppfVisitor>, mut universes: Vec<Result<Box<dyn SppfVisitor>, Error>>)

pub fn visit_sppf(result: &ParseResult<SppfImpl>, visitor: &Box<dyn SppfVisitor>) -> Vec<Result<Box<dyn SppfVisitor>, Error>>

/// SPPF Visitor interface
#[allow(unused_variables)]
pub trait SppfVisitor: DynClone {
    // Same for variables and virtualls
    fn on_terminal_identifier(&self, node: &SppfNodeVersion) -> Result<(), Error> {}

visit_sppf_version_node verifies if the action is valid or not

visit_sppf_node will fork visitor on each node version, calls visit_sppf_version_node and push back the visitor to universes if the result is not error (otherwise drop the visitor and push error instead)

visit_sppf initialize universes and return all possible results. 

Technically speaking, if there are more than 2 results in visit_sppf, then the whole program must be ambiguously defined as well (both syntactically and semantically).

TODO:

  1. Take care about any potential edge case for visit_sppf_node (1 version case is not defined?)
  2. Ergonomics