From 340e214b90503f13f3822fb354838c5b20cb2ae3 Mon Sep 17 00:00:00 2001 From: Andy Lok Date: Sat, 14 May 2022 15:31:45 +0800 Subject: [PATCH] improve --- common/ast/src/parser/util.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/common/ast/src/parser/util.rs b/common/ast/src/parser/util.rs index 636ba9dede625..4eec84f923748 100644 --- a/common/ast/src/parser/util.rs +++ b/common/ast/src/parser/util.rs @@ -95,17 +95,17 @@ fn non_reserved_identifier( ), move |i| { match_token(QuotedString)(i).and_then(|(i2, token)| { - if token.kind == QuotedString && !token.text().starts_with('\'') { + if token.text().starts_with('\'') { + Err(nom::Err::Error(Error::from_error_kind( + i, + ErrorKind::ExpectToken(Ident), + ))) + } else { 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), - ))) } }) }, @@ -131,13 +131,13 @@ fn non_reserved_keyword( pub fn literal_string(i: Input) -> IResult { 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 { + if token.text().starts_with('`') { Err(nom::Err::Error(Error::from_error_kind( i, ErrorKind::ExpectToken(QuotedString), ))) + } else { + Ok((i2, token.text()[1..token.text().len() - 1].to_string())) } }) }