Read a single-quoted string literal, handling escaped quotes ('').
(input: &str, start: usize)
| 223 | |
| 224 | /// Read a single-quoted string literal, handling escaped quotes (''). |
| 225 | fn read_string_literal(input: &str, start: usize) -> Result<(String, usize), ProceduralError> { |
| 226 | let bytes = input.as_bytes(); |
| 227 | let mut i = start + 1; // skip opening quote |
| 228 | let mut result = String::new(); |
| 229 | |
| 230 | while i < bytes.len() { |
| 231 | if bytes[i] == b'\'' { |
| 232 | // Check for escaped quote (''). |
| 233 | if i + 1 < bytes.len() && bytes[i + 1] == b'\'' { |
| 234 | result.push('\''); |
| 235 | i += 2; |
| 236 | } else { |
| 237 | // End of string literal. |
| 238 | return Ok((result, i + 1)); |
| 239 | } |
| 240 | } else { |
| 241 | result.push(bytes[i] as char); |
| 242 | i += 1; |
| 243 | } |
| 244 | } |
| 245 | Err(ProceduralError::tokenize("unterminated string literal")) |
| 246 | } |
| 247 | |
| 248 | /// Check if the current word + next word form a two-word keyword. |
| 249 | /// Returns (keyword, position_after_second_word) if matched. |