lexer: refactor string escape to separate rule (fixes '\\"')

This commit is contained in:
John 2023-09-25 16:49:18 -05:00
parent fe2b9880d6
commit 8ddf73dc76

View File

@ -138,7 +138,7 @@ pub mod lexer {
Type::String,
Rule::new(self.text())
.char('"')
.and_any(|rule| rule.str(r#"\""#).or(|rule| rule.not_char('"')))
.and_any(|rule| rule.and(Rule::string_escape).or(|rule| rule.not_char('"')))
.char('"')
.end()?,
)
@ -211,6 +211,9 @@ pub mod lexer {
pub fn bin_digit(self) -> Self {
self.char_between('0', '1')
}
pub fn string_escape(self) -> Self {
self.char('\\').and(Rule::any)
}
fn has(self, condition: impl Fn(&Self) -> bool, len: usize) -> Self {
let len = next_utf8(self.text, len);
self.and(|rule| match condition(&rule) && !rule.text.is_empty() {