Cover empty file cases, deal with empty final line

main
Elnu 2 years ago
parent d957816ded
commit 4113accdaa

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

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