@@ -5,14 +5,13 @@ use codspeed_criterion_compat::*;
5
5
use nom:: {
6
6
branch:: alt,
7
7
bytes:: { tag, take} ,
8
- character:: { anychar , char, multispace0, none_of} ,
9
- combinator:: { map, map_opt, map_res, value, verify} ,
8
+ character:: { char, multispace0, none_of} ,
9
+ combinator:: { map, map_opt, map_res, success , value, verify} ,
10
10
error:: { Error , ErrorKind , FromExternalError , ParseError } ,
11
11
multi:: { fold, separated_list0} ,
12
- number:: double,
13
- number:: recognize_float,
12
+ number:: { double, recognize_float} ,
14
13
sequence:: { delimited, preceded, separated_pair} ,
15
- Check , Complete , Emit , IResult , Mode , OutputM , Parser ,
14
+ Check , Complete , Either , Emit , IResult , OutputM , Parser ,
16
15
} ;
17
16
use nom_language:: error:: VerboseError ;
18
17
@@ -68,69 +67,22 @@ fn character<
68
67
' a ,
69
68
E : ParseError < & ' a str > + FromExternalError < & ' a str , ParseIntError > + FromExternalError < & ' a str , ( ) > ,
70
69
> ( ) -> impl Parser < & ' a str , Output = char , Error = E > {
71
- Character { e : PhantomData }
72
- /*let (input, c) = none_of("\"")(input)?;
73
- if c == '\\' {
74
- alt((
75
- map_res(anychar, |c| {
76
- Ok(match c {
77
- '"' | '\\' | '/' => c,
78
- 'b' => '\x08',
79
- 'f' => '\x0C',
80
- 'n' => '\n',
81
- 'r' => '\r',
82
- 't' => '\t',
83
- _ => return Err(()),
84
- })
85
- }),
86
- preceded(char('u'), unicode_escape()),
87
- ))
88
- .parse(input)
89
- } else {
90
- Ok((input, c))
91
- }*/
92
- }
93
-
94
- struct Character < E > {
95
- e : PhantomData < E > ,
96
- }
97
-
98
- impl < ' a , E > Parser < & ' a str > for Character < E >
99
- where
100
- E : ParseError < & ' a str >
101
- + FromExternalError < & ' a str , ParseIntError >
102
- + FromExternalError < & ' a str , ( ) > ,
103
- {
104
- type Output = char ;
105
-
106
- type Error = E ;
107
-
108
- fn process < OM : nom:: OutputMode > (
109
- & mut self ,
110
- input : & ' a str ,
111
- ) -> nom:: PResult < OM , & ' a str , Self :: Output , Self :: Error > {
112
- let ( input, c) : ( & str , char ) =
113
- none_of ( "\" " ) . process :: < OutputM < Emit , OM :: Error , OM :: Incomplete > > ( input) ?;
114
- if c == '\\' {
115
- alt ( (
116
- map_res ( anychar, |c| {
117
- Ok ( match c {
118
- '"' | '\\' | '/' => c,
119
- 'b' => '\x08' ,
120
- 'f' => '\x0C' ,
121
- 'n' => '\n' ,
122
- 'r' => '\r' ,
123
- 't' => '\t' ,
124
- _ => return Err ( ( ) ) ,
125
- } )
126
- } ) ,
127
- preceded ( char ( 'u' ) , unicode_escape ( ) ) ,
128
- ) )
129
- . process :: < OM > ( input)
70
+ none_of ( "\" " ) . flat_map ( |c| {
71
+ if c != '\\' {
72
+ Either :: Left ( success ( c) )
130
73
} else {
131
- Ok ( ( input, OM :: Output :: bind ( || c) ) )
74
+ Either :: Right ( alt ( (
75
+ value ( '\\' , tag ( "\\ " ) ) ,
76
+ value ( '\"' , tag ( "\" " ) ) ,
77
+ value ( '\n' , tag ( "n" ) ) ,
78
+ value ( '\r' , tag ( "r" ) ) ,
79
+ value ( '\t' , tag ( "t" ) ) ,
80
+ value ( '\x08' , tag ( "b" ) ) ,
81
+ value ( '\x0C' , tag ( "f" ) ) ,
82
+ preceded ( char ( 'u' ) , unicode_escape ( ) ) ,
83
+ ) ) )
132
84
}
133
- }
85
+ } )
134
86
}
135
87
136
88
fn string <
0 commit comments