(chars: &[char], pos: &mut usize)
| 324 | } |
| 325 | |
| 326 | fn parse_value(chars: &[char], pos: &mut usize) -> Result<Value, SqlError> { |
| 327 | skip_ws(chars, pos); |
| 328 | if *pos >= chars.len() { |
| 329 | return Err(SqlError::Parse { |
| 330 | detail: "unexpected end of input while parsing value".to_string(), |
| 331 | }); |
| 332 | } |
| 333 | match chars[*pos] { |
| 334 | '\'' => parse_string(chars, pos).map(Value::String), |
| 335 | '{' => parse_object(chars, pos).map(Value::Object), |
| 336 | '[' => parse_array(chars, pos).map(Value::Array), |
| 337 | '-' | '0'..='9' => parse_number(chars, pos), |
| 338 | _ => { |
| 339 | // bare word: true / false / null / identifier |
| 340 | let word = parse_ident(chars, pos); |
| 341 | match word.to_lowercase().as_str() { |
| 342 | "true" => Ok(Value::Bool(true)), |
| 343 | "false" => Ok(Value::Bool(false)), |
| 344 | "null" => Ok(Value::Null), |
| 345 | _ if word.is_empty() => Err(SqlError::Parse { |
| 346 | detail: format!("unexpected character '{}' at position {pos}", chars[*pos]), |
| 347 | }), |
| 348 | _ => Err(SqlError::Parse { |
| 349 | detail: format!("unknown bare word: '{word}'"), |
| 350 | }), |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | #[cfg(test)] |
| 357 | mod tests { |
no test coverage detected