Skip to content
This repository was archived by the owner on May 29, 2023. It is now read-only.

Commit af9f249

Browse files
authored
Merge pull request #10 from robinst/allow-opening-curly-as-literal
Allow unescaped `{` as literal when not after atom
2 parents 8dc181f + 59058f7 commit af9f249

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/parse.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'a> Parser<'a> {
200200
)),
201201
b'(' => self.parse_group(ix, depth),
202202
b'\\' => self.parse_escape(ix),
203-
b'+' | b'*' | b'?' | b'|' | b')' | b'{' =>
203+
b'+' | b'*' | b'?' | b'|' | b')' =>
204204
Ok((ix, Expr::Empty)),
205205
b'[' => self.parse_class(ix),
206206
b'#' | b' ' | b'\r' | b'\n' | b'\t'
@@ -558,6 +558,20 @@ mod tests {
558558
assert_eq!(p("]"), make_literal("]"));
559559
}
560560

561+
#[test]
562+
fn literal_unescaped_opening_curly() {
563+
assert_eq!(p("{"), make_literal("{"));
564+
assert_eq!(p("({)"), Expr::Group(Box::new(
565+
make_literal("{"),
566+
)));
567+
assert_eq!(p("a|{"), Expr::Alt(vec![
568+
make_literal("a"),
569+
make_literal("{"),
570+
]));
571+
assert_eq!(p("{{2}"), Expr::Repeat{ child: Box::new(make_literal("{")),
572+
lo: 2, hi: 2, greedy: true });
573+
}
574+
561575
#[test]
562576
fn literal_escape() {
563577
assert_eq!(p("\\'"), make_literal("'"));
@@ -611,6 +625,13 @@ mod tests {
611625
)));
612626
}
613627

628+
#[test]
629+
fn group_repeat() {
630+
assert_eq!(p("(a){2}"), Expr::Repeat{
631+
child: Box::new(Expr::Group(Box::new(make_literal("a")))), lo: 2, hi: 2, greedy: true
632+
});
633+
}
634+
614635
#[test]
615636
fn repeat() {
616637
assert_eq!(p("a{2,42}"), Expr::Repeat{ child: Box::new(make_literal("a")),

0 commit comments

Comments
 (0)