Merge pull request #324 from epage/escape

fix(token): Continue parsing on c-escape
This commit is contained in:
Ed Page 2021-08-02 09:23:42 -05:00 committed by GitHub
commit 3e5d2e0620
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header --> <!-- next-header -->
## [Unreleased] - ReleaseDate ## [Unreleased] - ReleaseDate
#### Bug Fixes
- Don't stop parsing at c-escape but continue on
## [1.1.3] - 2021-07-30 ## [1.1.3] - 2021-07-30
#### Bug Fixes #### Bug Fixes

View file

@ -176,7 +176,8 @@ mod parser {
{ {
take_many0(alt(( take_many0(alt((
// CAUTION: If adding an ignorable literal, if it doesn't start with `is_xid_continue`, // 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(uuid_literal, sep1),
terminated(hash_literal, sep1), terminated(hash_literal, sep1),
terminated(hex_literal, sep1), terminated(hex_literal, sep1),
@ -373,7 +374,7 @@ mod parser {
<T as nom::InputTakeAtPosition>::Item: AsChar + Copy, <T as nom::InputTakeAtPosition>::Item: AsChar + Copy,
<T as nom::InputIter>::Item: AsChar + Copy, <T as nom::InputIter>::Item: AsChar + Copy,
{ {
preceded(char('\\'), take_while1(is_xid_continue))(input) preceded(char('\\'), take_while(is_xid_continue))(input)
} }
fn printf<T>(input: T) -> IResult<T, T> fn printf<T>(input: T) -> IResult<T, T>
@ -989,10 +990,10 @@ mod test {
fn tokenize_c_escape() { fn tokenize_c_escape() {
let parser = TokenizerBuilder::new().build(); let parser = TokenizerBuilder::new().build();
let input = "Hello \\Hello World"; let input = "Hello \\Hello \\ World";
let expected: Vec<Identifier> = vec![ let expected: Vec<Identifier> = vec![
Identifier::new_unchecked("Hello", Case::None, 0), 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(); let actual: Vec<_> = parser.parse_bytes(input.as_bytes()).collect();
assert_eq!(expected, actual); assert_eq!(expected, actual);