From 2c97d65e977a1488eecbf3326e6eeeffa89c3c24 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 6 Jun 2022 00:35:44 +0100 Subject: [PATCH] Fix bug with graph traversal expression parsing --- lib/src/sql/graph.rs | 17 +++++++++++------ lib/src/sql/table.rs | 6 ++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/src/sql/graph.rs b/lib/src/sql/graph.rs index 39e21adc..05809c91 100644 --- a/lib/src/sql/graph.rs +++ b/lib/src/sql/graph.rs @@ -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, Option)> { - 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, Option)> { 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, Option)> { 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> { diff --git a/lib/src/sql/table.rs b/lib/src/sql/table.rs index c75aa13a..ca0bd7cd 100644 --- a/lib/src/sql/table.rs +++ b/lib/src/sql/table.rs @@ -13,6 +13,12 @@ use std::str; #[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize)] pub struct Tables(pub Vec); +impl From
for Tables { + fn from(v: Table) -> Self { + Tables(vec![v]) + } +} + impl Deref for Tables { type Target = Vec
; fn deref(&self) -> &Self::Target {