From 951ca55b5484470159339eb3eb065587fae9c3b2 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 20 Jun 2022 12:26:43 +0100 Subject: [PATCH] Add SQL Thing parsing functionality to external API --- lib/src/sql/parser.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/src/sql/parser.rs b/lib/src/sql/parser.rs index 31d36287..675aa9f7 100644 --- a/lib/src/sql/parser.rs +++ b/lib/src/sql/parser.rs @@ -1,7 +1,8 @@ use crate::err::Error; use crate::sql::error::Error::ParserError; use crate::sql::query::{query, Query}; -use crate::sql::value::{json as value, Value}; +use crate::sql::thing::Thing; +use crate::sql::value::Value; use nom::Err; use std::str; @@ -35,10 +36,40 @@ pub fn parse(input: &str) -> Result { } } +pub fn thing(input: &str) -> Result { + match input.trim().len() { + 0 => Err(Error::QueryEmpty), + _ => match super::thing::thing(input) { + Ok((_, query)) => Ok(query), + Err(Err::Error(e)) => match e { + ParserError(e) => { + let (s, l, c) = locate(input, e); + Err(Error::InvalidQuery { + line: l, + char: c, + sql: s.to_string(), + }) + } + }, + Err(Err::Failure(e)) => match e { + ParserError(e) => { + let (s, l, c) = locate(input, e); + Err(Error::InvalidQuery { + line: l, + char: c, + sql: s.to_string(), + }) + } + }, + _ => unreachable!(), + }, + } +} + pub fn json(input: &str) -> Result { match input.trim().len() { 0 => Err(Error::QueryEmpty), - _ => match value(input) { + _ => match super::value::json(input) { Ok((_, query)) => Ok(query), Err(Err::Error(e)) => match e { ParserError(e) => {