MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / parse_value

Function parse_value

nodedb-sql/src/parser/object_literal.rs:326–354  ·  view source on GitHub ↗
(chars: &[char], pos: &mut usize)

Source from the content-addressed store, hash-verified

324}
325
326fn 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)]
357mod tests {

Callers 2

parse_arrayFunction · 0.70
parse_objectFunction · 0.70

Calls 10

parse_stringFunction · 0.85
parse_objectFunction · 0.85
parse_numberFunction · 0.85
parse_identFunction · 0.85
to_stringMethod · 0.80
skip_wsFunction · 0.70
parse_arrayFunction · 0.70
lenMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected