Skip to content

Commit 2414acf

Browse files
committed
Fix empty file parsing
Pointer::start was modified to store line without trailing whitespaces. So we need extra step to check if the file isn't empty during token recognization.
1 parent 9b40fb4 commit 2414acf

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/lexer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ impl Lexer {
244244
/// character at end, so we must keep calling `next_line` until a non-empty
245245
/// `self.line` is returned.
246246
pub(crate) fn next_token(&mut self) -> Result<Option<Token>> {
247+
if self.buffer.is_empty() {
248+
self.token = None;
249+
return Ok(self.token);
250+
}
251+
247252
// Skip all leading whitespaces and trailing newlines.
248253
while self.buffer[self.ptr.current].is_ascii_whitespace() {
249254
self.ptr.current += 1;

tests/test_empty.ql

Whitespace-only changes.

tests/tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ fn test_ast_gen() -> Result<(), Box<dyn std::error::Error>> {
292292
|_ mix5: float64 = (1 >= w: float64)
293293
|_ (a0: float64 + (a1: float64 + (a2: float64 + a3: float64)))
294294
295+
");
296+
297+
test!("tests/test_empty.ql",
298+
"|_ test_empty // @test_empty.ql:1:1
295299
");
296300

297301
test!("examples/toss.ql",

0 commit comments

Comments
 (0)