@@ -479,6 +479,8 @@ pub enum Ast {
479479     Dot ( Box < Span > ) , 
480480    /// A single zero-width assertion. 
481481     Assertion ( Box < Assertion > ) , 
482+     /// A single look-around regular expression. 
483+      LookAround ( Box < LookAround > ) , 
482484    /// A single Unicode character class, e.g., `\pL` or `\p{Greek}`. 
483485     ClassUnicode ( Box < ClassUnicode > ) , 
484486    /// A single perl character class, e.g., `\d` or `\W`. 
@@ -523,6 +525,11 @@ impl Ast {
523525        Ast :: Assertion ( Box :: new ( e) ) 
524526    } 
525527
528+     /// Create a "look-around" AST item. 
529+      pub  fn  look_around ( e :  LookAround )  -> Ast  { 
530+         Ast :: LookAround ( Box :: new ( e) ) 
531+     } 
532+ 
526533    /// Create a "Unicode class" AST item. 
527534     pub  fn  class_unicode ( e :  ClassUnicode )  -> Ast  { 
528535        Ast :: ClassUnicode ( Box :: new ( e) ) 
@@ -566,6 +573,7 @@ impl Ast {
566573            Ast :: Literal ( ref  x)  => & x. span , 
567574            Ast :: Dot ( ref  span)  => span, 
568575            Ast :: Assertion ( ref  x)  => & x. span , 
576+             Ast :: LookAround ( ref  x)  => & x. span , 
569577            Ast :: ClassUnicode ( ref  x)  => & x. span , 
570578            Ast :: ClassPerl ( ref  x)  => & x. span , 
571579            Ast :: ClassBracketed ( ref  x)  => & x. span , 
@@ -598,6 +606,7 @@ impl Ast {
598606            Ast :: ClassBracketed ( _) 
599607            | Ast :: Repetition ( _) 
600608            | Ast :: Group ( _) 
609+             | Ast :: LookAround ( _) 
601610            | Ast :: Alternation ( _) 
602611            | Ast :: Concat ( _)  => true , 
603612        } 
@@ -1344,6 +1353,28 @@ pub enum AssertionKind {
13441353     WordBoundaryEndHalf , 
13451354} 
13461355
1356+ /// A single zero-width look-around. 
1357+ #[ derive( Clone ,  Debug ,  Eq ,  PartialEq ) ]  
1358+ #[ cfg_attr( feature = "arbitrary" ,  derive( arbitrary:: Arbitrary ) ) ]  
1359+ pub  struct  LookAround  { 
1360+     /// The span of this look-around. 
1361+      pub  span :  Span , 
1362+     /// The look-around kind, e.g. negative/positive look-behind. 
1363+      pub  kind :  LookAroundKind , 
1364+     /// The regular expression inside the look-around. 
1365+      pub  ast :  Box < Ast > , 
1366+ } 
1367+ 
1368+ /// A look-around kind. 
1369+ #[ derive( Clone ,  Debug ,  Eq ,  PartialEq ) ]  
1370+ #[ cfg_attr( feature = "arbitrary" ,  derive( arbitrary:: Arbitrary ) ) ]  
1371+ pub  enum  LookAroundKind  { 
1372+     /// `(?<=...)` 
1373+      PositiveLookBehind , 
1374+     /// `(?<!...)` 
1375+      NegativeLookBehind , 
1376+ } 
1377+ 
13471378/// A repetition operation applied to a regular expression. 
13481379#[ derive( Clone ,  Debug ,  Eq ,  PartialEq ) ]  
13491380#[ cfg_attr( feature = "arbitrary" ,  derive( arbitrary:: Arbitrary ) ) ]  
@@ -1649,6 +1680,7 @@ impl Drop for Ast {
16491680            | Ast :: ClassBracketed ( _)  => return , 
16501681            Ast :: Repetition ( ref  x)  if  !x. ast . has_subexprs ( )  => return , 
16511682            Ast :: Group ( ref  x)  if  !x. ast . has_subexprs ( )  => return , 
1683+             Ast :: LookAround ( ref  x)  if  !x. ast . has_subexprs ( )  => return , 
16521684            Ast :: Alternation ( ref  x)  if  x. asts . is_empty ( )  => return , 
16531685            Ast :: Concat ( ref  x)  if  x. asts . is_empty ( )  => return , 
16541686            _ => { } 
@@ -1675,6 +1707,9 @@ impl Drop for Ast {
16751707                Ast :: Group ( ref  mut  x)  => { 
16761708                    stack. push ( mem:: replace ( & mut  x. ast ,  empty_ast ( ) ) ) ; 
16771709                } 
1710+                 Ast :: LookAround ( ref  mut  x)  => { 
1711+                     stack. push ( mem:: replace ( & mut  x. ast ,  empty_ast ( ) ) ) ; 
1712+                 } 
16781713                Ast :: Alternation ( ref  mut  x)  => { 
16791714                    stack. extend ( x. asts . drain ( ..) ) ; 
16801715                } 
0 commit comments