@@ -1195,21 +1195,16 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
11951195 ) ) ;
11961196 }
11971197 let inner_span = self . span ( ) ;
1198- let mut has_p = false ;
1199- if self . bump_if ( "?<" ) || {
1200- has_p = true ;
1201- self . bump_if ( "?P <" )
1198+ let mut starts_with_p = true ;
1199+ if self . bump_if ( "?P <" ) || {
1200+ starts_with_p = false ;
1201+ self . bump_if ( "?<" )
12021202 } {
12031203 let capture_index = self . next_capture_index ( open_span) ?;
1204- let cap = self . parse_capture_name ( capture_index) ?;
1205- let kind = if has_p {
1206- ast:: GroupKind :: CapturePName
1207- } else {
1208- ast:: GroupKind :: CaptureName
1209- } ;
1204+ let name = self . parse_capture_name ( capture_index) ?;
12101205 Ok ( Either :: Right ( ast:: Group {
12111206 span : open_span,
1212- kind : kind ( cap ) ,
1207+ kind : ast :: GroupKind :: CaptureName { starts_with_p , name } ,
12131208 ast : Box :: new ( Ast :: Empty ( self . span ( ) ) ) ,
12141209 } ) )
12151210 } else if self . bump_if ( "?" ) {
@@ -2808,11 +2803,14 @@ bar
28082803 flag_set( pat, 0 ..4 , ast:: Flag :: IgnoreWhitespace , false ) ,
28092804 Ast :: Group ( ast:: Group {
28102805 span: span_range( pat, 4 ..pat. len( ) ) ,
2811- kind: ast:: GroupKind :: CapturePName ( ast:: CaptureName {
2812- span: span_range( pat, 9 ..12 ) ,
2813- name: s( "foo" ) ,
2814- index: 1 ,
2815- } ) ,
2806+ kind: ast:: GroupKind :: CaptureName {
2807+ starts_with_p: true ,
2808+ name: ast:: CaptureName {
2809+ span: span_range( pat, 9 ..12 ) ,
2810+ name: s( "foo" ) ,
2811+ index: 1 ,
2812+ }
2813+ } ,
28162814 ast: Box :: new( lit_with( 'a' , span_range( pat, 14 ..15 ) ) ) ,
28172815 } ) ,
28182816 ]
@@ -3831,23 +3829,29 @@ bar
38313829 parser( "(?P<a>z)" ) . parse( ) ,
38323830 Ok ( Ast :: Group ( ast:: Group {
38333831 span: span( 0 ..8 ) ,
3834- kind: ast:: GroupKind :: CapturePName ( ast:: CaptureName {
3835- span: span( 4 ..5 ) ,
3836- name: s( "a" ) ,
3837- index: 1 ,
3838- } ) ,
3832+ kind: ast:: GroupKind :: CaptureName {
3833+ starts_with_p: true ,
3834+ name: ast:: CaptureName {
3835+ span: span( 4 ..5 ) ,
3836+ name: s( "a" ) ,
3837+ index: 1 ,
3838+ }
3839+ } ,
38393840 ast: Box :: new( lit( 'z' , 6 ) ) ,
38403841 } ) )
38413842 ) ;
38423843 assert_eq ! (
38433844 parser( "(?P<abc>z)" ) . parse( ) ,
38443845 Ok ( Ast :: Group ( ast:: Group {
38453846 span: span( 0 ..10 ) ,
3846- kind: ast:: GroupKind :: CapturePName ( ast:: CaptureName {
3847- span: span( 4 ..7 ) ,
3848- name: s( "abc" ) ,
3849- index: 1 ,
3850- } ) ,
3847+ kind: ast:: GroupKind :: CaptureName {
3848+ starts_with_p: true ,
3849+ name: ast:: CaptureName {
3850+ span: span( 4 ..7 ) ,
3851+ name: s( "abc" ) ,
3852+ index: 1 ,
3853+ }
3854+ } ,
38513855 ast: Box :: new( lit( 'z' , 8 ) ) ,
38523856 } ) )
38533857 ) ;
@@ -3856,11 +3860,14 @@ bar
38563860 parser( "(?P<a_1>z)" ) . parse( ) ,
38573861 Ok ( Ast :: Group ( ast:: Group {
38583862 span: span( 0 ..10 ) ,
3859- kind: ast:: GroupKind :: CapturePName ( ast:: CaptureName {
3860- span: span( 4 ..7 ) ,
3861- name: s( "a_1" ) ,
3862- index: 1 ,
3863- } ) ,
3863+ kind: ast:: GroupKind :: CaptureName {
3864+ starts_with_p: true ,
3865+ name: ast:: CaptureName {
3866+ span: span( 4 ..7 ) ,
3867+ name: s( "a_1" ) ,
3868+ index: 1 ,
3869+ }
3870+ } ,
38643871 ast: Box :: new( lit( 'z' , 8 ) ) ,
38653872 } ) )
38663873 ) ;
@@ -3869,11 +3876,14 @@ bar
38693876 parser( "(?P<a.1>z)" ) . parse( ) ,
38703877 Ok ( Ast :: Group ( ast:: Group {
38713878 span: span( 0 ..10 ) ,
3872- kind: ast:: GroupKind :: CapturePName ( ast:: CaptureName {
3873- span: span( 4 ..7 ) ,
3874- name: s( "a.1" ) ,
3875- index: 1 ,
3876- } ) ,
3879+ kind: ast:: GroupKind :: CaptureName {
3880+ starts_with_p: true ,
3881+ name: ast:: CaptureName {
3882+ span: span( 4 ..7 ) ,
3883+ name: s( "a.1" ) ,
3884+ index: 1 ,
3885+ }
3886+ } ,
38773887 ast: Box :: new( lit( 'z' , 8 ) ) ,
38783888 } ) )
38793889 ) ;
@@ -3882,11 +3892,14 @@ bar
38823892 parser( "(?P<a[1]>z)" ) . parse( ) ,
38833893 Ok ( Ast :: Group ( ast:: Group {
38843894 span: span( 0 ..11 ) ,
3885- kind: ast:: GroupKind :: CapturePName ( ast:: CaptureName {
3886- span: span( 4 ..8 ) ,
3887- name: s( "a[1]" ) ,
3888- index: 1 ,
3889- } ) ,
3895+ kind: ast:: GroupKind :: CaptureName {
3896+ starts_with_p: true ,
3897+ name: ast:: CaptureName {
3898+ span: span( 4 ..8 ) ,
3899+ name: s( "a[1]" ) ,
3900+ index: 1 ,
3901+ }
3902+ } ,
38903903 ast: Box :: new( lit( 'z' , 9 ) ) ,
38913904 } ) )
38923905 ) ;
0 commit comments