Allow :: module separators in custom function names

Closes #1775
This commit is contained in:
Tobie Morgan Hitchcock 2023-04-06 09:33:52 +01:00
parent 59c6087169
commit 8083eaf751
3 changed files with 14 additions and 3 deletions

View file

@ -18,7 +18,9 @@ use nom::branch::alt;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
use nom::bytes::complete::take_while1; use nom::bytes::complete::take_while1;
use nom::character::complete::char; use nom::character::complete::char;
use nom::combinator::recognize;
use nom::multi::separated_list0; use nom::multi::separated_list0;
use nom::multi::separated_list1;
use serde::ser::SerializeTupleVariant; use serde::ser::SerializeTupleVariant;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::cmp::Ordering; use std::cmp::Ordering;
@ -277,7 +279,8 @@ pub fn normal(i: &str) -> IResult<&str, Function> {
pub fn custom(i: &str) -> IResult<&str, Function> { pub fn custom(i: &str) -> IResult<&str, Function> {
let (i, _) = tag("fn::")(i)?; let (i, _) = tag("fn::")(i)?;
let (i, s) = take_while1(val_char)(i)?; let (i, s) = recognize(separated_list1(tag("::"), take_while1(val_char)))(i)?;
let (i, _) = mightbespace(i)?;
let (i, _) = char('(')(i)?; let (i, _) = char('(')(i)?;
let (i, _) = mightbespace(i)?; let (i, _) = mightbespace(i)?;
let (i, a) = separated_list0(commas, value)(i)?; let (i, a) = separated_list0(commas, value)(i)?;

View file

@ -4,9 +4,12 @@ use crate::sql::escape::escape_ident;
use nom::branch::alt; use nom::branch::alt;
use nom::bytes::complete::escaped_transform; use nom::bytes::complete::escaped_transform;
use nom::bytes::complete::is_not; use nom::bytes::complete::is_not;
use nom::bytes::complete::tag;
use nom::bytes::complete::take_while1; use nom::bytes::complete::take_while1;
use nom::character::complete::char; use nom::character::complete::char;
use nom::combinator::recognize;
use nom::combinator::value; use nom::combinator::value;
use nom::multi::separated_list1;
use nom::sequence::delimited; use nom::sequence::delimited;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
@ -65,7 +68,12 @@ pub fn ident(i: &str) -> IResult<&str, Ident> {
} }
pub fn plain(i: &str) -> IResult<&str, Ident> { pub fn plain(i: &str) -> IResult<&str, Ident> {
let (i, v) = ident_default(i)?; let (i, v) = take_while1(val_char)(i)?;
Ok((i, Ident::from(v)))
}
pub fn multi(i: &str) -> IResult<&str, Ident> {
let (i, v) = recognize(separated_list1(tag("::"), take_while1(val_char)))(i)?;
Ok((i, Ident::from(v))) Ok((i, Ident::from(v)))
} }

View file

@ -277,7 +277,7 @@ fn function(i: &str) -> IResult<&str, DefineFunctionStatement> {
let (i, _) = tag_no_case("FUNCTION")(i)?; let (i, _) = tag_no_case("FUNCTION")(i)?;
let (i, _) = shouldbespace(i)?; let (i, _) = shouldbespace(i)?;
let (i, _) = tag("fn::")(i)?; let (i, _) = tag("fn::")(i)?;
let (i, name) = ident::plain(i)?; let (i, name) = ident::multi(i)?;
let (i, _) = mightbespace(i)?; let (i, _) = mightbespace(i)?;
let (i, _) = char('(')(i)?; let (i, _) = char('(')(i)?;
let (i, _) = mightbespace(i)?; let (i, _) = mightbespace(i)?;