Skip to content

Commit

Permalink
I have no idea what this does, but it works, and that's all that matt…
Browse files Browse the repository at this point in the history
…ers.
  • Loading branch information
elenakrittik committed Apr 9, 2024
1 parent 142788e commit 148b6a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
6 changes: 1 addition & 5 deletions logos-codegen/src/generator/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ pub struct Context {
}

impl Context {
pub fn can_backtrack(&self) -> bool {
self.backtrack.is_some()
}

pub fn switch(&mut self, miss: Option<NodeId>) -> Option<TokenStream> {
self.backtrack = Some(miss?);
self.bump()
None
}

pub const fn advance(self, n: usize) -> Self {
Expand Down
13 changes: 4 additions & 9 deletions logos-codegen/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,14 @@ impl<'a> Generator<'a> {
let meta = &self.meta[id];
let enters_loop = !meta.loop_entry_from.is_empty();

let bump = if enters_loop || !ctx.can_backtrack() {
ctx.switch(self.graph[id].miss())
ctx.switch(self.graph[id].miss());

let bump = if enters_loop || meta.min_read == 0 {
ctx.bump()
} else {
None
};

let bump = match (bump, enters_loop, meta.min_read) {
(Some(t), _, _) => Some(t),
(None, true, _) => ctx.bump(),
(None, false, 0) => ctx.bump(),
(None, false, _) => None,
};

if meta.min_read == 0 || ctx.remainder() < meta.min_read {
ctx.wipe();
}
Expand Down

0 comments on commit 148b6a0

Please sign in to comment.