Fix a bug in the parser where 'ns' would not be properly parsed as an alias for 'NAMESPACE' (#4242)
This commit is contained in:
parent
7b06e8b09a
commit
c60c365505
5 changed files with 47 additions and 17 deletions
|
@ -31,7 +31,9 @@ use crate::{
|
|||
impl Parser<'_> {
|
||||
pub async fn parse_define_stmt(&mut self, ctx: &mut Stk) -> ParseResult<DefineStatement> {
|
||||
match self.next().kind {
|
||||
t!("NAMESPACE") => self.parse_define_namespace().map(DefineStatement::Namespace),
|
||||
t!("NAMESPACE") | t!("ns") => {
|
||||
self.parse_define_namespace().map(DefineStatement::Namespace)
|
||||
}
|
||||
t!("DATABASE") => self.parse_define_database().map(DefineStatement::Database),
|
||||
t!("FUNCTION") => self.parse_define_function(ctx).await.map(DefineStatement::Function),
|
||||
t!("USER") => self.parse_define_user().map(DefineStatement::User),
|
||||
|
|
|
@ -402,19 +402,23 @@ impl Parser<'_> {
|
|||
/// # Parser State
|
||||
/// Expects `USE` to already be consumed.
|
||||
fn parse_use_stmt(&mut self) -> ParseResult<UseStatement> {
|
||||
let (ns, db) = if self.eat(t!("NAMESPACE")) {
|
||||
let ns = self.next_token_value::<Ident>()?.0;
|
||||
let db = self
|
||||
.eat(t!("DATABASE"))
|
||||
.then(|| self.next_token_value::<Ident>())
|
||||
.transpose()?
|
||||
.map(|x| x.0);
|
||||
(Some(ns), db)
|
||||
} else {
|
||||
expected!(self, t!("DATABASE"));
|
||||
|
||||
let db = self.next_token_value::<Ident>()?.0;
|
||||
(None, Some(db))
|
||||
let (ns, db) = match self.peek_kind() {
|
||||
t!("NAMESPACE") | t!("ns") => {
|
||||
self.pop_peek();
|
||||
let ns = self.next_token_value::<Ident>()?.0;
|
||||
let db = self
|
||||
.eat(t!("DATABASE"))
|
||||
.then(|| self.next_token_value::<Ident>())
|
||||
.transpose()?
|
||||
.map(|x| x.0);
|
||||
(Some(ns), db)
|
||||
}
|
||||
t!("DATABASE") => {
|
||||
self.pop_peek();
|
||||
let db = self.next_token_value::<Ident>()?;
|
||||
(None, Some(db.0))
|
||||
}
|
||||
x => unexpected!(self, x, "either DATABASE or NAMESPACE"),
|
||||
};
|
||||
|
||||
Ok(UseStatement {
|
||||
|
@ -449,7 +453,7 @@ impl Parser<'_> {
|
|||
expected!(self, t!("FOR"));
|
||||
let mut stmt = match self.next().kind {
|
||||
t!("ROOT") => InfoStatement::Root(false),
|
||||
t!("NAMESPACE") => InfoStatement::Ns(false),
|
||||
t!("NAMESPACE") | t!("ns") => InfoStatement::Ns(false),
|
||||
t!("DATABASE") => InfoStatement::Db(false),
|
||||
t!("TABLE") => {
|
||||
let ident = self.next_token_value()?;
|
||||
|
|
|
@ -316,7 +316,7 @@ impl Parser<'_> {
|
|||
/// Expects the next keyword to be a base.
|
||||
pub fn parse_base(&mut self, scope_allowed: bool) -> ParseResult<Base> {
|
||||
match self.next().kind {
|
||||
t!("NAMESPACE") => Ok(Base::Ns),
|
||||
t!("NAMESPACE") | t!("ns") => Ok(Base::Ns),
|
||||
t!("DATABASE") => Ok(Base::Db),
|
||||
t!("ROOT") => Ok(Base::Root),
|
||||
t!("SCOPE") => {
|
||||
|
|
|
@ -20,7 +20,7 @@ use crate::{
|
|||
impl Parser<'_> {
|
||||
pub fn parse_remove_stmt(&mut self) -> ParseResult<RemoveStatement> {
|
||||
let res = match self.next().kind {
|
||||
t!("NAMESPACE") => {
|
||||
t!("NAMESPACE") | t!("ns") => {
|
||||
let if_exists = if self.eat(t!("IF")) {
|
||||
expected!(self, t!("EXISTS"));
|
||||
true
|
||||
|
|
|
@ -1789,6 +1789,30 @@ fn parse_use() {
|
|||
assert_eq!(res, expect);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_use_lowercase() {
|
||||
let res = test_parse!(parse_stmt, r"use ns foo").unwrap();
|
||||
let expect = Statement::Use(UseStatement {
|
||||
ns: Some("foo".to_owned()),
|
||||
db: None,
|
||||
});
|
||||
assert_eq!(res, expect);
|
||||
|
||||
let res = test_parse!(parse_stmt, r"use db foo").unwrap();
|
||||
let expect = Statement::Use(UseStatement {
|
||||
ns: None,
|
||||
db: Some("foo".to_owned()),
|
||||
});
|
||||
assert_eq!(res, expect);
|
||||
|
||||
let res = test_parse!(parse_stmt, r"use ns bar db foo").unwrap();
|
||||
let expect = Statement::Use(UseStatement {
|
||||
ns: Some("bar".to_owned()),
|
||||
db: Some("foo".to_owned()),
|
||||
});
|
||||
assert_eq!(res, expect);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_value_stmt() {
|
||||
let res = test_parse!(parse_stmt, r"1s").unwrap();
|
||||
|
|
Loading…
Reference in a new issue