fix(token): Continue parsing on c-escape

This commit is contained in:
Ed Page 2021-08-02 09:28:57 -05:00
parent 3e5d2e0620
commit a5f0dd8ee9

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);