mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-25 18:41:05 -05:00
Merge pull request #325 from epage/escape
fix(token): Continue parsing on c-escape
This commit is contained in:
commit
f6b14d91bd
1 changed files with 9 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue