mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
Renamed BinaryExpression to BinaryOpDef for consistency.
This commit is contained in:
parent
53d598b773
commit
14bbd19f16
14
src/ast.rs
14
src/ast.rs
@ -230,9 +230,9 @@ pub enum BinaryExprType {
|
||||
Div,
|
||||
}
|
||||
|
||||
/// BinaryExpression represents an expression with a left and a right side.
|
||||
/// BinaryOpDef represents an expression with a left and a right side.
|
||||
#[derive(Debug,PartialEq,Clone)]
|
||||
pub struct BinaryExpression {
|
||||
pub struct BinaryOpDef {
|
||||
pub kind: BinaryExprType,
|
||||
pub left: Value,
|
||||
pub right: Box<Expression>,
|
||||
@ -259,7 +259,7 @@ pub enum Expression {
|
||||
// Base Expression
|
||||
Simple(Value),
|
||||
|
||||
Binary(BinaryExpression),
|
||||
Binary(BinaryOpDef),
|
||||
|
||||
// Complex Expressions
|
||||
Copy(CopyDef),
|
||||
@ -303,7 +303,7 @@ mod ast_test {
|
||||
"foo".to_string()
|
||||
],
|
||||
fields: vec![
|
||||
("f1".to_string(), Expression::Binary(BinaryExpression{
|
||||
("f1".to_string(), Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Symbol(make_value_node("foo".to_string())),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -322,7 +322,7 @@ mod ast_test {
|
||||
"foo".to_string()
|
||||
],
|
||||
fields: vec![
|
||||
("f1".to_string(), Expression::Binary(BinaryExpression{
|
||||
("f1".to_string(), Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Symbol(make_value_node("bar".to_string())),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -344,7 +344,7 @@ mod ast_test {
|
||||
"foo".to_string()
|
||||
],
|
||||
fields: vec![
|
||||
("f1".to_string(), Expression::Binary(BinaryExpression{
|
||||
("f1".to_string(), Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Selector(make_value_node(vec!["foo".to_string(), "quux".to_string()])),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -363,7 +363,7 @@ mod ast_test {
|
||||
"foo".to_string()
|
||||
],
|
||||
fields: vec![
|
||||
("f1".to_string(), Expression::Binary(BinaryExpression{
|
||||
("f1".to_string(), Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Selector(make_value_node(vec!["bar".to_string(), "quux".to_string()])),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
|
26
src/build.rs
26
src/build.rs
@ -629,7 +629,7 @@ mod test {
|
||||
let b = Builder::new();
|
||||
test_expr_to_val(vec![
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Div,
|
||||
left: Value::Int(make_value_node(2)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2)))),
|
||||
@ -637,7 +637,7 @@ mod test {
|
||||
}),
|
||||
Val::Int(1)),
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Div,
|
||||
left: Value::Float(make_value_node(2.0)),
|
||||
right: Box::new(Expression::Simple(Value::Float(make_value_node(2.0)))),
|
||||
@ -653,7 +653,7 @@ mod test {
|
||||
let b = Builder::new();
|
||||
test_expr_to_val(vec![
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Div,
|
||||
left: Value::Float(make_value_node(2.0)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2)))),
|
||||
@ -668,7 +668,7 @@ mod test {
|
||||
let b = Builder::new();
|
||||
test_expr_to_val(vec![
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Mul,
|
||||
left: Value::Int(make_value_node(2)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2)))),
|
||||
@ -676,7 +676,7 @@ mod test {
|
||||
}),
|
||||
Val::Int(4)),
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Mul,
|
||||
left: Value::Float(make_value_node(2.0)),
|
||||
right: Box::new(Expression::Simple(Value::Float(make_value_node(2.0)))),
|
||||
@ -692,7 +692,7 @@ mod test {
|
||||
let b = Builder::new();
|
||||
test_expr_to_val(vec![
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Mul,
|
||||
left: Value::Float(make_value_node(2.0)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(20)))),
|
||||
@ -707,7 +707,7 @@ mod test {
|
||||
let b = Builder::new();
|
||||
test_expr_to_val(vec![
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Sub,
|
||||
left: Value::Int(make_value_node(2)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -715,7 +715,7 @@ mod test {
|
||||
}),
|
||||
Val::Int(1)),
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Sub,
|
||||
left: Value::Float(make_value_node(2.0)),
|
||||
right: Box::new(Expression::Simple(Value::Float(make_value_node(1.0)))),
|
||||
@ -731,7 +731,7 @@ mod test {
|
||||
let b = Builder::new();
|
||||
test_expr_to_val(vec![
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Sub,
|
||||
left: Value::Float(make_value_node(2.0)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2)))),
|
||||
@ -746,7 +746,7 @@ mod test {
|
||||
let b = Builder::new();
|
||||
test_expr_to_val(vec![
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -754,7 +754,7 @@ mod test {
|
||||
}),
|
||||
Val::Int(2)),
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Float(make_value_node(1.0)),
|
||||
right: Box::new(Expression::Simple(Value::Float(make_value_node(1.0)))),
|
||||
@ -762,7 +762,7 @@ mod test {
|
||||
}),
|
||||
Val::Float(2.0)),
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::String(make_value_node("foo".to_string())),
|
||||
right: Box::new(Expression::Simple(Value::String(make_value_node("bar".to_string())))),
|
||||
@ -778,7 +778,7 @@ mod test {
|
||||
let b = Builder::new();
|
||||
test_expr_to_val(vec![
|
||||
(Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Float(make_value_node(2.0)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(2)))),
|
||||
|
24
src/parse.rs
24
src/parse.rs
@ -200,7 +200,7 @@ named!(simple_expression<Expression>,
|
||||
);
|
||||
|
||||
fn tuple_to_binary_expression(tpl: (BinaryExprType, Value, Expression)) -> ParseResult<Expression> {
|
||||
Ok(Expression::Binary(BinaryExpression{
|
||||
Ok(Expression::Binary(BinaryOpDef{
|
||||
kind: tpl.0,
|
||||
left: tpl.1,
|
||||
right: Box::new(tpl.2),
|
||||
@ -619,7 +619,7 @@ mod test {
|
||||
IResult::Done(&b""[..], Expression::Simple(Value::Symbol(make_value_node("foo".to_string())))));
|
||||
assert_eq!(expression(&b"1 + 1"[..]),
|
||||
IResult::Done(&b""[..],
|
||||
Expression::Binary(BinaryExpression{
|
||||
Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -627,7 +627,7 @@ mod test {
|
||||
})));
|
||||
assert_eq!(expression(&b"1 - 1"[..]),
|
||||
IResult::Done(&b""[..],
|
||||
Expression::Binary(BinaryExpression{
|
||||
Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Sub,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -635,7 +635,7 @@ mod test {
|
||||
})));
|
||||
assert_eq!(expression(&b"1 * 1"[..]),
|
||||
IResult::Done(&b""[..],
|
||||
Expression::Binary(BinaryExpression{
|
||||
Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Mul,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -643,7 +643,7 @@ mod test {
|
||||
})));
|
||||
assert_eq!(expression(&b"1 / 1"[..]),
|
||||
IResult::Done(&b""[..],
|
||||
Expression::Binary(BinaryExpression{
|
||||
Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Div,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -652,7 +652,7 @@ mod test {
|
||||
|
||||
assert_eq!(expression(&b"1+1"[..]),
|
||||
IResult::Done(&b""[..],
|
||||
Expression::Binary(BinaryExpression{
|
||||
Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -660,7 +660,7 @@ mod test {
|
||||
})));
|
||||
assert_eq!(expression(&b"1-1"[..]),
|
||||
IResult::Done(&b""[..],
|
||||
Expression::Binary(BinaryExpression{
|
||||
Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Sub,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -668,7 +668,7 @@ mod test {
|
||||
})));
|
||||
assert_eq!(expression(&b"1*1"[..]),
|
||||
IResult::Done(&b""[..],
|
||||
Expression::Binary(BinaryExpression{
|
||||
Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Mul,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -676,7 +676,7 @@ mod test {
|
||||
})));
|
||||
assert_eq!(expression(&b"1/1"[..]),
|
||||
IResult::Done(&b""[..],
|
||||
Expression::Binary(BinaryExpression{
|
||||
Expression::Binary(BinaryOpDef{
|
||||
kind: BinaryExprType::Div,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -725,7 +725,7 @@ mod test {
|
||||
Expression::Grouped(
|
||||
Box::new(
|
||||
Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
@ -906,7 +906,7 @@ mod test {
|
||||
Expression::Grouped(
|
||||
Box::new(
|
||||
Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(
|
||||
@ -1022,7 +1022,7 @@ mod test {
|
||||
},
|
||||
Statement::Expression(
|
||||
Expression::Binary(
|
||||
BinaryExpression{
|
||||
BinaryOpDef{
|
||||
kind: BinaryExprType::Add,
|
||||
left: Value::Int(make_value_node(1)),
|
||||
right: Box::new(Expression::Simple(Value::Int(make_value_node(1)))),
|
||||
|
Loading…
x
Reference in New Issue
Block a user