From 24d20784b2bfa531b407f276a39d1901d2e045f9 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Sat, 5 Dec 2020 19:41:37 +0100 Subject: [PATCH] Fix infinite loop when parsing strings --- examples_out/out.js | 4 ++-- src/lexer/mod.rs | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples_out/out.js b/examples_out/out.js index 3c84eea..be3aad0 100644 --- a/examples_out/out.js +++ b/examples_out/out.js @@ -1,6 +1,6 @@ function main() { -return; +return "Hello World" } function fib() { } -main() \ No newline at end of file +console.log(main()) \ No newline at end of file diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index a1f563b..a693519 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -288,6 +288,11 @@ impl Cursor<'_> { loop { match self.first() { '"' | '\'' => break, + '\n' => panic!( + "String does not end on same line. At {}:{}", + self.pos().line, + self.pos().offset + ), _ => self.bump(), }; }