Skip to content

Commit

Permalink
Fix the infinite loop, lexing back to prev state #52
Browse files Browse the repository at this point in the history
  • Loading branch information
mverleg committed Jun 18, 2018
1 parent ba3acda commit 0195c7a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/mango/lexing/code_lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,16 @@ impl SubLexer for CodeLexer {
panic!("Do not know how to proceed with parsing")
}
EOF() => {
// TODO: also dedent and end statement here
if self.indent <= 0 {
return SubLexerResult::End;
}
// TODO: currently the EndStatement is only made if the file stops on an indented line
let mut tokens = vec![Tokens::EndStatement(EndStatementToken::new_end_line())];
for _ in 0..self.indent {
// This line is dedented, make end tokens.
tokens.push(Tokens::EndBlock(EndBlockToken::new(true, false)));
}
self.indent = 0;
SubLexerResult::Result(tokens)
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/mango/token/collect/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ mod tests {

#[test]
fn test_tokens_size() {
assert!(size_of::<Tokens>() < 32);
assert!(size_of::<Tokens>() < 32, size_of::<Tokens>());
}
}
6 changes: 2 additions & 4 deletions src/mango/util/strslice/char_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ impl<'a> CharOps for &'a str {

impl CharOps for String {
fn without_char(&self, strip: &char) -> String {
println!("String.without_char");
(&self).without_char(strip)
self.chars().filter(|chr| chr != strip).collect()
}

fn char_len(&self) -> usize {
println!("String.char_len");
(&self).char_len()
self.chars().count()
}
}

0 comments on commit 0195c7a

Please sign in to comment.