File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use std:: collections:: BTreeMap ;
2+
3+ use pest:: iterators:: Pair ;
4+
5+ use super :: { ParseError , Rule , parse_expression} ;
6+ use crate :: lang:: Boolean ;
7+
8+ pub ( crate ) fn parse_condition (
9+ pair : Pair < ' _ , Rule > ,
10+ constants : & BTreeMap < String , usize > ,
11+ ) -> Result < Boolean , ParseError > {
12+ let inner = pair. into_inner ( ) . next ( ) . unwrap ( ) ;
13+ let mut parts = inner. clone ( ) . into_inner ( ) ;
14+ let left = parse_expression ( parts. next ( ) . unwrap ( ) , constants) ?;
15+ let right = parse_expression ( parts. next ( ) . unwrap ( ) , constants) ?;
16+
17+ match inner. as_rule ( ) {
18+ Rule :: condition_eq => Ok ( Boolean :: Equal { left, right } ) ,
19+ Rule :: condition_diff => Ok ( Boolean :: Different { left, right } ) ,
20+ _ => unreachable ! ( ) ,
21+ }
22+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ pub mod function;
2121pub ( crate ) use function:: * ;
2222pub mod statement;
2323pub ( crate ) use statement:: * ;
24+ pub mod condition;
25+ pub ( crate ) use condition:: * ;
2426
2527#[ derive( Parser , Debug ) ]
2628#[ grammar = "grammar.pest" ]
@@ -211,22 +213,6 @@ fn parse_tuple_expression(
211213 . collect ( )
212214}
213215
214- fn parse_condition (
215- pair : Pair < ' _ , Rule > ,
216- constants : & BTreeMap < String , usize > ,
217- ) -> Result < Boolean , ParseError > {
218- let inner = pair. into_inner ( ) . next ( ) . unwrap ( ) ;
219- let mut parts = inner. clone ( ) . into_inner ( ) ;
220- let left = parse_expression ( parts. next ( ) . unwrap ( ) , constants) ?;
221- let right = parse_expression ( parts. next ( ) . unwrap ( ) , constants) ?;
222-
223- match inner. as_rule ( ) {
224- Rule :: condition_eq => Ok ( Boolean :: Equal { left, right } ) ,
225- Rule :: condition_diff => Ok ( Boolean :: Different { left, right } ) ,
226- _ => unreachable ! ( ) ,
227- }
228- }
229-
230216fn parse_assert_eq (
231217 pair : Pair < ' _ , Rule > ,
232218 constants : & BTreeMap < String , usize > ,
You can’t perform that action at this time.
0 commit comments