From 7d2fe517092ac76cf2a104f8cedb861006625bc2 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 8 Jun 2023 17:13:45 -0700 Subject: [PATCH] account for comment delimiters in strings --- src/lex.rs | 4 ++++ tests/test_lex.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/lex.rs b/src/lex.rs index 73ddc4f..b42490e 100644 --- a/src/lex.rs +++ b/src/lex.rs @@ -143,6 +143,10 @@ fn process(document: &String) -> Result, String> { } // eat the whole line '#' | ';' => { + if is_str { + token.push(c); + continue; + } ign = true; delim_stack.push('\n'); } diff --git a/tests/test_lex.rs b/tests/test_lex.rs index 61ff340..e761841 100644 --- a/tests/test_lex.rs +++ b/tests/test_lex.rs @@ -32,6 +32,12 @@ mod lex_tests { assert_eq!(lex(&document).unwrap().to_string(), document); } + #[test] + fn test_comment_delim_in_str() { + let document = String::from("('#')"); + assert_eq!(lex(&document).unwrap().to_string(), document); + } + #[test] fn test_empty_string() { let document = String::from("('')");