Skip to content

Commit

Permalink
fix: treat "a" as ident
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy committed May 14, 2022
1 parent 22be367 commit 20271a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion common/ast/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,13 @@ pub fn expr_element(i: Input) -> IResult<WithSpan> {
| #tuple : "`(<expr>, ...)`"
| #function_call_with_param : "<function>"
| #function_call : "<function>"
| #literal : "<literal>"
| #case : "`CASE ... END`"
| #exists : "`EXISTS (SELECT ...)`"
| #subquery : "`(SELECT ...)`"
| #map_access : "[<key>] | .<key> | :<key>"
| #group
| #column_ref : "<column>"
| #literal : "<literal>"
),
)))(i)?;

Expand Down
45 changes: 27 additions & 18 deletions common/ast/src/parser/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,22 @@ fn non_reserved_identifier(
quote: None,
},
),
map(rule! { QuotedString }, |token| Identifier {
span: token.clone(),
name: token.text()[1..token.text().len() - 1].to_string(),
quote: Some(token.text().chars().next().unwrap()),
}),
move |i| {
match_token(QuotedString)(i).and_then(|(i2, token)| {
if token.kind == QuotedString && !token.text().starts_with('\'') {
Ok((i2, Identifier {
span: token.clone(),
name: token.text()[1..token.text().len() - 1].to_string(),
quote: Some(token.text().chars().next().unwrap()),
}))
} else {
Err(nom::Err::Error(Error::from_error_kind(
i,
ErrorKind::ExpectToken(Ident),
)))
}
})
},
))(i)
}
}
Expand All @@ -119,22 +130,20 @@ fn non_reserved_keyword(
}

pub fn literal_string(i: Input) -> IResult<String> {
let token = &i[0];
if token.kind == QuotedString && token.text().chars().next().unwrap() != '`' {
Ok((
i.slice(1..),
token.text()[1..token.text().len() - 1].to_string(),
))
} else {
Err(nom::Err::Error(Error::from_error_kind(
i,
ErrorKind::ExpectToken(QuotedString),
)))
}
match_token(QuotedString)(i).and_then(|(i2, token)| {
if token.kind == QuotedString && !token.text().starts_with('`') {
Ok((i2, token.text()[1..token.text().len() - 1].to_string()))
} else {
Err(nom::Err::Error(Error::from_error_kind(
i,
ErrorKind::ExpectToken(QuotedString),
)))
}
})
}

pub fn literal_u64(i: Input) -> IResult<u64> {
rule!(LiteralNumber)(i).and_then(|(i2, token)| {
match_token(LiteralNumber)(i).and_then(|(i2, token)| {
token
.text()
.parse()
Expand Down

0 comments on commit 20271a8

Please sign in to comment.