From eaf3cd1da31bcc44339c4124fc60cad607fbbfa4 Mon Sep 17 00:00:00 2001 From: Lach Date: Wed, 26 Aug 2020 05:42:58 +0000 Subject: [PATCH] feat(parser): impl Display for op types --- --- a/crates/jrsonnet-parser/src/expr.rs +++ b/crates/jrsonnet-parser/src/expr.rs @@ -2,7 +2,12 @@ use serde::Deserialize; #[cfg(feature = "serialize")] use serde::Serialize; -use std::{fmt::Debug, ops::Deref, path::PathBuf, rc::Rc}; +use std::{ + fmt::{Debug, Display}, + ops::Deref, + path::PathBuf, + rc::Rc, +}; #[cfg(feature = "dump")] use structdump_derive::Codegen; @@ -68,6 +73,21 @@ BitNot, Not, } +impl Display for UnaryOpType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use UnaryOpType::*; + write!( + f, + "{}", + match self { + Plus => "+", + Minus => "-", + BitNot => "~", + Not => "!", + } + ) + } +} #[cfg_attr(feature = "dump", derive(Codegen))] #[cfg_attr(feature = "serialize", derive(Serialize))] @@ -95,6 +115,32 @@ And, Or, } +impl Display for BinaryOpType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use BinaryOpType::*; + write!( + f, + "{}", + match self { + Mul => "*", + Div => "/", + Add => "+", + Sub => "-", + Lhs => "<<", + Rhs => ">>", + Lt => "<", + Gt => ">", + Lte => "<=", + Gte => ">=", + BitAnd => "&", + BitOr => "|", + BitXor => "^", + And => "&&", + Or => "||", + } + ) + } +} /// name, default value #[cfg_attr(feature = "dump", derive(Codegen))] -- gitstuff