mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-26 11:45:00 +03:00
add formatting for unary expression
This commit is contained in:
parent
e84aa7b782
commit
599c886d23
@ -66,7 +66,7 @@ impl<'ast> fmt::Display for Expression<'ast> {
|
||||
match *self {
|
||||
Expression::Value(ref expression) => write!(f, "{}", expression),
|
||||
Expression::Identifier(ref expression) => write!(f, "{}", expression),
|
||||
Expression::Unary(ref expression) => write!(f, "!{}", expression.expression),
|
||||
Expression::Unary(ref expression) => write!(f, "{}", expression),
|
||||
Expression::Binary(ref expression) => write!(f, "{} == {}", expression.left, expression.right),
|
||||
Expression::Ternary(ref expression) => write!(
|
||||
f,
|
||||
|
@ -3,6 +3,7 @@ use crate::{ast::Rule, expressions::Expression, operations::UnaryOperation, Span
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::expression_unary))]
|
||||
@ -13,3 +14,9 @@ pub struct UnaryExpression<'ast> {
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for UnaryExpression {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}{}", self.operation, self.expression)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ use crate::ast::Rule;
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::operation_unary))]
|
||||
@ -10,6 +11,15 @@ pub enum UnaryOperation {
|
||||
Not(Not),
|
||||
}
|
||||
|
||||
impl fmt::Display for UnaryOperation {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
UnaryOperation::Minus(_) => write!(f, "-"),
|
||||
UnaryOperation::Not(_) => write!(f, "!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::operation_not))]
|
||||
pub struct Not {}
|
||||
|
Loading…
Reference in New Issue
Block a user