summaryrefslogtreecommitdiffstats
path: root/vendor/regex-syntax/src/ast/parse.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/regex-syntax/src/ast/parse.rs')
-rw-r--r--vendor/regex-syntax/src/ast/parse.rs576
1 files changed, 386 insertions, 190 deletions
diff --git a/vendor/regex-syntax/src/ast/parse.rs b/vendor/regex-syntax/src/ast/parse.rs
index 9cf64e9ec..593b14fbc 100644
--- a/vendor/regex-syntax/src/ast/parse.rs
+++ b/vendor/regex-syntax/src/ast/parse.rs
@@ -53,11 +53,11 @@ impl Primitive {
/// Convert this primitive into a proper AST.
fn into_ast(self) -> Ast {
match self {
- Primitive::Literal(lit) => Ast::Literal(lit),
- Primitive::Assertion(assert) => Ast::Assertion(assert),
- Primitive::Dot(span) => Ast::Dot(span),
- Primitive::Perl(cls) => Ast::Class(ast::Class::Perl(cls)),
- Primitive::Unicode(cls) => Ast::Class(ast::Class::Unicode(cls)),
+ Primitive::Literal(lit) => Ast::literal(lit),
+ Primitive::Assertion(assert) => Ast::assertion(assert),
+ Primitive::Dot(span) => Ast::dot(span),
+ Primitive::Perl(cls) => Ast::class_perl(cls),
+ Primitive::Unicode(cls) => Ast::class_unicode(cls),
}
}
@@ -383,7 +383,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
/// Return a reference to the pattern being parsed.
fn pattern(&self) -> &str {
- self.pattern.borrow()
+ self.pattern
}
/// Create a new error with the given span and error type.
@@ -691,7 +691,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
self.parser().ignore_whitespace.set(v);
}
- concat.asts.push(Ast::Flags(set));
+ concat.asts.push(Ast::flags(set));
Ok(concat)
}
Either::Right(group) => {
@@ -764,7 +764,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
group.ast = Box::new(group_concat.into_ast());
}
}
- prior_concat.asts.push(Ast::Group(group));
+ prior_concat.asts.push(Ast::group(group));
Ok(prior_concat)
}
@@ -783,7 +783,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
Some(GroupState::Alternation(mut alt)) => {
alt.span.end = self.pos();
alt.asts.push(concat.into_ast());
- Ok(Ast::Alternation(alt))
+ Ok(Ast::alternation(alt))
}
Some(GroupState::Group { group, .. }) => {
return Err(
@@ -850,7 +850,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
fn pop_class(
&self,
nested_union: ast::ClassSetUnion,
- ) -> Result<Either<ast::ClassSetUnion, ast::Class>> {
+ ) -> Result<Either<ast::ClassSetUnion, ast::ClassBracketed>> {
assert_eq!(self.char(), ']');
let item = ast::ClassSet::Item(nested_union.into_item());
@@ -882,7 +882,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
set.span.end = self.pos();
set.kind = prevset;
if stack.is_empty() {
- Ok(Either::Right(ast::Class::Bracketed(set)))
+ Ok(Either::Right(set))
} else {
union.push(ast::ClassSetItem::Bracketed(Box::new(set)));
Ok(Either::Left(union))
@@ -976,7 +976,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
'|' => concat = self.push_alternate(concat)?,
'[' => {
let class = self.parse_set_class()?;
- concat.asts.push(Ast::Class(class));
+ concat.asts.push(Ast::class_bracketed(class));
}
'?' => {
concat = self.parse_uncounted_repetition(
@@ -1057,7 +1057,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
greedy = false;
self.bump();
}
- concat.asts.push(Ast::Repetition(ast::Repetition {
+ concat.asts.push(Ast::repetition(ast::Repetition {
span: ast.span().with_end(self.pos()),
op: ast::RepetitionOp {
span: Span::new(op_start, self.pos()),
@@ -1159,7 +1159,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
self.error(op_span, ast::ErrorKind::RepetitionCountInvalid)
);
}
- concat.asts.push(Ast::Repetition(ast::Repetition {
+ concat.asts.push(Ast::repetition(ast::Repetition {
span: ast.span().with_end(self.pos()),
op: ast::RepetitionOp {
span: op_span,
@@ -1212,7 +1212,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
Ok(Either::Right(ast::Group {
span: open_span,
kind: ast::GroupKind::CaptureName { starts_with_p, name },
- ast: Box::new(Ast::Empty(self.span())),
+ ast: Box::new(Ast::empty(self.span())),
}))
} else if self.bump_if("?") {
if self.is_eof() {
@@ -1241,7 +1241,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
Ok(Either::Right(ast::Group {
span: open_span,
kind: ast::GroupKind::NonCapturing(flags),
- ast: Box::new(Ast::Empty(self.span())),
+ ast: Box::new(Ast::empty(self.span())),
}))
}
} else {
@@ -1249,7 +1249,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
Ok(Either::Right(ast::Group {
span: open_span,
kind: ast::GroupKind::CaptureIndex(capture_index),
- ast: Box::new(Ast::Empty(self.span())),
+ ast: Box::new(Ast::empty(self.span())),
}))
}
}
@@ -1528,18 +1528,115 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
span,
kind: ast::AssertionKind::EndText,
})),
- 'b' => Ok(Primitive::Assertion(ast::Assertion {
- span,
- kind: ast::AssertionKind::WordBoundary,
- })),
+ 'b' => {
+ let mut wb = ast::Assertion {
+ span,
+ kind: ast::AssertionKind::WordBoundary,
+ };
+ // After a \b, we "try" to parse things like \b{start} for
+ // special word boundary assertions.
+ if !self.is_eof() && self.char() == '{' {
+ if let Some(kind) =
+ self.maybe_parse_special_word_boundary(start)?
+ {
+ wb.kind = kind;
+ wb.span.end = self.pos();
+ }
+ }
+ Ok(Primitive::Assertion(wb))
+ }
'B' => Ok(Primitive::Assertion(ast::Assertion {
span,
kind: ast::AssertionKind::NotWordBoundary,
})),
+ '<' => Ok(Primitive::Assertion(ast::Assertion {
+ span,
+ kind: ast::AssertionKind::WordBoundaryStartAngle,
+ })),
+ '>' => Ok(Primitive::Assertion(ast::Assertion {
+ span,
+ kind: ast::AssertionKind::WordBoundaryEndAngle,
+ })),
_ => Err(self.error(span, ast::ErrorKind::EscapeUnrecognized)),
}
}
+ /// Attempt to parse a specialty word boundary. That is, `\b{start}`,
+ /// `\b{end}`, `\b{start-half}` or `\b{end-half}`.
+ ///
+ /// This is similar to `maybe_parse_ascii_class` in that, in most cases,
+ /// if it fails it will just return `None` with no error. This is done
+ /// because `\b{5}` is a valid expression and we want to let that be parsed
+ /// by the existing counted repetition parsing code. (I thought about just
+ /// invoking the counted repetition code from here, but it seemed a little
+ /// ham-fisted.)
+ ///
+ /// Unlike `maybe_parse_ascii_class` though, this can return an error.
+ /// Namely, if we definitely know it isn't a counted repetition, then we
+ /// return an error specific to the specialty word boundaries.
+ ///
+ /// This assumes the parser is positioned at a `{` immediately following
+ /// a `\b`. When `None` is returned, the parser is returned to the position
+ /// at which it started: pointing at a `{`.
+ ///
+ /// The position given should correspond to the start of the `\b`.
+ fn maybe_parse_special_word_boundary(
+ &self,
+ wb_start: Position,
+ ) -> Result<Option<ast::AssertionKind>> {
+ assert_eq!(self.char(), '{');
+
+ let is_valid_char = |c| match c {
+ 'A'..='Z' | 'a'..='z' | '-' => true,
+ _ => false,
+ };
+ let start = self.pos();
+ if !self.bump_and_bump_space() {
+ return Err(self.error(
+ Span::new(wb_start, self.pos()),
+ ast::ErrorKind::SpecialWordOrRepetitionUnexpectedEof,
+ ));
+ }
+ let start_contents = self.pos();
+ // This is one of the critical bits: if the first non-whitespace
+ // character isn't in [-A-Za-z] (i.e., this can't be a special word
+ // boundary), then we bail and let the counted repetition parser deal
+ // with this.
+ if !is_valid_char(self.char()) {
+ self.parser().pos.set(start);
+ return Ok(None);
+ }
+
+ // Now collect up our chars until we see a '}'.
+ let mut scratch = self.parser().scratch.borrow_mut();
+ scratch.clear();
+ while !self.is_eof() && is_valid_char(self.char()) {
+ scratch.push(self.char());
+ self.bump_and_bump_space();
+ }
+ if self.is_eof() || self.char() != '}' {
+ return Err(self.error(
+ Span::new(start, self.pos()),
+ ast::ErrorKind::SpecialWordBoundaryUnclosed,
+ ));
+ }
+ let end = self.pos();
+ self.bump();
+ let kind = match scratch.as_str() {
+ "start" => ast::AssertionKind::WordBoundaryStart,
+ "end" => ast::AssertionKind::WordBoundaryEnd,
+ "start-half" => ast::AssertionKind::WordBoundaryStartHalf,
+ "end-half" => ast::AssertionKind::WordBoundaryEndHalf,
+ _ => {
+ return Err(self.error(
+ Span::new(start_contents, end),
+ ast::ErrorKind::SpecialWordBoundaryUnrecognized,
+ ))
+ }
+ };
+ Ok(Some(kind))
+ }
+
/// Parse an octal representation of a Unicode codepoint up to 3 digits
/// long. This expects the parser to be positioned at the first octal
/// digit and advances the parser to the first character immediately
@@ -1743,7 +1840,7 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
/// is successful, then the parser is advanced to the position immediately
/// following the closing `]`.
#[inline(never)]
- fn parse_set_class(&self) -> Result<ast::Class> {
+ fn parse_set_class(&self) -> Result<ast::ClassBracketed> {
assert_eq!(self.char(), '[');
let mut union =
@@ -1967,9 +2064,9 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
// because parsing cannot fail with any interesting error. For example,
// in order to use an ASCII character class, it must be enclosed in
// double brackets, e.g., `[[:alnum:]]`. Alternatively, you might think
- // of it as "ASCII character characters have the syntax `[:NAME:]`
- // which can only appear within character brackets." This means that
- // things like `[[:lower:]A]` are legal constructs.
+ // of it as "ASCII character classes have the syntax `[:NAME:]` which
+ // can only appear within character brackets." This means that things
+ // like `[[:lower:]A]` are legal constructs.
//
// However, if one types an incorrect ASCII character class, e.g.,
// `[[:loower:]]`, then we treat that as a normal nested character
@@ -2189,12 +2286,12 @@ impl<'p, 's, P: Borrow<Parser>> ast::Visitor for NestLimiter<'p, 's, P> {
| Ast::Literal(_)
| Ast::Dot(_)
| Ast::Assertion(_)
- | Ast::Class(ast::Class::Unicode(_))
- | Ast::Class(ast::Class::Perl(_)) => {
+ | Ast::ClassUnicode(_)
+ | Ast::ClassPerl(_) => {
// These are all base cases, so we don't increment depth.
return Ok(());
}
- Ast::Class(ast::Class::Bracketed(ref x)) => &x.span,
+ Ast::ClassBracketed(ref x) => &x.span,
Ast::Repetition(ref x) => &x.span,
Ast::Group(ref x) => &x.span,
Ast::Alternation(ref x) => &x.span,
@@ -2210,12 +2307,12 @@ impl<'p, 's, P: Borrow<Parser>> ast::Visitor for NestLimiter<'p, 's, P> {
| Ast::Literal(_)
| Ast::Dot(_)
| Ast::Assertion(_)
- | Ast::Class(ast::Class::Unicode(_))
- | Ast::Class(ast::Class::Perl(_)) => {
+ | Ast::ClassUnicode(_)
+ | Ast::ClassPerl(_) => {
// These are all base cases, so we don't decrement depth.
Ok(())
}
- Ast::Class(ast::Class::Bracketed(_))
+ Ast::ClassBracketed(_)
| Ast::Repetition(_)
| Ast::Group(_)
| Ast::Alternation(_)
@@ -2426,12 +2523,12 @@ mod tests {
/// Create a meta literal starting at the given position.
fn meta_lit(c: char, span: Span) -> Ast {
- Ast::Literal(ast::Literal { span, kind: ast::LiteralKind::Meta, c })
+ Ast::literal(ast::Literal { span, kind: ast::LiteralKind::Meta, c })
}
/// Create a verbatim literal with the given span.
fn lit_with(c: char, span: Span) -> Ast {
- Ast::Literal(ast::Literal {
+ Ast::literal(ast::Literal {
span,
kind: ast::LiteralKind::Verbatim,
c,
@@ -2445,17 +2542,17 @@ mod tests {
/// Create a concatenation with the given span.
fn concat_with(span: Span, asts: Vec<Ast>) -> Ast {
- Ast::Concat(ast::Concat { span, asts })
+ Ast::concat(ast::Concat { span, asts })
}
/// Create an alternation with the given span.
fn alt(range: Range<usize>, asts: Vec<Ast>) -> Ast {
- Ast::Alternation(ast::Alternation { span: span(range), asts })
+ Ast::alternation(ast::Alternation { span: span(range), asts })
}
/// Create a capturing group with the given span.
fn group(range: Range<usize>, index: u32, ast: Ast) -> Ast {
- Ast::Group(ast::Group {
+ Ast::group(ast::Group {
span: span(range),
kind: ast::GroupKind::CaptureIndex(index),
ast: Box::new(ast),
@@ -2488,7 +2585,7 @@ mod tests {
},
);
}
- Ast::Flags(ast::SetFlags {
+ Ast::flags(ast::SetFlags {
span: span_range(pat, range.clone()),
flags: ast::Flags {
span: span_range(pat, (range.start + 2)..(range.end - 1)),
@@ -2502,7 +2599,7 @@ mod tests {
// A nest limit of 0 still allows some types of regexes.
assert_eq!(
parser_nest_limit("", 0).parse(),
- Ok(Ast::Empty(span(0..0)))
+ Ok(Ast::empty(span(0..0)))
);
assert_eq!(parser_nest_limit("a", 0).parse(), Ok(lit('a', 0)));
@@ -2516,7 +2613,7 @@ mod tests {
);
assert_eq!(
parser_nest_limit("a+", 1).parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..2),
op: ast::RepetitionOp {
span: span(1..2),
@@ -2542,14 +2639,14 @@ mod tests {
);
assert_eq!(
parser_nest_limit("a+*", 2).parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..3),
op: ast::RepetitionOp {
span: span(2..3),
kind: ast::RepetitionKind::ZeroOrMore,
},
greedy: true,
- ast: Box::new(Ast::Repetition(ast::Repetition {
+ ast: Box::new(Ast::repetition(ast::Repetition {
span: span(0..2),
op: ast::RepetitionOp {
span: span(1..2),
@@ -2606,7 +2703,7 @@ mod tests {
);
assert_eq!(
parser_nest_limit("[a]", 1).parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..3),
negated: false,
kind: ast::ClassSet::Item(ast::ClassSetItem::Literal(
@@ -2616,7 +2713,7 @@ mod tests {
c: 'a',
}
)),
- })))
+ }))
);
assert_eq!(
parser_nest_limit("[ab]", 1).parse().unwrap_err(),
@@ -2776,7 +2873,7 @@ bar
vec![
lit_with('a', span_range(pat, 0..1)),
lit_with(' ', span_range(pat, 1..2)),
- Ast::Group(ast::Group {
+ Ast::group(ast::Group {
span: span_range(pat, 2..9),
kind: ast::GroupKind::NonCapturing(ast::Flags {
span: span_range(pat, 4..5),
@@ -2803,7 +2900,7 @@ bar
span_range(pat, 0..pat.len()),
vec![
flag_set(pat, 0..4, ast::Flag::IgnoreWhitespace, false),
- Ast::Group(ast::Group {
+ Ast::group(ast::Group {
span: span_range(pat, 4..pat.len()),
kind: ast::GroupKind::CaptureName {
starts_with_p: true,
@@ -2825,7 +2922,7 @@ bar
span_range(pat, 0..pat.len()),
vec![
flag_set(pat, 0..4, ast::Flag::IgnoreWhitespace, false),
- Ast::Group(ast::Group {
+ Ast::group(ast::Group {
span: span_range(pat, 4..pat.len()),
kind: ast::GroupKind::CaptureIndex(1),
ast: Box::new(lit_with('a', span_range(pat, 7..8))),
@@ -2840,7 +2937,7 @@ bar
span_range(pat, 0..pat.len()),
vec![
flag_set(pat, 0..4, ast::Flag::IgnoreWhitespace, false),
- Ast::Group(ast::Group {
+ Ast::group(ast::Group {
span: span_range(pat, 4..pat.len()),
kind: ast::GroupKind::NonCapturing(ast::Flags {
span: span_range(pat, 8..8),
@@ -2858,7 +2955,7 @@ bar
span_range(pat, 0..pat.len()),
vec![
flag_set(pat, 0..4, ast::Flag::IgnoreWhitespace, false),
- Ast::Literal(ast::Literal {
+ Ast::literal(ast::Literal {
span: span(4..13),
kind: ast::LiteralKind::HexBrace(
ast::HexLiteralKind::X
@@ -2877,7 +2974,7 @@ bar
span_range(pat, 0..pat.len()),
vec![
flag_set(pat, 0..4, ast::Flag::IgnoreWhitespace, false),
- Ast::Literal(ast::Literal {
+ Ast::literal(ast::Literal {
span: span_range(pat, 4..6),
kind: ast::LiteralKind::Superfluous,
c: ' ',
@@ -2895,9 +2992,9 @@ bar
Ok(concat_with(
span_range(pat, 0..3),
vec![
- Ast::Dot(span_range(pat, 0..1)),
+ Ast::dot(span_range(pat, 0..1)),
lit_with('\n', span_range(pat, 1..2)),
- Ast::Dot(span_range(pat, 2..3)),
+ Ast::dot(span_range(pat, 2..3)),
]
))
);
@@ -2933,7 +3030,7 @@ bar
fn parse_uncounted_repetition() {
assert_eq!(
parser(r"a*").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..2),
op: ast::RepetitionOp {
span: span(1..2),
@@ -2945,7 +3042,7 @@ bar
);
assert_eq!(
parser(r"a+").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..2),
op: ast::RepetitionOp {
span: span(1..2),
@@ -2958,7 +3055,7 @@ bar
assert_eq!(
parser(r"a?").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..2),
op: ast::RepetitionOp {
span: span(1..2),
@@ -2970,7 +3067,7 @@ bar
);
assert_eq!(
parser(r"a??").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..3),
op: ast::RepetitionOp {
span: span(1..3),
@@ -2982,7 +3079,7 @@ bar
);
assert_eq!(
parser(r"a?").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..2),
op: ast::RepetitionOp {
span: span(1..2),
@@ -2997,7 +3094,7 @@ bar
Ok(concat(
0..3,
vec![
- Ast::Repetition(ast::Repetition {
+ Ast::repetition(ast::Repetition {
span: span(0..2),
op: ast::RepetitionOp {
span: span(1..2),
@@ -3015,7 +3112,7 @@ bar
Ok(concat(
0..4,
vec![
- Ast::Repetition(ast::Repetition {
+ Ast::repetition(ast::Repetition {
span: span(0..3),
op: ast::RepetitionOp {
span: span(1..3),
@@ -3034,7 +3131,7 @@ bar
0..3,
vec![
lit('a', 0),
- Ast::Repetition(ast::Repetition {
+ Ast::repetition(ast::Repetition {
span: span(1..3),
op: ast::RepetitionOp {
span: span(2..3),
@@ -3048,7 +3145,7 @@ bar
);
assert_eq!(
parser(r"(ab)?").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..5),
op: ast::RepetitionOp {
span: span(4..5),
@@ -3067,8 +3164,8 @@ bar
Ok(alt(
0..3,
vec![
- Ast::Empty(span(0..0)),
- Ast::Repetition(ast::Repetition {
+ Ast::empty(span(0..0)),
+ Ast::repetition(ast::Repetition {
span: span(1..3),
op: ast::RepetitionOp {
span: span(2..3),
@@ -3157,7 +3254,7 @@ bar
fn parse_counted_repetition() {
assert_eq!(
parser(r"a{5}").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..4),
op: ast::RepetitionOp {
span: span(1..4),
@@ -3171,7 +3268,7 @@ bar
);
assert_eq!(
parser(r"a{5,}").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..5),
op: ast::RepetitionOp {
span: span(1..5),
@@ -3185,7 +3282,7 @@ bar
);
assert_eq!(
parser(r"a{5,9}").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..6),
op: ast::RepetitionOp {
span: span(1..6),
@@ -3199,7 +3296,7 @@ bar
);
assert_eq!(
parser(r"a{5}?").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..5),
op: ast::RepetitionOp {
span: span(1..5),
@@ -3217,7 +3314,7 @@ bar
0..5,
vec![
lit('a', 0),
- Ast::Repetition(ast::Repetition {
+ Ast::repetition(ast::Repetition {
span: span(1..5),
op: ast::RepetitionOp {
span: span(2..5),
@@ -3237,7 +3334,7 @@ bar
0..6,
vec![
lit('a', 0),
- Ast::Repetition(ast::Repetition {
+ Ast::repetition(ast::Repetition {
span: span(1..5),
op: ast::RepetitionOp {
span: span(2..5),
@@ -3255,7 +3352,7 @@ bar
assert_eq!(
parser(r"a{ 5 }").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..6),
op: ast::RepetitionOp {
span: span(1..6),
@@ -3269,7 +3366,7 @@ bar
);
assert_eq!(
parser(r"a{ 5 , 9 }").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..10),
op: ast::RepetitionOp {
span: span(1..10),
@@ -3283,7 +3380,7 @@ bar
);
assert_eq!(
parser_ignore_whitespace(r"a{5,9} ?").parse(),
- Ok(Ast::Repetition(ast::Repetition {
+ Ok(Ast::repetition(ast::Repetition {
span: span(0..8),
op: ast::RepetitionOp {
span: span(1..8),
@@ -3295,6 +3392,23 @@ bar
ast: Box::new(lit('a', 0)),
}))
);
+ assert_eq!(
+ parser(r"\b{5,9}").parse(),
+ Ok(Ast::repetition(ast::Repetition {
+ span: span(0..7),
+ op: ast::RepetitionOp {
+ span: span(2..7),
+ kind: ast::RepetitionKind::Range(
+ ast::RepetitionRange::Bounded(5, 9)
+ ),
+ },
+ greedy: true,
+ ast: Box::new(Ast::assertion(ast::Assertion {
+ span: span(0..2),
+ kind: ast::AssertionKind::WordBoundary,
+ })),
+ }))
+ );
assert_eq!(
parser(r"(?i){0}").parse().unwrap_err(),
@@ -3414,7 +3528,7 @@ bar
fn parse_alternate() {
assert_eq!(
parser(r"a|b").parse(),
- Ok(Ast::Alternation(ast::Alternation {
+ Ok(Ast::alternation(ast::Alternation {
span: span(0..3),
asts: vec![lit('a', 0), lit('b', 2)],
}))
@@ -3424,7 +3538,7 @@ bar
Ok(group(
0..5,
1,
- Ast::Alternation(ast::Alternation {
+ Ast::alternation(ast::Alternation {
span: span(1..4),
asts: vec![lit('a', 1), lit('b', 3)],
})
@@ -3433,14 +3547,14 @@ bar
assert_eq!(
parser(r"a|b|c").parse(),
- Ok(Ast::Alternation(ast::Alternation {
+ Ok(Ast::alternation(ast::Alternation {
span: span(0..5),
asts: vec![lit('a', 0), lit('b', 2), lit('c', 4)],
}))
);
assert_eq!(
parser(r"ax|by|cz").parse(),
- Ok(Ast::Alternation(ast::Alternation {
+ Ok(Ast::alternation(ast::Alternation {
span: span(0..8),
asts: vec![
concat(0..2, vec![lit('a', 0), lit('x', 1)]),
@@ -3454,7 +3568,7 @@ bar
Ok(group(
0..10,
1,
- Ast::Alternation(ast::Alternation {
+ Ast::alternation(ast::Alternation {
span: span(1..9),
asts: vec![
concat(1..3, vec![lit('a', 1), lit('x', 2)]),
@@ -3503,7 +3617,7 @@ bar
parser(r"|").parse(),
Ok(alt(
0..1,
- vec![Ast::Empty(span(0..0)), Ast::Empty(span(1..1)),]
+ vec![Ast::empty(span(0..0)), Ast::empty(span(1..1)),]
))
);
assert_eq!(
@@ -3511,19 +3625,19 @@ bar
Ok(alt(
0..2,
vec![
- Ast::Empty(span(0..0)),
- Ast::Empty(span(1..1)),
- Ast::Empty(span(2..2)),
+ Ast::empty(span(0..0)),
+ Ast::empty(span(1..1)),
+ Ast::empty(span(2..2)),
]
))
);
assert_eq!(
parser(r"a|").parse(),
- Ok(alt(0..2, vec![lit('a', 0), Ast::Empty(span(2..2)),]))
+ Ok(alt(0..2, vec![lit('a', 0), Ast::empty(span(2..2)),]))
);
assert_eq!(
parser(r"|a").parse(),
- Ok(alt(0..2, vec![Ast::Empty(span(0..0)), lit('a', 1),]))
+ Ok(alt(0..2, vec![Ast::empty(span(0..0)), lit('a', 1),]))
);
assert_eq!(
@@ -3533,7 +3647,7 @@ bar
1,
alt(
1..2,
- vec![Ast::Empty(span(1..1)), Ast::Empty(span(2..2)),]
+ vec![Ast::empty(span(1..1)), Ast::empty(span(2..2)),]
)
))
);
@@ -3542,7 +3656,7 @@ bar
Ok(group(
0..4,
1,
- alt(1..3, vec![lit('a', 1), Ast::Empty(span(3..3)),])
+ alt(1..3, vec![lit('a', 1), Ast::empty(span(3..3)),])
))
);
assert_eq!(
@@ -3550,7 +3664,7 @@ bar
Ok(group(
0..4,
1,
- alt(1..3, vec![Ast::Empty(span(1..1)), lit('a', 2),])
+ alt(1..3, vec![Ast::empty(span(1..1)), lit('a', 2),])
))
);
@@ -3606,7 +3720,7 @@ bar
fn parse_group() {
assert_eq!(
parser("(?i)").parse(),
- Ok(Ast::Flags(ast::SetFlags {
+ Ok(Ast::flags(ast::SetFlags {
span: span(0..4),
flags: ast::Flags {
span: span(2..3),
@@ -3621,7 +3735,7 @@ bar
);
assert_eq!(
parser("(?iU)").parse(),
- Ok(Ast::Flags(ast::SetFlags {
+ Ok(Ast::flags(ast::SetFlags {
span: span(0..5),
flags: ast::Flags {
span: span(2..4),
@@ -3644,7 +3758,7 @@ bar
);
assert_eq!(
parser("(?i-U)").parse(),
- Ok(Ast::Flags(ast::SetFlags {
+ Ok(Ast::flags(ast::SetFlags {
span: span(0..6),
flags: ast::Flags {
span: span(2..5),
@@ -3672,15 +3786,15 @@ bar
assert_eq!(
parser("()").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..2),
kind: ast::GroupKind::CaptureIndex(1),
- ast: Box::new(Ast::Empty(span(1..1))),
+ ast: Box::new(Ast::empty(span(1..1))),
}))
);
assert_eq!(
parser("(a)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..3),
kind: ast::GroupKind::CaptureIndex(1),
ast: Box::new(lit('a', 1)),
@@ -3688,20 +3802,20 @@ bar
);
assert_eq!(
parser("(())").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..4),
kind: ast::GroupKind::CaptureIndex(1),
- ast: Box::new(Ast::Group(ast::Group {
+ ast: Box::new(Ast::group(ast::Group {
span: span(1..3),
kind: ast::GroupKind::CaptureIndex(2),
- ast: Box::new(Ast::Empty(span(2..2))),
+ ast: Box::new(Ast::empty(span(2..2))),
})),
}))
);
assert_eq!(
parser("(?:a)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..5),
kind: ast::GroupKind::NonCapturing(ast::Flags {
span: span(2..2),
@@ -3713,7 +3827,7 @@ bar
assert_eq!(
parser("(?i:a)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..6),
kind: ast::GroupKind::NonCapturing(ast::Flags {
span: span(2..3),
@@ -3729,7 +3843,7 @@ bar
);
assert_eq!(
parser("(?i-U:a)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..8),
kind: ast::GroupKind::NonCapturing(ast::Flags {
span: span(2..5),
@@ -3818,7 +3932,7 @@ bar
fn parse_capture_name() {
assert_eq!(
parser("(?<a>z)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..7),
kind: ast::GroupKind::CaptureName {
starts_with_p: false,
@@ -3833,7 +3947,7 @@ bar
);
assert_eq!(
parser("(?P<a>z)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..8),
kind: ast::GroupKind::CaptureName {
starts_with_p: true,
@@ -3848,7 +3962,7 @@ bar
);
assert_eq!(
parser("(?P<abc>z)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..10),
kind: ast::GroupKind::CaptureName {
starts_with_p: true,
@@ -3864,7 +3978,7 @@ bar
assert_eq!(
parser("(?P<a_1>z)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..10),
kind: ast::GroupKind::CaptureName {
starts_with_p: true,
@@ -3880,7 +3994,7 @@ bar
assert_eq!(
parser("(?P<a.1>z)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..10),
kind: ast::GroupKind::CaptureName {
starts_with_p: true,
@@ -3896,7 +4010,7 @@ bar
assert_eq!(
parser("(?P<a[1]>z)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: span(0..11),
kind: ast::GroupKind::CaptureName {
starts_with_p: true,
@@ -3912,7 +4026,7 @@ bar
assert_eq!(
parser("(?P<a¾>)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: Span::new(
Position::new(0, 1, 1),
Position::new(9, 1, 9),
@@ -3928,7 +4042,7 @@ bar
index: 1,
}
},
- ast: Box::new(Ast::Empty(Span::new(
+ ast: Box::new(Ast::empty(Span::new(
Position::new(8, 1, 8),
Position::new(8, 1, 8),
))),
@@ -3936,7 +4050,7 @@ bar
);
assert_eq!(
parser("(?P<名字>)").parse(),
- Ok(Ast::Group(ast::Group {
+ Ok(Ast::group(ast::Group {
span: Span::new(
Position::new(0, 1, 1),
Position::new(12, 1, 9),
@@ -3952,7 +4066,7 @@ bar
index: 1,
}
},
- ast: Box::new(Ast::Empty(Span::new(
+ ast: Box::new(Ast::empty(Span::new(
Position::new(11, 1, 8),
Position::new(11, 1, 8),
))),
@@ -4382,6 +4496,48 @@ bar
}))
);
assert_eq!(
+ parser(r"\b{start}").parse_primitive(),
+ Ok(Primitive::Assertion(ast::Assertion {
+ span: span(0..9),
+ kind: ast::AssertionKind::WordBoundaryStart,
+ }))
+ );
+ assert_eq!(
+ parser(r"\b{end}").parse_primitive(),
+ Ok(Primitive::Assertion(ast::Assertion {
+ span: span(0..7),
+ kind: ast::AssertionKind::WordBoundaryEnd,
+ }))
+ );
+ assert_eq!(
+ parser(r"\b{start-half}").parse_primitive(),
+ Ok(Primitive::Assertion(ast::Assertion {
+ span: span(0..14),
+ kind: ast::AssertionKind::WordBoundaryStartHalf,
+ }))
+ );
+ assert_eq!(
+ parser(r"\b{end-half}").parse_primitive(),
+ Ok(Primitive::Assertion(ast::Assertion {
+ span: span(0..12),
+ kind: ast::AssertionKind::WordBoundaryEndHalf,
+ }))
+ );
+ assert_eq!(
+ parser(r"\<").parse_primitive(),
+ Ok(Primitive::Assertion(ast::Assertion {
+ span: span(0..2),
+ kind: ast::AssertionKind::WordBoundaryStartAngle,
+ }))
+ );
+ assert_eq!(
+ parser(r"\>").parse_primitive(),
+ Ok(Primitive::Assertion(ast::Assertion {
+ span: span(0..2),
+ kind: ast::AssertionKind::WordBoundaryEndAngle,
+ }))
+ );
+ assert_eq!(
parser(r"\B").parse_primitive(),
Ok(Primitive::Assertion(ast::Assertion {
span: span(0..2),
@@ -4418,20 +4574,60 @@ bar
kind: ast::ErrorKind::EscapeUnrecognized,
}
);
- // But also, < and > are banned, so that we may evolve them into
- // start/end word boundary assertions. (Not sure if we will...)
+
+ // Starting a special word boundary without any non-whitespace chars
+ // after the brace makes it ambiguous whether the user meant to write
+ // a counted repetition (probably not?) or an actual special word
+ // boundary assertion.
assert_eq!(
- parser(r"\<").parse_escape().unwrap_err(),
+ parser(r"\b{").parse_escape().unwrap_err(),
TestError {
- span: span(0..2),
- kind: ast::ErrorKind::EscapeUnrecognized,
+ span: span(0..3),
+ kind: ast::ErrorKind::SpecialWordOrRepetitionUnexpectedEof,
}
);
assert_eq!(
- parser(r"\>").parse_escape().unwrap_err(),
+ parser_ignore_whitespace(r"\b{ ").parse_escape().unwrap_err(),
TestError {
- span: span(0..2),
- kind: ast::ErrorKind::EscapeUnrecognized,
+ span: span(0..4),
+ kind: ast::ErrorKind::SpecialWordOrRepetitionUnexpectedEof,
+ }
+ );
+ // When 'x' is not enabled, the space is seen as a non-[-A-Za-z] char,
+ // and thus causes the parser to treat it as a counted repetition.
+ assert_eq!(
+ parser(r"\b{ ").parse().unwrap_err(),
+ TestError {
+ span: span(4..4),
+ kind: ast::ErrorKind::RepetitionCountDecimalEmpty,
+ }
+ );
+ // In this case, we got some valid chars that makes it look like the
+ // user is writing one of the special word boundary assertions, but
+ // we forget to close the brace.
+ assert_eq!(
+ parser(r"\b{foo").parse_escape().unwrap_err(),
+ TestError {
+ span: span(2..6),
+ kind: ast::ErrorKind::SpecialWordBoundaryUnclosed,
+ }
+ );
+ // We get the same error as above, except it is provoked by seeing a
+ // char that we know is invalid before seeing a closing brace.
+ assert_eq!(
+ parser(r"\b{foo!}").parse_escape().unwrap_err(),
+ TestError {
+ span: span(2..6),
+ kind: ast::ErrorKind::SpecialWordBoundaryUnclosed,
+ }
+ );
+ // And this one occurs when, syntactically, everything looks okay, but
+ // we don't use a valid spelling of a word boundary assertion.
+ assert_eq!(
+ parser(r"\b{foo}").parse_escape().unwrap_err(),
+ TestError {
+ span: span(3..6),
+ kind: ast::ErrorKind::SpecialWordBoundaryUnrecognized,
}
);
@@ -4494,15 +4690,15 @@ bar
);
assert_eq!(
parser_octal(r"\778").parse(),
- Ok(Ast::Concat(ast::Concat {
+ Ok(Ast::concat(ast::Concat {
span: span(0..4),
asts: vec![
- Ast::Literal(ast::Literal {
+ Ast::literal(ast::Literal {
span: span(0..3),
kind: ast::LiteralKind::Octal,
c: '?',
}),
- Ast::Literal(ast::Literal {
+ Ast::literal(ast::Literal {
span: span(3..4),
kind: ast::LiteralKind::Verbatim,
c: '8',
@@ -4512,15 +4708,15 @@ bar
);
assert_eq!(
parser_octal(r"\7777").parse(),
- Ok(Ast::Concat(ast::Concat {
+ Ok(Ast::concat(ast::Concat {
span: span(0..5),
asts: vec![
- Ast::Literal(ast::Literal {
+ Ast::literal(ast::Literal {
span: span(0..4),
kind: ast::LiteralKind::Octal,
c: '\u{01FF}',
}),
- Ast::Literal(ast::Literal {
+ Ast::literal(ast::Literal {
span: span(4..5),
kind: ast::LiteralKind::Verbatim,
c: '7',
@@ -4965,15 +5161,15 @@ bar
assert_eq!(
parser("[[:alnum:]]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..11),
negated: false,
kind: itemset(item_ascii(alnum(span(1..10), false))),
- })))
+ }))
);
assert_eq!(
parser("[[[:alnum:]]]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..13),
negated: false,
kind: itemset(item_bracket(ast::ClassBracketed {
@@ -4981,11 +5177,11 @@ bar
negated: false,
kind: itemset(item_ascii(alnum(span(2..11), false))),
})),
- })))
+ }))
);
assert_eq!(
parser("[[:alnum:]&&[:lower:]]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..22),
negated: false,
kind: intersection(
@@ -4993,11 +5189,11 @@ bar
itemset(item_ascii(alnum(span(1..10), false))),
itemset(item_ascii(lower(span(12..21), false))),
),
- })))
+ }))
);
assert_eq!(
parser("[[:alnum:]--[:lower:]]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..22),
negated: false,
kind: difference(
@@ -5005,11 +5201,11 @@ bar
itemset(item_ascii(alnum(span(1..10), false))),
itemset(item_ascii(lower(span(12..21), false))),
),
- })))
+ }))
);
assert_eq!(
parser("[[:alnum:]~~[:lower:]]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..22),
negated: false,
kind: symdifference(
@@ -5017,20 +5213,20 @@ bar
itemset(item_ascii(alnum(span(1..10), false))),
itemset(item_ascii(lower(span(12..21), false))),
),
- })))
+ }))
);
assert_eq!(
parser("[a]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..3),
negated: false,
kind: itemset(lit(span(1..2), 'a')),
- })))
+ }))
);
assert_eq!(
parser(r"[a\]]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..5),
negated: false,
kind: union(
@@ -5044,11 +5240,11 @@ bar
}),
]
),
- })))
+ }))
);
assert_eq!(
parser(r"[a\-z]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..6),
negated: false,
kind: union(
@@ -5063,44 +5259,44 @@ bar
lit(span(4..5), 'z'),
]
),
- })))
+ }))
);
assert_eq!(
parser("[ab]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..4),
negated: false,
kind: union(
span(1..3),
vec![lit(span(1..2), 'a'), lit(span(2..3), 'b'),]
),
- })))
+ }))
);
assert_eq!(
parser("[a-]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..4),
negated: false,
kind: union(
span(1..3),
vec![lit(span(1..2), 'a'), lit(span(2..3), '-'),]
),
- })))
+ }))
);
assert_eq!(
parser("[-a]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..4),
negated: false,
kind: union(
span(1..3),
vec![lit(span(1..2), '-'), lit(span(2..3), 'a'),]
),
- })))
+ }))
);
assert_eq!(
parser(r"[\pL]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..5),
negated: false,
kind: itemset(item_unicode(ast::ClassUnicode {
@@ -5108,11 +5304,11 @@ bar
negated: false,
kind: ast::ClassUnicodeKind::OneLetter('L'),
})),
- })))
+ }))
);
assert_eq!(
parser(r"[\w]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..4),
negated: false,
kind: itemset(item_perl(ast::ClassPerl {
@@ -5120,11 +5316,11 @@ bar
kind: ast::ClassPerlKind::Word,
negated: false,
})),
- })))
+ }))
);
assert_eq!(
parser(r"[a\wz]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..6),
negated: false,
kind: union(
@@ -5139,20 +5335,20 @@ bar
lit(span(4..5), 'z'),
]
),
- })))
+ }))
);
assert_eq!(
parser("[a-z]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..5),
negated: false,
kind: itemset(range(span(1..4), 'a', 'z')),
- })))
+ }))
);
assert_eq!(
parser("[a-cx-z]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..8),
negated: false,
kind: union(
@@ -5162,11 +5358,11 @@ bar
range(span(4..7), 'x', 'z'),
]
),
- })))
+ }))
);
assert_eq!(
parser(r"[\w&&a-cx-z]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..12),
negated: false,
kind: intersection(
@@ -5184,11 +5380,11 @@ bar
]
),
),
- })))
+ }))
);
assert_eq!(
parser(r"[a-cx-z&&\w]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..12),
negated: false,
kind: intersection(
@@ -5206,11 +5402,11 @@ bar
negated: false,
})),
),
- })))
+ }))
);
assert_eq!(
parser(r"[a--b--c]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..9),
negated: false,
kind: difference(
@@ -5222,11 +5418,11 @@ bar
),
itemset(lit(span(7..8), 'c')),
),
- })))
+ }))
);
assert_eq!(
parser(r"[a~~b~~c]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..9),
negated: false,
kind: symdifference(
@@ -5238,11 +5434,11 @@ bar
),
itemset(lit(span(7..8), 'c')),
),
- })))
+ }))
);
assert_eq!(
parser(r"[\^&&^]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..7),
negated: false,
kind: intersection(
@@ -5254,11 +5450,11 @@ bar
})),
itemset(lit(span(5..6), '^')),
),
- })))
+ }))
);
assert_eq!(
parser(r"[\&&&&]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..7),
negated: false,
kind: intersection(
@@ -5270,11 +5466,11 @@ bar
})),
itemset(lit(span(5..6), '&')),
),
- })))
+ }))
);
assert_eq!(
parser(r"[&&&&]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..6),
negated: false,
kind: intersection(
@@ -5286,13 +5482,13 @@ bar
),
itemset(empty(span(5..5))),
),
- })))
+ }))
);
let pat = "[☃-⛄]";
assert_eq!(
parser(pat).parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span_range(pat, 0..9),
negated: false,
kind: itemset(ast::ClassSetItem::Range(ast::ClassSetRange {
@@ -5308,20 +5504,20 @@ bar
c: '⛄',
},
})),
- })))
+ }))
);
assert_eq!(
parser(r"[]]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..3),
negated: false,
kind: itemset(lit(span(1..2), ']')),
- })))
+ }))
);
assert_eq!(
parser(r"[]\[]").parse(),
- Ok(Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ok(Ast::class_bracketed(ast::ClassBracketed {
span: span(0..5),
negated: false,
kind: union(
@@ -5335,14 +5531,14 @@ bar
}),
]
),
- })))
+ }))
);
assert_eq!(
parser(r"[\[]]").parse(),
Ok(concat(
0..5,
vec![
- Ast::Class(ast::Class::Bracketed(ast::ClassBracketed {
+ Ast::class_bracketed(ast::ClassBracketed {
span: span(0..4),
negated: false,
kind: itemset(ast::ClassSetItem::Literal(
@@ -5352,8 +5548,8 @@ bar
c: '[',
}
)),
- })),
- Ast::Literal(ast::Literal {
+ }),
+ Ast::literal(ast::Literal {
span: span(4..5),
kind: ast::LiteralKind::Verbatim,
c: ']',
@@ -5914,15 +6110,15 @@ bar
assert_eq!(
parser(r"\pNz").parse(),
- Ok(Ast::Concat(ast::Concat {
+ Ok(Ast::concat(ast::Concat {
span: span(0..4),
asts: vec![
- Ast::Class(ast::Class::Unicode(ast::ClassUnicode {
+ Ast::class_unicode(ast::ClassUnicode {
span: span(0..3),
negated: false,
kind: ast::ClassUnicodeKind::OneLetter('N'),
- })),
- Ast::Literal(ast::Literal {
+ }),
+ Ast::literal(ast::Literal {
span: span(3..4),
kind: ast::LiteralKind::Verbatim,
c: 'z',
@@ -5932,15 +6128,15 @@ bar
);
assert_eq!(
parser(r"\p{Greek}z").parse(),
- Ok(Ast::Concat(ast::Concat {
+ Ok(Ast::concat(ast::Concat {
span: span(0..10),
asts: vec![
- Ast::Class(ast::Class::Unicode(ast::ClassUnicode {
+ Ast::class_unicode(ast::ClassUnicode {
span: span(0..9),
negated: false,
kind: ast::ClassUnicodeKind::Named(s("Greek")),
- })),
- Ast::Literal(ast::Literal {
+ }),
+ Ast::literal(ast::Literal {
span: span(9..10),
kind: ast::LiteralKind::Verbatim,
c: 'z',
@@ -6017,23 +6213,23 @@ bar
assert_eq!(
parser(r"\d").parse(),
- Ok(Ast::Class(ast::Class::Perl(ast::ClassPerl {
+ Ok(Ast::class_perl(ast::ClassPerl {
span: span(0..2),
kind: ast::ClassPerlKind::Digit,
negated: false,
- })))
+ }))
);
assert_eq!(
parser(r"\dz").parse(),
- Ok(Ast::Concat(ast::Concat {
+ Ok(Ast::concat(ast::Concat {
span: span(0..3),
asts: vec![
- Ast::Class(ast::Class::Perl(ast::ClassPerl {
+ Ast::class_perl(ast::ClassPerl {
span: span(0..2),
kind: ast::ClassPerlKind::Digit,
negated: false,
- })),
- Ast::Literal(ast::Literal {
+ }),
+ Ast::literal(ast::Literal {
span: span(2..3),
kind: ast::LiteralKind::Verbatim,
c: 'z',