Skip to content

Commit 171b4de

Browse files
committed
refactor: Renamed chain to then_with
1 parent 4ef61c8 commit 171b4de

5 files changed

Lines changed: 19 additions & 13 deletions

File tree

rusty_parser/src/pc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod and;
44
mod and_without_undo;
55
mod any;
66
pub mod boxed;
7-
mod chain;
87
mod delimited;
98
mod filter;
109
mod filter_map;
@@ -26,13 +25,13 @@ mod row_col_view;
2625
mod seq;
2726
mod string_view;
2827
pub mod supplier;
28+
mod then_with;
2929
mod to_option;
3030
mod tokenizers;
3131

3232
pub use and::*;
3333
pub use and_without_undo::AndWithoutUndo;
3434
pub use any::*;
35-
pub use chain::*;
3635
pub use delimited::*;
3736
pub use filter::Filter;
3837
pub use filter_map::FilterMap;
@@ -49,5 +48,6 @@ pub use parse_result::*;
4948
pub use parsers::*;
5049
pub use seq::*;
5150
pub use string_view::RcStringView;
51+
pub use then_with::*;
5252
pub use to_option::ToOption;
5353
pub use tokenizers::*;
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
use crate::error::ParseError;
22
use crate::pc::{ParseResult, ParseResultTrait, Parser};
33

4-
pub trait Chain<I>: Parser<I>
4+
/// Similar to `and_without_undo`, but the right parser is created dynamically
5+
/// based on the result of the first parser.
6+
pub trait ThenWith<I>: Parser<I>
57
where
68
Self: Sized,
79
{
8-
fn chain<RF, R, F, O>(self, right_factory: RF, combiner: F) -> impl Parser<I, Output = O>
10+
/// Similar to `and_without_undo`, but the right parser is created dynamically
11+
/// based on the result of the first parser.
12+
fn then_with<RF, R, F, O>(self, right_factory: RF, combiner: F) -> impl Parser<I, Output = O>
913
where
1014
RF: Fn(&Self::Output) -> R,
1115
R: Parser<I>,
1216
F: Fn(Self::Output, R::Output) -> O,
1317
{
14-
ChainParser::new(self, right_factory, combiner)
18+
ThenWithParser::new(self, right_factory, combiner)
1519
}
1620
}
1721

18-
impl<I, P> Chain<I> for P where P: Parser<I> {}
22+
impl<I, P> ThenWith<I> for P where P: Parser<I> {}
1923

20-
struct ChainParser<L, R, F> {
24+
struct ThenWithParser<L, R, F> {
2125
left: L,
2226
right: R,
2327
combiner: F,
2428
}
25-
impl<L, R, F> ChainParser<L, R, F> {
29+
impl<L, R, F> ThenWithParser<L, R, F> {
2630
pub fn new(left: L, right: R, combiner: F) -> Self {
2731
Self {
2832
left,
@@ -32,7 +36,7 @@ impl<L, R, F> ChainParser<L, R, F> {
3236
}
3337
}
3438

35-
impl<I, L, RF, R, F, O> Parser<I> for ChainParser<L, RF, F>
39+
impl<I, L, RF, R, F, O> Parser<I> for ThenWithParser<L, RF, F>
3640
where
3741
L: Parser<I>,
3842
RF: Fn(&L::Output) -> R,

rusty_parser/src/specific/core/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ fn preceded_by_ws(
542542
fn followed_by_ws(
543543
parser: impl Parser<RcStringView, Output = ExpressionPos>,
544544
) -> impl Parser<RcStringView, Output = ExpressionPos> {
545-
parser.chain(
545+
parser.then_with(
546546
|expr_pos| {
547547
let is_paren = expr_pos.is_parenthesis();
548548
conditionally_opt_whitespace(is_paren).no_incomplete()

rusty_parser/src/specific/core/opt_second_expression.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::error::ParseError;
22
use crate::pc::boxed::boxed;
3-
use crate::pc::{And, AndWithoutUndo, Chain, Errors, Map, Parser, RcStringView, ToOption, Token};
3+
use crate::pc::{
4+
And, AndWithoutUndo, Errors, Map, Parser, RcStringView, ThenWith, ToOption, Token,
5+
};
46
use crate::specific::core::expression::ws_expr_pos_p;
57
use crate::specific::pc_specific::{keyword, opt_whitespace, whitespace};
68
use crate::specific::{ExpressionPos, Keyword};
@@ -20,7 +22,7 @@ where
2022
P: Parser<RcStringView>,
2123
F: Fn(&P::Output) -> bool,
2224
{
23-
first_parser.chain(
25+
first_parser.then_with(
2426
move |first| {
2527
let is_paren = is_first_wrapped_in_parenthesis(&first);
2628
parse_second(keyword, is_paren).to_option()

rusty_parser/src/specific/core/var_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ where
111111
T: Clone + Default + VarType + CreateArray<ArrayDimensions = A> + 'static,
112112
P: Parser<RcStringView, Output = T> + 'static,
113113
{
114-
Seq2::new(name_with_dots(), array_p).chain(
114+
Seq2::new(name_with_dots(), array_p).then_with(
115115
move |(name, _)| name_chain(name, built_in_extended_factory),
116116
|(name, array), var_type| {
117117
let bare_name: BareName = name.to_bare_name();

0 commit comments

Comments
 (0)