Browse Source

Don't allow quotes inside string

main
Dylan Baker 3 years ago
parent
commit
858292a377
1 changed files with 12 additions and 1 deletions
  1. 12
    1
      src/lexer.rs

+ 12
- 1
src/lexer.rs View File

@@ -22,7 +22,7 @@ impl Matcher {
22 22
 lazy_static! {
23 23
     static ref WHITESPACE_REGEX: Regex = Regex::new(r"\s").unwrap();
24 24
     static ref MATCHERS: Vec<Matcher> = vec![
25
-        Matcher::new(r#"^"(.*)""#, TokenType::String),
25
+        Matcher::new(r#"^"([^"]*)""#, TokenType::String),
26 26
         Matcher::new(r#"(?i)^SELECT"#, TokenType::Select),
27 27
         Matcher::new(r#"(?i)^FROM"#, TokenType::From),
28 28
         Matcher::new(r#"(?i)^WHERE"#, TokenType::Where),
@@ -91,6 +91,17 @@ mod tests {
91 91
         )
92 92
     }
93 93
 
94
+    #[test]
95
+    fn it_scans_two_strings() {
96
+        assert_eq!(
97
+            scan("\"hello\"  \"world\"").unwrap(),
98
+            vec![
99
+                Token::new(TokenType::String, "hello"),
100
+                Token::new(TokenType::String, "world"),
101
+            ]
102
+        )
103
+    }
104
+
94 105
     #[test]
95 106
     fn it_scans_uppercase_keywords() {
96 107
         assert_eq!(

Loading…
Cancel
Save