Fix bug with graph traversal expression parsing

This commit is contained in:
Tobie Morgan Hitchcock 2022-06-06 00:35:44 +01:00
parent 91a859f6b0
commit 2c97d65e97
2 changed files with 17 additions and 6 deletions

View file

@ -2,7 +2,7 @@ use crate::sql::comment::mightbespace;
use crate::sql::comment::shouldbespace;
use crate::sql::error::IResult;
use crate::sql::idiom::{idiom, Idiom};
use crate::sql::table::{tables, Tables};
use crate::sql::table::{table, tables, Tables};
use crate::sql::value::{value, Value};
use nom::branch::alt;
use nom::bytes::complete::tag_no_case;
@ -119,14 +119,14 @@ fn graph_both(i: &str) -> IResult<&str, Graph> {
}
fn simple(i: &str) -> IResult<&str, (Tables, Option<Value>, Option<Idiom>)> {
let (i, w) = what(i)?;
let (i, w) = alt((any, single))(i)?;
Ok((i, (w, None, None)))
}
fn custom(i: &str) -> IResult<&str, (Tables, Option<Value>, Option<Idiom>)> {
let (i, _) = char('(')(i)?;
let (i, _) = mightbespace(i)?;
let (i, w) = what(i)?;
let (i, w) = alt((any, multi))(i)?;
let (i, c) = opt(cond)(i)?;
let (i, a) = opt(alias)(i)?;
let (i, _) = mightbespace(i)?;
@ -134,9 +134,14 @@ fn custom(i: &str) -> IResult<&str, (Tables, Option<Value>, Option<Idiom>)> {
Ok((i, (w, c, a)))
}
fn what(i: &str) -> IResult<&str, Tables> {
let (i, v) = alt((any, tables))(i)?;
Ok((i, v))
fn single(i: &str) -> IResult<&str, Tables> {
let (i, v) = table(i)?;
Ok((i, Tables::from(v)))
}
fn multi(i: &str) -> IResult<&str, Tables> {
let (i, v) = tables(i)?;
Ok((i, Tables::from(v)))
}
fn any(i: &str) -> IResult<&str, Tables> {

View file

@ -13,6 +13,12 @@ use std::str;
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Tables(pub Vec<Table>);
impl From<Table> for Tables {
fn from(v: Table) -> Self {
Tables(vec![v])
}
}
impl Deref for Tables {
type Target = Vec<Table>;
fn deref(&self) -> &Self::Target {