Skip to content

Commit e35d3e2

Browse files
committed
parser: mv condition parser
1 parent f037892 commit e35d3e2

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

crates/leanVm/src/parser/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub mod function;
2121
pub(crate) use function::*;
2222
pub mod statement;
2323
pub(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-
230216
fn parse_assert_eq(
231217
pair: Pair<'_, Rule>,
232218
constants: &BTreeMap<String, usize>,

0 commit comments

Comments
 (0)