Error on extra args

next
Sayan Nandan 2 years ago
parent b78258289c
commit c074656c7a
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -246,10 +246,17 @@ impl<'a> Compiler<'a> {
impl<'a> Compiler<'a> {
#[inline(always)]
#[cfg(test)]
/// Compile the given BlueQL source
pub fn compile(src: &'a [u8]) -> LangResult<Life<'a, Statement>> {
Self::compile_with_extra(src, 0)
}
#[inline(always)]
/// Compile the given BlueQL source with optionally supplied extra arguments
/// HACK: Just helps us omit an additional check
pub fn compile_with_extra(src: &'a [u8], len: usize) -> LangResult<Life<'a, Statement>> {
let tokens = Lexer::lex(src)?;
Self::new(&tokens).eval().map(Life::new)
Self::new(&tokens).eval(len).map(Life::new)
}
#[inline(always)]
pub const fn new(tokens: &[Token]) -> Self {
@ -263,7 +270,7 @@ impl<'a> Compiler<'a> {
}
#[inline(always)]
/// The inner eval method
fn eval(&mut self) -> LangResult<Statement> {
fn eval(&mut self, extra_len: usize) -> LangResult<Statement> {
let stmt = match self.next() {
Some(tok) => match tok {
Token::Keyword(Keyword::Create) => self.parse_create0(),
@ -274,7 +281,7 @@ impl<'a> Compiler<'a> {
},
None => Err(LangError::UnexpectedEOF),
};
if compiler::likely(self.remaining() == 0) {
if compiler::likely(self.remaining() == 0 && extra_len == 0) {
stmt
} else {
Err(LangError::InvalidSyntax)

@ -41,13 +41,15 @@ pub async fn execute<'a, P, Strm, T>(
handle: &'a mut Corestore,
con: &'a mut T,
maybe_statement: &[u8],
extra: usize,
) -> ActionResult<()>
where
P: ProtocolSpec,
T: ClientConnection<P, Strm>,
Strm: Stream,
{
let statement = error::map_ql_err_to_resp::<StatementLT, P>(blueql::compile(maybe_statement))?;
let statement =
error::map_ql_err_to_resp::<StatementLT, P>(blueql::compile(maybe_statement, extra))?;
let system_health_okay = registry::state_okay();
let result = match statement.as_ref() {
Statement::Use(entity) => handle.swap_entity(entity),

@ -45,8 +45,8 @@ use core::{mem, slice};
#[allow(clippy::needless_lifetimes)]
#[inline(always)]
pub fn compile<'a>(src: &'a [u8]) -> LangResult<Life<'a, Statement>> {
Compiler::compile(src)
pub fn compile<'a>(src: &'a [u8], extra: usize) -> LangResult<Life<'a, Statement>> {
Compiler::compile_with_extra(src, extra)
}
#[cfg_attr(not(test), derive(Debug))]

@ -64,7 +64,7 @@ macro_rules! gen_constants_and_matches {
tags::$action2 => $fns2.await?,
)*
_ => {
blueql::execute($db, $con, first_slice).await?;
blueql::execute($db, $con, first_slice, $buf.len()).await?;
}
}
};

@ -128,3 +128,14 @@ mod sys {
)
}
}
use skytable::{query, Element, RespCode};
#[sky_macros::dbtest_func]
async fn blueql_extra_args() {
runeq!(
con,
query!("use default.default", "extra useless arg"),
Element::RespCode(RespCode::ErrorString("bql-invalid-syntax".into()))
);
}

Loading…
Cancel
Save