Skip to content

Commit d38bbc0

Browse files
committed
Use IifCtxParser in dir_name
1 parent fef8a35 commit d38bbc0

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

rusty_parser/src/core/dim_name.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,22 @@ mod type_definition {
164164

165165
pub fn extended_type()
166166
-> impl Parser<StringView, VarNameCtx, Output = DimType, Error = ParserError> {
167-
ctx_parser::<StringView, VarNameCtx, ParserError>()
168-
.map(|(_opt_q, allow_user_defined)| {
169-
let mut parsers: Vec<
170-
Box<dyn Parser<StringView, Output = DimType, Error = ParserError>>,
171-
> = vec![
172-
Box::new(built_in_numeric_type()),
173-
Box::new(built_in_string()),
174-
];
175-
let mut expected_message = "INTEGER or LONG or SINGLE or DOUBLE or STRING";
176-
177-
if allow_user_defined {
178-
parsers.push(Box::new(user_defined_type()));
179-
expected_message =
180-
"INTEGER or LONG or SINGLE or DOUBLE or STRING or identifier";
181-
}
182-
183-
OrParser::new(parsers).with_expected_message(expected_message)
184-
})
185-
.flatten()
167+
IifCtxParser::new(
168+
// allow user defined
169+
OrParser::new(vec![
170+
Box::new(built_in_numeric_type()),
171+
Box::new(built_in_string()),
172+
Box::new(user_defined_type()),
173+
])
174+
.with_expected_message("INTEGER or LONG or SINGLE or DOUBLE or STRING or identifier"),
175+
// do not allow user defined
176+
OrParser::new(vec![
177+
Box::new(built_in_numeric_type()),
178+
Box::new(built_in_string()),
179+
])
180+
.with_expected_message("INTEGER or LONG or SINGLE or DOUBLE or STRING"),
181+
)
182+
.map_ctx(|(_, allow_user_defined): &(_, bool)| *allow_user_defined)
186183
}
187184

188185
fn built_in_numeric_type() -> impl Parser<StringView, Output = DimType, Error = ParserError> {

0 commit comments

Comments
 (0)