lexer: refactor string escape to separate rule (fixes '\\"')
This commit is contained in:
parent
fe2b9880d6
commit
8ddf73dc76
@ -138,7 +138,7 @@ pub mod lexer {
|
|||||||
Type::String,
|
Type::String,
|
||||||
Rule::new(self.text())
|
Rule::new(self.text())
|
||||||
.char('"')
|
.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('"')
|
.char('"')
|
||||||
.end()?,
|
.end()?,
|
||||||
)
|
)
|
||||||
@ -211,6 +211,9 @@ pub mod lexer {
|
|||||||
pub fn bin_digit(self) -> Self {
|
pub fn bin_digit(self) -> Self {
|
||||||
self.char_between('0', '1')
|
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 {
|
fn has(self, condition: impl Fn(&Self) -> bool, len: usize) -> Self {
|
||||||
let len = next_utf8(self.text, len);
|
let len = next_utf8(self.text, len);
|
||||||
self.and(|rule| match condition(&rule) && !rule.text.is_empty() {
|
self.and(|rule| match condition(&rule) && !rule.text.is_empty() {
|
||||||
|
Loading…
Reference in New Issue
Block a user