Skip to content

Commit

Permalink
First tranche of unit tests all passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Micah Dubinko authored and Micah Dubinko committed Aug 14, 2022
1 parent beb4ef3 commit ba027d6
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 102 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ path = "src/eb.rs"
name = "earleybird"

[dependencies]
multimap = "0.8.3"
quick-xml = "0.23.0"
smol_str = "0.1"
argh = "0.1"
Expand Down
Binary file added archive/Earley_trace.pdf
Binary file not shown.
32 changes: 13 additions & 19 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Grammar {
for (syn_name, builders) in rb.syn_rules {
for builder in builders {
let syn_branching_rule = self.definitions.entry(syn_name.clone())
.or_insert(BranchingRule::new(Mark::Hidden));
.or_insert(BranchingRule::new(Mark::Skip));
syn_branching_rule.add_alt_branch(Rule::new(builder.terms));
}
}
Expand Down Expand Up @@ -112,25 +112,25 @@ impl BranchingRule {
}
}

/// Representation of marks on rules or terms.
/// Representation of marks on rules or terms. These get used everywhere, so the varient names are kept short
/// @ for attribute
/// - for hidden
/// ^ for visible (default)
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Mark {
Default,
Visible,
Hidden,
Attrib,
Viz,
Skip,
Attr,
}

impl fmt::Display for Mark {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Mark::Default => write!(f, ""),
Mark::Visible => write!(f, "^"),
Mark::Hidden => write!(f, "-"),
Mark::Attrib => write!(f, "@"),
Mark::Viz => write!(f, "^"),
Mark::Skip => write!(f, "-"),
Mark::Attr => write!(f, "@"),
}
}
}
Expand Down Expand Up @@ -317,7 +317,7 @@ impl RuleBuilder {
self = self.syn_rule(f_option, Rule::build()); // empty
self = self.syn_rule(f_option, sub);
// 2 insert newly created nt into sequence under construction
self.nt_mark(f_option, Mark::Hidden)
self.nt_mark(f_option, Mark::Skip)
}

/// f* ⇒ f-star
Expand All @@ -328,7 +328,7 @@ impl RuleBuilder {
let f_star: &str = &self.mint_internal_id("f-star");
self = self.syn_rule(f_star, Rule::build().opt(Rule::build().expr(sub).nt(f_star)));
// 2 insert newly-created nt into sequence under construction
self.nt_mark(f_star, Mark::Hidden)
self.nt_mark(f_star, Mark::Skip)
}

/// f+ ⇒ f-plus
Expand All @@ -339,7 +339,7 @@ impl RuleBuilder {
let f_plus: &str = &self.mint_internal_id("f-plus");
self = self.syn_rule(f_plus, Rule::build().expr(sub).repeat0(Rule::build().nt(f_plus)));
// 2 insert newly-created nt into sequence under construction
self.nt_mark(f_plus, Mark::Hidden)
self.nt_mark(f_plus, Mark::Skip)
}

/// f++sep ⇒ f-plus-sep
Expand All @@ -351,7 +351,7 @@ impl RuleBuilder {
let f_plus_sep: &str = &self.mint_internal_id("f-plus-sep");
self = self.syn_rule(f_plus_sep, Rule::build().expr(sub1.clone()).repeat0(Rule::build().expr(sub2).expr(sub1)));
// 2 insert newly-created nt into sequence under construction
self.nt_mark(f_plus_sep, Mark::Hidden)
self.nt_mark(f_plus_sep, Mark::Skip)
}

/// f**sep ⇒ f-star-sep
Expand All @@ -363,7 +363,7 @@ impl RuleBuilder {
let f_star_sep: &str = &self.mint_internal_id("f-star-sep");
self = self.syn_rule(f_star_sep, Rule::build().opt( Rule::build().repeat1_sep(sub1, sub2)));
// 2 insert newly-created nt into sequence under construction
self.nt_mark(f_star_sep, Mark::Hidden)
self.nt_mark(f_star_sep, Mark::Skip)
}

/// internal identifier for synthesized rules
Expand All @@ -376,10 +376,4 @@ impl RuleBuilder {
}
}

// empty contents into new TermList
//pub fn get(&mut self) -> Rule {
// let tl = Rule::new(self.terms);
// tl
//}

}
6 changes: 3 additions & 3 deletions src/ixml_grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub fn grammar() -> Grammar {
.opt(Rule::build().nt("mark").nt("s"))
.nt("name")
.nt("s")
.lit_mark('=', Mark::Hidden) // TODO: choice here
.lit_mark('=', Mark::Skip) // TODO: choice here
.nt("s")
.nt_mark("alts", Mark::Hidden)
.lit_mark('.', Mark::Hidden) );
.nt_mark("alts", Mark::Skip)
.lit_mark('.', Mark::Skip) );
/*
// alts: alt++(-[";|"], s).
let alt_plus_plus_semi_or_vbar = g.add_repeat1_sep(alt, _semicolon_or_vbar);
Expand Down
Loading

0 comments on commit ba027d6

Please sign in to comment.