From fdeba0e71bfe6a0e8fc59b0c89e0e3babdacae3f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 2 Aug 2021 09:11:54 -0500 Subject: [PATCH] fix(token): Continue parsing on c-escape --- CHANGELOG.md | 4 ++++ crates/typos/src/tokens.rs | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fffcc1c..2a80188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +#### Bug Fixes + +- Don't stop parsing at c-escape but continue on + ## [1.1.3] - 2021-07-30 #### Bug Fixes diff --git a/crates/typos/src/tokens.rs b/crates/typos/src/tokens.rs index 46865f4..3c4afdf 100644 --- a/crates/typos/src/tokens.rs +++ b/crates/typos/src/tokens.rs @@ -176,7 +176,8 @@ mod parser { { take_many0(alt(( // CAUTION: If adding an ignorable literal, if it doesn't start with `is_xid_continue`, - // then you need to update `is_ignore_char` to make sure `sep1` doesn't eat it all up. + // - Update `is_ignore_char` to make sure `sep1` doesn't eat it all up + // - Make sure you always consume it terminated(uuid_literal, sep1), terminated(hash_literal, sep1), terminated(hex_literal, sep1), @@ -373,7 +374,7 @@ mod parser { ::Item: AsChar + Copy, ::Item: AsChar + Copy, { - preceded(char('\\'), take_while1(is_xid_continue))(input) + preceded(char('\\'), take_while(is_xid_continue))(input) } fn printf(input: T) -> IResult @@ -989,10 +990,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 = vec![ Identifier::new_unchecked("Hello", Case::None, 0), - Identifier::new_unchecked("World", Case::None, 13), + Identifier::new_unchecked("World", Case::None, 15), ]; let actual: Vec<_> = parser.parse_bytes(input.as_bytes()).collect(); assert_eq!(expected, actual);