Cover empty file cases, deal with empty final line

This commit is contained in:
Elnu 2023-05-20 18:35:02 -07:00
parent d957816ded
commit 4113accdaa
2 changed files with 5 additions and 2 deletions

View file

@ -30,7 +30,10 @@ pub fn parse(script: &str) -> Vec<Vec<Token>> {
Rule::EOI => (),
_ => unreachable!(),
}
lines.push(tokens);
// TODO: For some a blank final line is always parsed
if tokens.len() > 0 {
lines.push(tokens);
}
}
lines
}

View file

@ -41,4 +41,4 @@ COMMENT = _{ "#" ~ char* }
// lines are comprised of a statement
line = { token+ }
file = { SOI ~ line ~ (NEWLINE+ ~ line)* ~ NEWLINE* ~ EOI }
file = { SOI ~ (line ~ (NEWLINE+ ~ line)*)? ~ NEWLINE* ~ EOI }