@@ -5,7 +5,7 @@ use crate::expr::opt_second_expression::conditionally_opt_whitespace;
55use crate :: input:: StringView ;
66use crate :: pc_specific:: * ;
77use crate :: tokens:: comma_ws;
8- use crate :: { ExpressionPos , ExpressionTrait , Expressions , ParserError } ;
8+ use crate :: { ExpressionPos , ExpressionTrait , Expressions , Keyword , ParserError } ;
99
1010/// `( expr [, expr]* )`
1111pub fn in_parenthesis_csv_expressions_non_opt (
@@ -51,22 +51,6 @@ pub fn ws_expr_pos_p() -> impl Parser<StringView, Output = ExpressionPos, Error
5151 super :: parenthesis:: parser ( ) . or ( lead_ws ( expression_pos_p ( ) ) )
5252}
5353
54- /// Parses an expression that is either followed by whitespace
55- /// or is a parenthesis expression.
56- ///
57- /// The whitespace is mandatory after a non-parenthesis
58- /// expression.
59- ///
60- /// ```text
61- /// <expr-not-in-parenthesis> <ws> |
62- /// <expr-in-parenthesis> <ws> |
63- /// <expr-in-parenthesis>
64- /// ```
65- #[ deprecated]
66- pub fn expr_pos_ws_p ( ) -> impl Parser < StringView , Output = ExpressionPos , Error = ParserError > {
67- followed_by_ws ( expression_pos_p ( ) )
68- }
69-
7054/// Parses an expression that is either surrounded by whitespace
7155/// or is a parenthesis expression.
7256///
@@ -78,6 +62,7 @@ pub fn expr_pos_ws_p() -> impl Parser<StringView, Output = ExpressionPos, Error
7862/// <ws> <expr-in-parenthesis> <ws> |
7963/// <expr-in-parenthesis>
8064/// ```
65+ #[ deprecated]
8166pub fn ws_expr_pos_ws_p ( ) -> impl Parser < StringView , Output = ExpressionPos , Error = ParserError > {
8267 followed_by_ws ( ws_expr_pos_p ( ) )
8368}
@@ -97,3 +82,41 @@ fn eager_expression_pos_p() -> impl Parser<StringView, Output = ExpressionPos, E
9782{
9883 super :: binary_expression:: parser ( )
9984}
85+
86+ /// Parses an expression,
87+ /// then demands whitespace, unless the expression is a parenthesis.
88+ /// Finally it demands the given keyword.
89+ pub fn expr_ws_keyword_p (
90+ keyword : Keyword ,
91+ ) -> impl Parser < StringView , Output = ExpressionPos , Error = ParserError > {
92+ expr_ws_followed_by ( expression_pos_p ( ) , keyword_ignoring ( keyword) )
93+ }
94+
95+ /// Parses an expression, failing fatally with the given expectation message if it can't be parsed.
96+ /// Then it demands whitespace, unless the expression is a parenthesis.
97+ /// Finally it demands the given keyword.
98+ pub fn demand_expr_ws_keyword_p (
99+ expectation : & str ,
100+ keyword : Keyword ,
101+ ) -> impl Parser < StringView , Output = ExpressionPos , Error = ParserError > {
102+ expr_ws_followed_by (
103+ expression_pos_p ( ) . or_expected ( expectation) ,
104+ keyword_ignoring ( keyword) ,
105+ )
106+ }
107+
108+ /// Parses the expression using the given parser,
109+ /// then demands whitespace, unless the expression is a parenthesis.
110+ /// Finally it demands the second parser.
111+ pub fn expr_ws_followed_by (
112+ expr_parser : impl Parser < StringView , Output = ExpressionPos , Error = ParserError > ,
113+ other_parser : impl Parser < StringView , Error = ParserError > ,
114+ ) -> impl Parser < StringView , Output = ExpressionPos , Error = ParserError > {
115+ expr_parser. then_with_in_context (
116+ conditionally_opt_whitespace ( )
117+ . to_fatal ( )
118+ . and_keep_right ( other_parser. to_fatal ( ) . no_context ( ) ) ,
119+ |e| e. is_parenthesis ( ) ,
120+ KeepLeftCombiner ,
121+ )
122+ }
0 commit comments