@@ -1195,21 +1195,16 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
1195
1195
) ) ;
1196
1196
}
1197
1197
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 ( "?<" )
1202
1202
} {
1203
1203
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) ?;
1210
1205
Ok ( Either :: Right ( ast:: Group {
1211
1206
span : open_span,
1212
- kind : kind ( cap ) ,
1207
+ kind : ast :: GroupKind :: CaptureName { starts_with_p , name } ,
1213
1208
ast : Box :: new ( Ast :: Empty ( self . span ( ) ) ) ,
1214
1209
} ) )
1215
1210
} else if self . bump_if ( "?" ) {
@@ -2808,11 +2803,14 @@ bar
2808
2803
flag_set( pat, 0 ..4 , ast:: Flag :: IgnoreWhitespace , false ) ,
2809
2804
Ast :: Group ( ast:: Group {
2810
2805
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
+ } ,
2816
2814
ast: Box :: new( lit_with( 'a' , span_range( pat, 14 ..15 ) ) ) ,
2817
2815
} ) ,
2818
2816
]
@@ -3831,23 +3829,29 @@ bar
3831
3829
parser( "(?P<a>z)" ) . parse( ) ,
3832
3830
Ok ( Ast :: Group ( ast:: Group {
3833
3831
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
+ } ,
3839
3840
ast: Box :: new( lit( 'z' , 6 ) ) ,
3840
3841
} ) )
3841
3842
) ;
3842
3843
assert_eq ! (
3843
3844
parser( "(?P<abc>z)" ) . parse( ) ,
3844
3845
Ok ( Ast :: Group ( ast:: Group {
3845
3846
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
+ } ,
3851
3855
ast: Box :: new( lit( 'z' , 8 ) ) ,
3852
3856
} ) )
3853
3857
) ;
@@ -3856,11 +3860,14 @@ bar
3856
3860
parser( "(?P<a_1>z)" ) . parse( ) ,
3857
3861
Ok ( Ast :: Group ( ast:: Group {
3858
3862
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
+ } ,
3864
3871
ast: Box :: new( lit( 'z' , 8 ) ) ,
3865
3872
} ) )
3866
3873
) ;
@@ -3869,11 +3876,14 @@ bar
3869
3876
parser( "(?P<a.1>z)" ) . parse( ) ,
3870
3877
Ok ( Ast :: Group ( ast:: Group {
3871
3878
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
+ } ,
3877
3887
ast: Box :: new( lit( 'z' , 8 ) ) ,
3878
3888
} ) )
3879
3889
) ;
@@ -3882,11 +3892,14 @@ bar
3882
3892
parser( "(?P<a[1]>z)" ) . parse( ) ,
3883
3893
Ok ( Ast :: Group ( ast:: Group {
3884
3894
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
+ } ,
3890
3903
ast: Box :: new( lit( 'z' , 9 ) ) ,
3891
3904
} ) )
3892
3905
) ;
0 commit comments