feat: new snapshots
This commit is contained in:
parent
05eb281f40
commit
2c2f3c90fb
|
@ -0,0 +1,72 @@
|
||||||
|
use chumsky::prelude::*;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
ast::LogicalOpChainKind,
|
||||||
|
expr::UntypedExpr,
|
||||||
|
parser::{error::ParseError, token::Token},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn parser(
|
||||||
|
expression: Recursive<'_, Token, UntypedExpr, ParseError>,
|
||||||
|
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
|
||||||
|
choice((
|
||||||
|
just(Token::And).to(LogicalOpChainKind::And),
|
||||||
|
just(Token::Or).to(LogicalOpChainKind::Or),
|
||||||
|
))
|
||||||
|
.then(
|
||||||
|
expression
|
||||||
|
.separated_by(just(Token::Comma))
|
||||||
|
.allow_trailing()
|
||||||
|
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace)),
|
||||||
|
)
|
||||||
|
.map_with_span(|(kind, exprs), span| UntypedExpr::LogicalOpChain {
|
||||||
|
kind,
|
||||||
|
expressions: exprs,
|
||||||
|
location: span,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::assert_expr;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn and_chain() {
|
||||||
|
assert_expr!(
|
||||||
|
r#"
|
||||||
|
and {
|
||||||
|
1 == 2,
|
||||||
|
something,
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn or_chain() {
|
||||||
|
assert_expr!(
|
||||||
|
r#"
|
||||||
|
or {
|
||||||
|
1 == 2,
|
||||||
|
something,
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn and_or_chain() {
|
||||||
|
assert_expr!(
|
||||||
|
r#"
|
||||||
|
or {
|
||||||
|
1 == 2,
|
||||||
|
something,
|
||||||
|
and {
|
||||||
|
1 == 2,
|
||||||
|
something,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
---
|
||||||
|
source: crates/aiken-lang/src/parser/expr/and_or_chain.rs
|
||||||
|
description: "Code:\n\nand {\n 1 == 2,\n something,\n}\n"
|
||||||
|
---
|
||||||
|
LogicalOpChain {
|
||||||
|
kind: And,
|
||||||
|
expressions: [
|
||||||
|
BinOp {
|
||||||
|
location: 8..14,
|
||||||
|
name: Eq,
|
||||||
|
left: UInt {
|
||||||
|
location: 8..9,
|
||||||
|
value: "1",
|
||||||
|
base: Decimal {
|
||||||
|
numeric_underscore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
right: UInt {
|
||||||
|
location: 13..14,
|
||||||
|
value: "2",
|
||||||
|
base: Decimal {
|
||||||
|
numeric_underscore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Var {
|
||||||
|
location: 18..27,
|
||||||
|
name: "something",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
location: 0..30,
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
---
|
||||||
|
source: crates/aiken-lang/src/parser/expr/and_or_chain.rs
|
||||||
|
description: "Code:\n\nor {\n 1 == 2,\n something,\n and {\n 1 == 2,\n something,\n },\n}\n"
|
||||||
|
---
|
||||||
|
LogicalOpChain {
|
||||||
|
kind: Or,
|
||||||
|
expressions: [
|
||||||
|
BinOp {
|
||||||
|
location: 7..13,
|
||||||
|
name: Eq,
|
||||||
|
left: UInt {
|
||||||
|
location: 7..8,
|
||||||
|
value: "1",
|
||||||
|
base: Decimal {
|
||||||
|
numeric_underscore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
right: UInt {
|
||||||
|
location: 12..13,
|
||||||
|
value: "2",
|
||||||
|
base: Decimal {
|
||||||
|
numeric_underscore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Var {
|
||||||
|
location: 17..26,
|
||||||
|
name: "something",
|
||||||
|
},
|
||||||
|
LogicalOpChain {
|
||||||
|
kind: And,
|
||||||
|
expressions: [
|
||||||
|
BinOp {
|
||||||
|
location: 40..46,
|
||||||
|
name: Eq,
|
||||||
|
left: UInt {
|
||||||
|
location: 40..41,
|
||||||
|
value: "1",
|
||||||
|
base: Decimal {
|
||||||
|
numeric_underscore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
right: UInt {
|
||||||
|
location: 45..46,
|
||||||
|
value: "2",
|
||||||
|
base: Decimal {
|
||||||
|
numeric_underscore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Var {
|
||||||
|
location: 52..61,
|
||||||
|
name: "something",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
location: 30..66,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
location: 0..69,
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
---
|
||||||
|
source: crates/aiken-lang/src/parser/expr/and_or_chain.rs
|
||||||
|
description: "Code:\n\nor {\n 1 == 2,\n something,\n}\n"
|
||||||
|
---
|
||||||
|
LogicalOpChain {
|
||||||
|
kind: Or,
|
||||||
|
expressions: [
|
||||||
|
BinOp {
|
||||||
|
location: 7..13,
|
||||||
|
name: Eq,
|
||||||
|
left: UInt {
|
||||||
|
location: 7..8,
|
||||||
|
value: "1",
|
||||||
|
base: Decimal {
|
||||||
|
numeric_underscore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
right: UInt {
|
||||||
|
location: 12..13,
|
||||||
|
value: "2",
|
||||||
|
base: Decimal {
|
||||||
|
numeric_underscore: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Var {
|
||||||
|
location: 17..26,
|
||||||
|
name: "something",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
location: 0..29,
|
||||||
|
}
|
Loading…
Reference in New Issue