Skip to content

Commit

Permalink
stars work better
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelCourtney committed Jun 19, 2021
1 parent 2f8b169 commit bfd1f76
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
31 changes: 17 additions & 14 deletions src/parser/automata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ pub enum AutomatonCommand {
Victory,

/// time to die :)
Die
Die,

Fallthrough
}

impl Default for AutomatonCommand {
Expand All @@ -86,7 +88,7 @@ impl Default for AutomatonCommand {
pub enum Continuation {
PassDie,
PassAdvance,
Advance
Advance,
}

#[derive(Shrinkwrap)]
Expand All @@ -97,7 +99,8 @@ pub struct CommandResult<'a> {
pub new_recruits: TinyVec<[Rawtomaton<'a>; 4]>,
pub reactivated: TinyVec<[Rawtomaton<'a>; 4]>,
pub victorious: Option<Rawtomaton<'a>>,
pub remove: bool
pub remove: bool,
pub fallthrough: bool
}

impl<'a> Army<'a> {
Expand Down Expand Up @@ -125,11 +128,9 @@ impl<'a> Army<'a> {

let mut result = CommandResult::default();

for action in actions {
for action in &actions {
match action {
Advance => {
println!("\n advancing");
dbg!((**auto).route);
(**auto).state += 1;
}
Die => {
Expand All @@ -142,13 +143,13 @@ impl<'a> Army<'a> {
on_victory
} => {
let mut die = actions.contains(&AutomatonCommand::Die);
for i in 0..how_many {
let new = self.recruit(rule, route + i);
for i in 0..*how_many {
let new = self.recruit(*rule, route + i);
if die {
(**new).parent = Some((auto, on_victory));
(**new).parent = Some((auto, *on_victory));
die = false;
} else {
(**new).parent = Some((get_clone(), on_victory));
(**new).parent = Some((get_clone(), *on_victory));
}
result.new_recruits.push(new);
}
Expand All @@ -159,18 +160,16 @@ impl<'a> Army<'a> {
(**auto).state += 1;
loop {
match (**auto).parent {
Some((parent, cont)) => {
dbg!("\nadvancing parent");
dbg!((**parent).route);
Some((mut parent, cont)) => {
(**parent).state += 1;
if die {
(**parent).children.push(auto);
} else {
parent = self.alloc((**parent).clone()).into();
(**parent).children.push(self.alloc((**auto).clone()).into());
}
match cont {
Continuation::PassDie => {
dbg!("pass die");
auto = parent;
die = true;
}
Expand All @@ -192,6 +191,10 @@ impl<'a> Army<'a> {
}
}
}
Fallthrough => {
(**auto).state += 1;
result.fallthrough = true
}
}
}
result
Expand Down
15 changes: 14 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<I: ToString, O: Parser> Parse<O> for I {
}
if result.remove {
alive.remove(j);
} else {
} else if !result.fallthrough {
j += 1;
}
}
Expand Down Expand Up @@ -195,5 +195,18 @@ mod tests {
#[test]
fn other_rule() {
pass!("a aba a" DelegateGrammar::Start);
pass!("a abca a" DelegateGrammar::Start);
}

////// DOT & GREEDINESS

#[parser(MyLexer)]
enum DotGrammar {
Dot = "A B* C"
}

#[test]
fn dot_and_greedy() {
pass!("a b c" DotGrammar::Dot);
}
}

0 comments on commit bfd1f76

Please sign in to comment.