Merge pull request #325 from epage/escape

fix(token): Continue parsing on c-escape
This commit is contained in:
Ed Page 2021-08-02 09:48:40 -05:00 committed by GitHub
commit f6b14d91bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -374,7 +374,7 @@ mod parser {
<T as nom::InputTakeAtPosition>::Item: AsChar + Copy,
<T as nom::InputIter>::Item: AsChar + Copy,
{
preceded(char('\\'), take_while(is_xid_continue))(input)
preceded(take_while1(is_escape), take_while(is_xid_continue))(input)
}
fn printf<T>(input: T) -> IResult<T, T>
@ -496,6 +496,12 @@ mod parser {
unicode_xid::UnicodeXID::is_xid_continue(c)
}
#[inline]
fn is_escape(i: impl AsChar + Copy) -> bool {
let c = i.as_char();
c == '\\'
}
#[inline]
fn is_digit_sep(chr: char) -> bool {
// `_`: number literal separator in Rust and other languages
@ -990,10 +996,10 @@ mod test {
fn tokenize_c_escape() {
let parser = TokenizerBuilder::new().build();
let input = "Hello \\Hello \\ World";
let input = "Hello \\Hello \\ \\\\ World";
let expected: Vec<Identifier> = vec![
Identifier::new_unchecked("Hello", Case::None, 0),
Identifier::new_unchecked("World", Case::None, 15),
Identifier::new_unchecked("World", Case::None, 18),
];
let actual: Vec<_> = parser.parse_bytes(input.as_bytes()).collect();
assert_eq!(expected, actual);