Skip to content

Commit

Permalink
fix(lexer): temporary fix for skipping first line
Browse files Browse the repository at this point in the history
  • Loading branch information
HorryPortier committed Jun 29, 2023
1 parent acdf6b7 commit 6ea438b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ impl Lexer {
}

pub fn parse<T: ToString>(&mut self, input: &T) -> Result<Vec<Token>, Error> {
self.input = input.to_string().into();
// BUG: format!("\n{}") is needed becuze it skips first line
self.input = format!("\n{}", input.to_string()).into();
// self.input = input.to_string().into();

let mut tokens: Vec<Token> = Vec::new();
self.next_token()?;
Expand Down Expand Up @@ -205,6 +207,7 @@ mod test {
";

let tokens = vec![
Token::EOL,
Token::Heading(1),
Token::WhiteSpace,
Token::Indent("Test".into()),
Expand All @@ -229,9 +232,18 @@ mod test {

let mut lexer = Lexer::new();


let res = lexer.parse::<&str>(&input)?;

println!("tokens: {:?}\nres {:?}\n", tokens, res);
let mut diff: Vec<(Token, Token)> = vec![];
for (i,t) in tokens.iter().enumerate() {
if *t != res[i] {
diff.push((t.clone(), res[i].clone()))
}
}

println!("DIFF {:?}", diff);
println!("TOKENS: {:?}\nres {:?}\n", tokens, res);
assert_eq!(tokens, res);

Ok(())
Expand Down

0 comments on commit 6ea438b

Please sign in to comment.