surrealpatch/src/sql/comment.rs

66 lines
1.5 KiB
Rust
Raw Normal View History

2020-06-29 15:36:01 +00:00
use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::bytes::complete::take_until;
use nom::character::complete::multispace0;
use nom::character::complete::multispace1;
use nom::character::complete::not_line_ending;
use nom::multi::many1;
use nom::IResult;
pub fn mightbespace(i: &str) -> IResult<&str, ()> {
let (i, _) = alt((comment, blank))(i)?;
Ok((i, ()))
}
pub fn shouldbespace(i: &str) -> IResult<&str, ()> {
let (i, _) = alt((comment, space))(i)?;
Ok((i, ()))
}
pub fn comment(i: &str) -> IResult<&str, ()> {
let (i, _) = multispace0(i)?;
let (i, _) = many1(alt((block, slash, dash, hash)))(i)?;
let (i, _) = multispace0(i)?;
Ok((i, ()))
}
fn blank(i: &str) -> IResult<&str, ()> {
let (i, _) = multispace0(i)?;
Ok((i, ()))
}
fn space(i: &str) -> IResult<&str, ()> {
let (i, _) = multispace1(i)?;
Ok((i, ()))
}
fn block(i: &str) -> IResult<&str, ()> {
let (i, _) = multispace0(i)?;
let (i, _) = tag("/*")(i)?;
let (i, _) = take_until("*/")(i)?;
let (i, _) = tag("*/")(i)?;
let (i, _) = multispace0(i)?;
Ok((i, ()))
}
fn slash(i: &str) -> IResult<&str, ()> {
let (i, _) = multispace0(i)?;
let (i, _) = tag("//")(i)?;
let (i, _) = not_line_ending(i)?;
Ok((i, ()))
}
fn dash(i: &str) -> IResult<&str, ()> {
let (i, _) = multispace0(i)?;
let (i, _) = tag("--")(i)?;
let (i, _) = not_line_ending(i)?;
Ok((i, ()))
}
fn hash(i: &str) -> IResult<&str, ()> {
let (i, _) = multispace0(i)?;
let (i, _) = tag("#")(i)?;
let (i, _) = not_line_ending(i)?;
Ok((i, ()))
}