Enable parsing of thing records inside strings
This allows for thing records to be parsed within JSON strings.
This commit is contained in:
parent
0c86061086
commit
d0c37f4d66
2 changed files with 31 additions and 3 deletions
|
@ -4,11 +4,15 @@ use crate::sql::id::{id, Id};
|
|||
use crate::sql::ident::ident_raw;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use derive::Store;
|
||||
use nom::branch::alt;
|
||||
use nom::character::complete::char;
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
const SINGLE: char = '\'';
|
||||
const DOUBLE: char = '"';
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Deserialize, Store)]
|
||||
pub struct Thing {
|
||||
pub tb: String,
|
||||
|
@ -72,6 +76,15 @@ impl Serialize for Thing {
|
|||
}
|
||||
|
||||
pub fn thing(i: &str) -> IResult<&str, Thing> {
|
||||
let (i, v) = thing_raw(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn thing_raw(i: &str) -> IResult<&str, Thing> {
|
||||
alt((thing_normal, thing_single, thing_double))(i)
|
||||
}
|
||||
|
||||
fn thing_normal(i: &str) -> IResult<&str, Thing> {
|
||||
let (i, t) = ident_raw(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
let (i, v) = id(i)?;
|
||||
|
@ -84,6 +97,20 @@ pub fn thing(i: &str) -> IResult<&str, Thing> {
|
|||
))
|
||||
}
|
||||
|
||||
fn thing_single(i: &str) -> IResult<&str, Thing> {
|
||||
let (i, _) = char(SINGLE)(i)?;
|
||||
let (i, v) = thing_normal(i)?;
|
||||
let (i, _) = char(SINGLE)(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
fn thing_double(i: &str) -> IResult<&str, Thing> {
|
||||
let (i, _) = char(DOUBLE)(i)?;
|
||||
let (i, v) = thing_normal(i)?;
|
||||
let (i, _) = char(DOUBLE)(i)?;
|
||||
Ok((i, v))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
|
|
|
@ -1179,6 +1179,7 @@ pub fn single(i: &str) -> IResult<&str, Value> {
|
|||
map(datetime, Value::from),
|
||||
map(duration, Value::from),
|
||||
map(geometry, Value::from),
|
||||
map(thing, Value::from),
|
||||
map(unique, Value::from),
|
||||
map(number, Value::from),
|
||||
map(strand, Value::from),
|
||||
|
@ -1188,7 +1189,6 @@ pub fn single(i: &str) -> IResult<&str, Value> {
|
|||
map(regex, Value::from),
|
||||
map(model, Value::from),
|
||||
map(idiom, Value::from),
|
||||
map(thing, Value::from),
|
||||
))(i)
|
||||
}
|
||||
|
||||
|
@ -1204,6 +1204,8 @@ pub fn select(i: &str) -> IResult<&str, Value> {
|
|||
map(datetime, Value::from),
|
||||
map(duration, Value::from),
|
||||
map(geometry, Value::from),
|
||||
map(edges, Value::from),
|
||||
map(thing, Value::from),
|
||||
map(unique, Value::from),
|
||||
map(number, Value::from),
|
||||
map(strand, Value::from),
|
||||
|
@ -1212,8 +1214,6 @@ pub fn select(i: &str) -> IResult<&str, Value> {
|
|||
map(param, Value::from),
|
||||
map(regex, Value::from),
|
||||
map(model, Value::from),
|
||||
map(edges, Value::from),
|
||||
map(thing, Value::from),
|
||||
map(table, Value::from),
|
||||
))(i)
|
||||
}
|
||||
|
@ -1238,6 +1238,7 @@ pub fn json(i: &str) -> IResult<&str, Value> {
|
|||
map(datetime, Value::from),
|
||||
map(duration, Value::from),
|
||||
map(geometry, Value::from),
|
||||
map(thing, Value::from),
|
||||
map(unique, Value::from),
|
||||
map(number, Value::from),
|
||||
map(object, Value::from),
|
||||
|
|
Loading…
Reference in a new issue