@@ -1202,12 +1202,16 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> {
1202
1202
) ) ;
1203
1203
}
1204
1204
let inner_span = self . span ( ) ;
1205
- if self . bump_if ( "?P<" ) {
1205
+ let mut starts_with_p = true ;
1206
+ if self . bump_if ( "?P<" ) || {
1207
+ starts_with_p = false ;
1208
+ self . bump_if ( "?<" )
1209
+ } {
1206
1210
let capture_index = self . next_capture_index ( open_span) ?;
1207
- let cap = self . parse_capture_name ( capture_index) ?;
1211
+ let name = self . parse_capture_name ( capture_index) ?;
1208
1212
Ok ( Either :: Right ( ast:: Group {
1209
1213
span : open_span,
1210
- kind : ast:: GroupKind :: CaptureName ( cap ) ,
1214
+ kind : ast:: GroupKind :: CaptureName { starts_with_p , name } ,
1211
1215
ast : Box :: new ( Ast :: Empty ( self . span ( ) ) ) ,
1212
1216
} ) )
1213
1217
} else if self . bump_if ( "?" ) {
@@ -2800,11 +2804,14 @@ bar
2800
2804
flag_set( pat, 0 ..4 , ast:: Flag :: IgnoreWhitespace , false ) ,
2801
2805
Ast :: Group ( ast:: Group {
2802
2806
span: span_range( pat, 4 ..pat. len( ) ) ,
2803
- kind: ast:: GroupKind :: CaptureName ( ast:: CaptureName {
2804
- span: span_range( pat, 9 ..12 ) ,
2805
- name: s( "foo" ) ,
2806
- index: 1 ,
2807
- } ) ,
2807
+ kind: ast:: GroupKind :: CaptureName {
2808
+ starts_with_p: true ,
2809
+ name: ast:: CaptureName {
2810
+ span: span_range( pat, 9 ..12 ) ,
2811
+ name: s( "foo" ) ,
2812
+ index: 1 ,
2813
+ }
2814
+ } ,
2808
2815
ast: Box :: new( lit_with( 'a' , span_range( pat, 14 ..15 ) ) ) ,
2809
2816
} ) ,
2810
2817
]
@@ -3819,27 +3826,48 @@ bar
3819
3826
3820
3827
#[ test]
3821
3828
fn parse_capture_name ( ) {
3829
+ assert_eq ! (
3830
+ parser( "(?<a>z)" ) . parse( ) ,
3831
+ Ok ( Ast :: Group ( ast:: Group {
3832
+ span: span( 0 ..7 ) ,
3833
+ kind: ast:: GroupKind :: CaptureName {
3834
+ starts_with_p: false ,
3835
+ name: ast:: CaptureName {
3836
+ span: span( 3 ..4 ) ,
3837
+ name: s( "a" ) ,
3838
+ index: 1 ,
3839
+ }
3840
+ } ,
3841
+ ast: Box :: new( lit( 'z' , 5 ) ) ,
3842
+ } ) )
3843
+ ) ;
3822
3844
assert_eq ! (
3823
3845
parser( "(?P<a>z)" ) . parse( ) ,
3824
3846
Ok ( Ast :: Group ( ast:: Group {
3825
3847
span: span( 0 ..8 ) ,
3826
- kind: ast:: GroupKind :: CaptureName ( ast:: CaptureName {
3827
- span: span( 4 ..5 ) ,
3828
- name: s( "a" ) ,
3829
- index: 1 ,
3830
- } ) ,
3848
+ kind: ast:: GroupKind :: CaptureName {
3849
+ starts_with_p: true ,
3850
+ name: ast:: CaptureName {
3851
+ span: span( 4 ..5 ) ,
3852
+ name: s( "a" ) ,
3853
+ index: 1 ,
3854
+ }
3855
+ } ,
3831
3856
ast: Box :: new( lit( 'z' , 6 ) ) ,
3832
3857
} ) )
3833
3858
) ;
3834
3859
assert_eq ! (
3835
3860
parser( "(?P<abc>z)" ) . parse( ) ,
3836
3861
Ok ( Ast :: Group ( ast:: Group {
3837
3862
span: span( 0 ..10 ) ,
3838
- kind: ast:: GroupKind :: CaptureName ( ast:: CaptureName {
3839
- span: span( 4 ..7 ) ,
3840
- name: s( "abc" ) ,
3841
- index: 1 ,
3842
- } ) ,
3863
+ kind: ast:: GroupKind :: CaptureName {
3864
+ starts_with_p: true ,
3865
+ name: ast:: CaptureName {
3866
+ span: span( 4 ..7 ) ,
3867
+ name: s( "abc" ) ,
3868
+ index: 1 ,
3869
+ }
3870
+ } ,
3843
3871
ast: Box :: new( lit( 'z' , 8 ) ) ,
3844
3872
} ) )
3845
3873
) ;
@@ -3848,11 +3876,14 @@ bar
3848
3876
parser( "(?P<a_1>z)" ) . parse( ) ,
3849
3877
Ok ( Ast :: Group ( ast:: Group {
3850
3878
span: span( 0 ..10 ) ,
3851
- kind: ast:: GroupKind :: CaptureName ( ast:: CaptureName {
3852
- span: span( 4 ..7 ) ,
3853
- name: s( "a_1" ) ,
3854
- index: 1 ,
3855
- } ) ,
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
+ } ,
3856
3887
ast: Box :: new( lit( 'z' , 8 ) ) ,
3857
3888
} ) )
3858
3889
) ;
@@ -3861,11 +3892,14 @@ bar
3861
3892
parser( "(?P<a.1>z)" ) . parse( ) ,
3862
3893
Ok ( Ast :: Group ( ast:: Group {
3863
3894
span: span( 0 ..10 ) ,
3864
- kind: ast:: GroupKind :: CaptureName ( ast:: CaptureName {
3865
- span: span( 4 ..7 ) ,
3866
- name: s( "a.1" ) ,
3867
- index: 1 ,
3868
- } ) ,
3895
+ kind: ast:: GroupKind :: CaptureName {
3896
+ starts_with_p: true ,
3897
+ name: ast:: CaptureName {
3898
+ span: span( 4 ..7 ) ,
3899
+ name: s( "a.1" ) ,
3900
+ index: 1 ,
3901
+ }
3902
+ } ,
3869
3903
ast: Box :: new( lit( 'z' , 8 ) ) ,
3870
3904
} ) )
3871
3905
) ;
@@ -3874,11 +3908,14 @@ bar
3874
3908
parser( "(?P<a[1]>z)" ) . parse( ) ,
3875
3909
Ok ( Ast :: Group ( ast:: Group {
3876
3910
span: span( 0 ..11 ) ,
3877
- kind: ast:: GroupKind :: CaptureName ( ast:: CaptureName {
3878
- span: span( 4 ..8 ) ,
3879
- name: s( "a[1]" ) ,
3880
- index: 1 ,
3881
- } ) ,
3911
+ kind: ast:: GroupKind :: CaptureName {
3912
+ starts_with_p: true ,
3913
+ name: ast:: CaptureName {
3914
+ span: span( 4 ..8 ) ,
3915
+ name: s( "a[1]" ) ,
3916
+ index: 1 ,
3917
+ }
3918
+ } ,
3882
3919
ast: Box :: new( lit( 'z' , 9 ) ) ,
3883
3920
} ) )
3884
3921
) ;
0 commit comments