From 4113accdaa72dca501908736c1bf6ecff3deabbb Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 20 May 2023 18:35:02 -0700 Subject: [PATCH] Cover empty file cases, deal with empty final line --- src/lib.rs | 5 ++++- src/rpy.pest | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0dfeb54..0e8fe86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,10 @@ pub fn parse(script: &str) -> Vec> { Rule::EOI => (), _ => unreachable!(), } - lines.push(tokens); + // TODO: For some a blank final line is always parsed + if tokens.len() > 0 { + lines.push(tokens); + } } lines } diff --git a/src/rpy.pest b/src/rpy.pest index 060253c..5600fa6 100644 --- a/src/rpy.pest +++ b/src/rpy.pest @@ -41,4 +41,4 @@ COMMENT = _{ "#" ~ char* } // lines are comprised of a statement line = { token+ } -file = { SOI ~ line ~ (NEWLINE+ ~ line)* ~ NEWLINE* ~ EOI } \ No newline at end of file +file = { SOI ~ (line ~ (NEWLINE+ ~ line)*)? ~ NEWLINE* ~ EOI } \ No newline at end of file