@@ -554,7 +554,6 @@ fn eager_expression_pos_p() -> impl Parser<StringView, Output = ExpressionPos, E
554554}
555555
556556mod single_or_double_literal {
557- use rusty_pc:: and:: opt_and_tuple;
558557 use rusty_pc:: * ;
559558
560559 use crate :: input:: StringView ;
@@ -570,36 +569,36 @@ mod single_or_double_literal {
570569 // TODO support more qualifiers besides '#'
571570
572571 pub fn parser ( ) -> impl Parser < StringView , Output = ExpressionPos , Error = ParserError > {
573- // TODO this is difficult to understand
574- opt_and_tuple (
575- // read integer digits optionally (might start with . e.g. `.123`)
576- digits ( ) ,
572+ // read integer digits optionally (might start with . e.g. `.123`)
573+ digits ( )
574+ . to_option ( )
577575 // read dot and demand digits after decimal point
578576 // if dot is missing, the parser returns an empty result
579577 // the "deal breaker" is therefore the dot
580- dot ( ) . and_keep_right ( digits ( ) . to_fatal ( ) ) ,
581- )
582- // and parse optionally a type qualifier such as `#`
583- . and_tuple ( pound ( ) . to_option ( ) )
584- // done parsing, flat map everything
585- . and_then ( |( ( opt_integer_digits, frac_digits) , opt_pound) | {
586- let left = opt_integer_digits
587- . map ( |token| token. to_string ( ) )
588- . unwrap_or_else ( || "0" . to_owned ( ) ) ;
589- let s = format ! ( "{}.{}" , left, frac_digits. as_str( ) ) ;
590- if opt_pound. is_some ( ) {
591- match s. parse :: < f64 > ( ) {
592- Ok ( f) => Ok ( Expression :: DoubleLiteral ( f) ) ,
593- Err ( err) => Err ( err. into ( ) ) ,
594- }
595- } else {
596- match s. parse :: < f32 > ( ) {
597- Ok ( f) => Ok ( Expression :: SingleLiteral ( f) ) ,
598- Err ( err) => Err ( err. into ( ) ) ,
578+ . and_keep_left ( dot ( ) )
579+ // demand digits after decimal point
580+ . and_tuple ( digits ( ) . to_fatal ( ) )
581+ // and parse optionally a type qualifier such as `#`
582+ . and_tuple ( pound ( ) . to_option ( ) )
583+ // done parsing, flat map everything
584+ . and_then ( |( ( opt_integer_digits, frac_digits) , opt_pound) | {
585+ let left = opt_integer_digits
586+ . map ( |token| token. to_string ( ) )
587+ . unwrap_or_else ( || "0" . to_owned ( ) ) ;
588+ let s = format ! ( "{}.{}" , left, frac_digits. as_str( ) ) ;
589+ if opt_pound. is_some ( ) {
590+ match s. parse :: < f64 > ( ) {
591+ Ok ( f) => Ok ( Expression :: DoubleLiteral ( f) ) ,
592+ Err ( err) => Err ( err. into ( ) ) ,
593+ }
594+ } else {
595+ match s. parse :: < f32 > ( ) {
596+ Ok ( f) => Ok ( Expression :: SingleLiteral ( f) ) ,
597+ Err ( err) => Err ( err. into ( ) ) ,
598+ }
599599 }
600- }
601- } )
602- . with_pos ( )
600+ } )
601+ . with_pos ( )
603602 }
604603}
605604
@@ -998,16 +997,16 @@ mod built_in_function_call {
998997
999998mod binary_expression {
1000999 use rusty_common:: Positioned ;
1001- use rusty_pc:: and:: { TupleCombiner , opt_and_keep_right } ;
1000+ use rusty_pc:: and:: TupleCombiner ;
10021001 use rusty_pc:: * ;
10031002
10041003 use super :: {
10051004 built_in_function_call, expression_pos_p, guard, integer_or_long_literal, parenthesis, property, single_or_double_literal, string_literal, unary_expression
10061005 } ;
10071006 use crate :: error:: ParserError ;
10081007 use crate :: input:: StringView ;
1009- use crate :: pc_specific:: { OrExpected , WithPos } ;
1010- use crate :: tokens:: { TokenType , any_token, whitespace_ignoring } ;
1008+ use crate :: pc_specific:: { OrExpected , WithPos , lead_opt_ws , lead_ws } ;
1009+ use crate :: tokens:: { TokenType , any_token} ;
10111010 use crate :: * ;
10121011
10131012 // result ::= <non-bin-expr> <operator> <expr>
@@ -1078,14 +1077,9 @@ mod binary_expression {
10781077 -> impl Parser < StringView , bool , Output = Positioned < Operator > , Error = ParserError > {
10791078 IifParser :: new (
10801079 // no whitespace needed
1081- opt_and_keep_right ( whitespace_ignoring ( ) , operator_p ( ) ) ,
1080+ lead_opt_ws ( operator_p ( ) ) ,
10821081 // whitespace needed
1083- whitespace_ignoring ( )
1084- . and_keep_right ( operator_p ( ) )
1085- . or ( opt_and_keep_right (
1086- whitespace_ignoring ( ) ,
1087- symbol_operator_p ( ) ,
1088- ) ) ,
1082+ lead_ws ( operator_p ( ) ) . or ( lead_opt_ws ( symbol_operator_p ( ) ) ) ,
10891083 )
10901084 }
10911085
@@ -1201,7 +1195,7 @@ pub mod file_handle {
12011195 use crate :: error:: ParserError ;
12021196 use crate :: input:: StringView ;
12031197 use crate :: pc_specific:: * ;
1204- use crate :: tokens:: { TokenType , any_token_of, pound, whitespace_ignoring } ;
1198+ use crate :: tokens:: { TokenType , any_token_of, pound} ;
12051199 use crate :: * ;
12061200
12071201 pub fn file_handle_p ( )
@@ -1230,7 +1224,7 @@ pub mod file_handle {
12301224 }
12311225
12321226 fn ws_file_handle ( ) -> impl Parser < StringView , Output = ExpressionPos , Error = ParserError > {
1233- whitespace_ignoring ( ) . and_keep_right ( file_handle_as_expression_pos_p ( ) )
1227+ lead_ws ( file_handle_as_expression_pos_p ( ) )
12341228 }
12351229}
12361230
@@ -1239,8 +1233,8 @@ pub mod guard {
12391233
12401234 use crate :: ParserError ;
12411235 use crate :: input:: StringView ;
1242- use crate :: pc_specific:: WithExpected ;
1243- use crate :: tokens:: { any_symbol_of, any_token_of, whitespace_ignoring } ;
1236+ use crate :: pc_specific:: { WithExpected , whitespace_ignoring } ;
1237+ use crate :: tokens:: { any_symbol_of, any_token_of} ;
12441238
12451239 /// `result ::= " " | "("`
12461240 ///
0 commit comments