@@ -173,7 +173,7 @@ enum HirFrame {
173
173
/// This sentinel only exists to stop other things (like flattening
174
174
/// literals) from reaching across repetition operators.
175
175
Repetition ,
176
- /// This is pushed on to the stack upon first seeing any kind of group ,
176
+ /// This is pushed on to the stack upon first seeing any kind of capture ,
177
177
/// indicated by parentheses (including non-capturing groups). It is popped
178
178
/// upon leaving a group.
179
179
Group {
@@ -414,7 +414,7 @@ impl<'t, 'p> Visitor for TranslatorI<'t, 'p> {
414
414
let expr = self . pop ( ) . unwrap ( ) . unwrap_expr ( ) ;
415
415
let old_flags = self . pop ( ) . unwrap ( ) . unwrap_group ( ) ;
416
416
self . trans ( ) . flags . set ( old_flags) ;
417
- self . push ( HirFrame :: Expr ( self . hir_group ( x, expr) ) ) ;
417
+ self . push ( HirFrame :: Expr ( self . hir_capture ( x, expr) ) ) ;
418
418
}
419
419
Ast :: Concat ( _) => {
420
420
let mut exprs = vec ! [ ] ;
@@ -902,7 +902,7 @@ impl<'t, 'p> TranslatorI<'t, 'p> {
902
902
} )
903
903
}
904
904
905
- fn hir_group ( & self , group : & ast:: Group , expr : Hir ) -> Hir {
905
+ fn hir_capture ( & self , group : & ast:: Group , expr : Hir ) -> Hir {
906
906
let ( index, name) = match group. kind {
907
907
ast:: GroupKind :: CaptureIndex ( index) => ( index, None ) ,
908
908
ast:: GroupKind :: CaptureName { ref name, .. } => {
@@ -912,7 +912,7 @@ impl<'t, 'p> TranslatorI<'t, 'p> {
912
912
// in which the data type is defined handles this automatically.
913
913
ast:: GroupKind :: NonCapturing ( _) => return expr,
914
914
} ;
915
- Hir :: group ( hir:: Group { index, name, hir : Box :: new ( expr) } )
915
+ Hir :: capture ( hir:: Capture { index, name, hir : Box :: new ( expr) } )
916
916
}
917
917
918
918
fn hir_repetition ( & self , rep : & ast:: Repetition , expr : Hir ) -> Hir {
@@ -1352,12 +1352,12 @@ mod tests {
1352
1352
Hir :: literal ( s)
1353
1353
}
1354
1354
1355
- fn hir_group ( index : u32 , expr : Hir ) -> Hir {
1356
- Hir :: group ( hir:: Group { index, name : None , hir : Box :: new ( expr) } )
1355
+ fn hir_capture ( index : u32 , expr : Hir ) -> Hir {
1356
+ Hir :: capture ( hir:: Capture { index, name : None , hir : Box :: new ( expr) } )
1357
1357
}
1358
1358
1359
- fn hir_group_name ( index : u32 , name : & str , expr : Hir ) -> Hir {
1360
- Hir :: group ( hir:: Group {
1359
+ fn hir_capture_name ( index : u32 , name : & str , expr : Hir ) -> Hir {
1360
+ Hir :: capture ( hir:: Capture {
1361
1361
index,
1362
1362
name : Some ( name. into ( ) ) ,
1363
1363
hir : Box :: new ( expr) ,
@@ -1528,35 +1528,35 @@ mod tests {
1528
1528
fn empty ( ) {
1529
1529
assert_eq ! ( t( "" ) , Hir :: empty( ) ) ;
1530
1530
assert_eq ! ( t( "(?i)" ) , Hir :: empty( ) ) ;
1531
- assert_eq ! ( t( "()" ) , hir_group ( 1 , Hir :: empty( ) ) ) ;
1531
+ assert_eq ! ( t( "()" ) , hir_capture ( 1 , Hir :: empty( ) ) ) ;
1532
1532
assert_eq ! ( t( "(?:)" ) , Hir :: empty( ) ) ;
1533
- assert_eq ! ( t( "(?P<wat>)" ) , hir_group_name ( 1 , "wat" , Hir :: empty( ) ) ) ;
1533
+ assert_eq ! ( t( "(?P<wat>)" ) , hir_capture_name ( 1 , "wat" , Hir :: empty( ) ) ) ;
1534
1534
assert_eq ! ( t( "|" ) , hir_alt( vec![ Hir :: empty( ) , Hir :: empty( ) ] ) ) ;
1535
1535
assert_eq ! (
1536
1536
t( "()|()" ) ,
1537
1537
hir_alt( vec![
1538
- hir_group ( 1 , Hir :: empty( ) ) ,
1539
- hir_group ( 2 , Hir :: empty( ) ) ,
1538
+ hir_capture ( 1 , Hir :: empty( ) ) ,
1539
+ hir_capture ( 2 , Hir :: empty( ) ) ,
1540
1540
] )
1541
1541
) ;
1542
1542
assert_eq ! (
1543
1543
t( "(|b)" ) ,
1544
- hir_group ( 1 , hir_alt( vec![ Hir :: empty( ) , hir_lit( "b" ) , ] ) )
1544
+ hir_capture ( 1 , hir_alt( vec![ Hir :: empty( ) , hir_lit( "b" ) , ] ) )
1545
1545
) ;
1546
1546
assert_eq ! (
1547
1547
t( "(a|)" ) ,
1548
- hir_group ( 1 , hir_alt( vec![ hir_lit( "a" ) , Hir :: empty( ) , ] ) )
1548
+ hir_capture ( 1 , hir_alt( vec![ hir_lit( "a" ) , Hir :: empty( ) , ] ) )
1549
1549
) ;
1550
1550
assert_eq ! (
1551
1551
t( "(a||c)" ) ,
1552
- hir_group (
1552
+ hir_capture (
1553
1553
1 ,
1554
1554
hir_alt( vec![ hir_lit( "a" ) , Hir :: empty( ) , hir_lit( "c" ) , ] )
1555
1555
)
1556
1556
) ;
1557
1557
assert_eq ! (
1558
1558
t( "(||)" ) ,
1559
- hir_group (
1559
+ hir_capture (
1560
1560
1 ,
1561
1561
hir_alt( vec![ Hir :: empty( ) , Hir :: empty( ) , Hir :: empty( ) , ] )
1562
1562
)
@@ -1740,56 +1740,59 @@ mod tests {
1740
1740
1741
1741
#[ test]
1742
1742
fn group ( ) {
1743
- assert_eq ! ( t( "(a)" ) , hir_group ( 1 , hir_lit( "a" ) ) ) ;
1743
+ assert_eq ! ( t( "(a)" ) , hir_capture ( 1 , hir_lit( "a" ) ) ) ;
1744
1744
assert_eq ! (
1745
1745
t( "(a)(b)" ) ,
1746
1746
hir_cat( vec![
1747
- hir_group ( 1 , hir_lit( "a" ) ) ,
1748
- hir_group ( 2 , hir_lit( "b" ) ) ,
1747
+ hir_capture ( 1 , hir_lit( "a" ) ) ,
1748
+ hir_capture ( 2 , hir_lit( "b" ) ) ,
1749
1749
] )
1750
1750
) ;
1751
1751
assert_eq ! (
1752
1752
t( "(a)|(b)" ) ,
1753
1753
hir_alt( vec![
1754
- hir_group ( 1 , hir_lit( "a" ) ) ,
1755
- hir_group ( 2 , hir_lit( "b" ) ) ,
1754
+ hir_capture ( 1 , hir_lit( "a" ) ) ,
1755
+ hir_capture ( 2 , hir_lit( "b" ) ) ,
1756
1756
] )
1757
1757
) ;
1758
- assert_eq ! ( t( "(?P<foo>)" ) , hir_group_name ( 1 , "foo" , Hir :: empty( ) ) ) ;
1759
- assert_eq ! ( t( "(?P<foo>a)" ) , hir_group_name ( 1 , "foo" , hir_lit( "a" ) ) ) ;
1758
+ assert_eq ! ( t( "(?P<foo>)" ) , hir_capture_name ( 1 , "foo" , Hir :: empty( ) ) ) ;
1759
+ assert_eq ! ( t( "(?P<foo>a)" ) , hir_capture_name ( 1 , "foo" , hir_lit( "a" ) ) ) ;
1760
1760
assert_eq ! (
1761
1761
t( "(?P<foo>a)(?P<bar>b)" ) ,
1762
1762
hir_cat( vec![
1763
- hir_group_name ( 1 , "foo" , hir_lit( "a" ) ) ,
1764
- hir_group_name ( 2 , "bar" , hir_lit( "b" ) ) ,
1763
+ hir_capture_name ( 1 , "foo" , hir_lit( "a" ) ) ,
1764
+ hir_capture_name ( 2 , "bar" , hir_lit( "b" ) ) ,
1765
1765
] )
1766
1766
) ;
1767
1767
assert_eq ! ( t( "(?:)" ) , Hir :: empty( ) ) ;
1768
1768
assert_eq ! ( t( "(?:a)" ) , hir_lit( "a" ) ) ;
1769
1769
assert_eq ! (
1770
1770
t( "(?:a)(b)" ) ,
1771
- hir_cat( vec![ hir_lit( "a" ) , hir_group ( 1 , hir_lit( "b" ) ) , ] )
1771
+ hir_cat( vec![ hir_lit( "a" ) , hir_capture ( 1 , hir_lit( "b" ) ) , ] )
1772
1772
) ;
1773
1773
assert_eq ! (
1774
1774
t( "(a)(?:b)(c)" ) ,
1775
1775
hir_cat( vec![
1776
- hir_group ( 1 , hir_lit( "a" ) ) ,
1776
+ hir_capture ( 1 , hir_lit( "a" ) ) ,
1777
1777
hir_lit( "b" ) ,
1778
- hir_group ( 2 , hir_lit( "c" ) ) ,
1778
+ hir_capture ( 2 , hir_lit( "c" ) ) ,
1779
1779
] )
1780
1780
) ;
1781
1781
assert_eq ! (
1782
1782
t( "(a)(?P<foo>b)(c)" ) ,
1783
1783
hir_cat( vec![
1784
- hir_group ( 1 , hir_lit( "a" ) ) ,
1785
- hir_group_name ( 2 , "foo" , hir_lit( "b" ) ) ,
1786
- hir_group ( 3 , hir_lit( "c" ) ) ,
1784
+ hir_capture ( 1 , hir_lit( "a" ) ) ,
1785
+ hir_capture_name ( 2 , "foo" , hir_lit( "b" ) ) ,
1786
+ hir_capture ( 3 , hir_lit( "c" ) ) ,
1787
1787
] )
1788
1788
) ;
1789
- assert_eq ! ( t( "()" ) , hir_group( 1 , Hir :: empty( ) ) ) ;
1790
- assert_eq ! ( t( "((?i))" ) , hir_group( 1 , Hir :: empty( ) ) ) ;
1791
- assert_eq ! ( t( "((?x))" ) , hir_group( 1 , Hir :: empty( ) ) ) ;
1792
- assert_eq ! ( t( "(((?x)))" ) , hir_group( 1 , hir_group( 2 , Hir :: empty( ) ) ) ) ;
1789
+ assert_eq ! ( t( "()" ) , hir_capture( 1 , Hir :: empty( ) ) ) ;
1790
+ assert_eq ! ( t( "((?i))" ) , hir_capture( 1 , Hir :: empty( ) ) ) ;
1791
+ assert_eq ! ( t( "((?x))" ) , hir_capture( 1 , Hir :: empty( ) ) ) ;
1792
+ assert_eq ! (
1793
+ t( "(((?x)))" ) ,
1794
+ hir_capture( 1 , hir_capture( 2 , Hir :: empty( ) ) )
1795
+ ) ;
1793
1796
}
1794
1797
1795
1798
#[ test]
@@ -1818,7 +1821,7 @@ mod tests {
1818
1821
assert_eq ! (
1819
1822
t( "((?i-u)a)b" ) ,
1820
1823
hir_cat( vec![
1821
- hir_group ( 1 , hir_bclass( & [ ( b'A' , b'A' ) , ( b'a' , b'a' ) ] ) ) ,
1824
+ hir_capture ( 1 , hir_bclass( & [ ( b'A' , b'A' ) , ( b'a' , b'a' ) ] ) ) ,
1822
1825
hir_lit( "b" ) ,
1823
1826
] )
1824
1827
) ;
@@ -1908,7 +1911,7 @@ mod tests {
1908
1911
t( "ab?" ) ,
1909
1912
hir_cat( vec![ hir_lit( "a" ) , hir_quest( true , hir_lit( "b" ) ) , ] )
1910
1913
) ;
1911
- assert_eq ! ( t( "(ab)?" ) , hir_quest( true , hir_group ( 1 , hir_lit( "ab" ) ) ) ) ;
1914
+ assert_eq ! ( t( "(ab)?" ) , hir_quest( true , hir_capture ( 1 , hir_lit( "ab" ) ) ) ) ;
1912
1915
assert_eq ! (
1913
1916
t( "a|b?" ) ,
1914
1917
hir_alt( vec![ hir_lit( "a" ) , hir_quest( true , hir_lit( "b" ) ) , ] )
@@ -1922,7 +1925,7 @@ mod tests {
1922
1925
let c = || hir_look ( hir:: Look :: WordUnicode ) ;
1923
1926
let d = || hir_look ( hir:: Look :: WordUnicodeNegate ) ;
1924
1927
1925
- assert_eq ! ( t( "(^$)" ) , hir_group ( 1 , hir_cat( vec![ a( ) , b( ) ] ) ) ) ;
1928
+ assert_eq ! ( t( "(^$)" ) , hir_capture ( 1 , hir_cat( vec![ a( ) , b( ) ] ) ) ) ;
1926
1929
assert_eq ! ( t( "^|$" ) , hir_alt( vec![ a( ) , b( ) ] ) ) ;
1927
1930
assert_eq ! ( t( r"^|$|\b" ) , hir_alt( vec![ a( ) , b( ) , c( ) ] ) ) ;
1928
1931
assert_eq ! (
@@ -1933,11 +1936,14 @@ mod tests {
1933
1936
hir_cat( vec![ c( ) , d( ) ] ) ,
1934
1937
] )
1935
1938
) ;
1936
- assert_eq ! ( t( "(^|$)" ) , hir_group( 1 , hir_alt( vec![ a( ) , b( ) ] ) ) ) ;
1937
- assert_eq ! ( t( r"(^|$|\b)" ) , hir_group( 1 , hir_alt( vec![ a( ) , b( ) , c( ) ] ) ) ) ;
1939
+ assert_eq ! ( t( "(^|$)" ) , hir_capture( 1 , hir_alt( vec![ a( ) , b( ) ] ) ) ) ;
1940
+ assert_eq ! (
1941
+ t( r"(^|$|\b)" ) ,
1942
+ hir_capture( 1 , hir_alt( vec![ a( ) , b( ) , c( ) ] ) )
1943
+ ) ;
1938
1944
assert_eq ! (
1939
1945
t( r"(^$|$\b|\b\B)" ) ,
1940
- hir_group (
1946
+ hir_capture (
1941
1947
1 ,
1942
1948
hir_alt( vec![
1943
1949
hir_cat( vec![ a( ) , b( ) ] ) ,
@@ -1948,15 +1954,15 @@ mod tests {
1948
1954
) ;
1949
1955
assert_eq ! (
1950
1956
t( r"(^$|($\b|(\b\B)))" ) ,
1951
- hir_group (
1957
+ hir_capture (
1952
1958
1 ,
1953
1959
hir_alt( vec![
1954
1960
hir_cat( vec![ a( ) , b( ) ] ) ,
1955
- hir_group (
1961
+ hir_capture (
1956
1962
2 ,
1957
1963
hir_alt( vec![
1958
1964
hir_cat( vec![ b( ) , c( ) ] ) ,
1959
- hir_group ( 3 , hir_cat( vec![ c( ) , d( ) ] ) ) ,
1965
+ hir_capture ( 3 , hir_cat( vec![ c( ) , d( ) ] ) ) ,
1960
1966
] )
1961
1967
) ,
1962
1968
] )
0 commit comments