1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! # RubyLit - Trait Implementations
//!
//! This module contains trait implementations for `RubyLit`.
//!
//! ## Implemented Traits
//!
//! - `Display`
//!
//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
use crate::lcnf::*;
use super::functions::{fmt_ruby_class, fmt_ruby_method, fmt_ruby_module_stmt, fmt_ruby_stmt};
use super::types::RubyLit;
use std::fmt;
impl fmt::Display for RubyLit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RubyLit::Int(n) => write!(f, "{}", n),
RubyLit::Float(n) => {
if n.fract() == 0.0 && n.is_finite() {
write!(f, "{}.0", *n as i64)
} else {
write!(f, "{}", n)
}
}
RubyLit::Str(s) => {
write!(f, "\"")?;
for c in s.chars() {
match c {
'"' => write!(f, "\\\"")?,
'\\' => write!(f, "\\\\")?,
'\n' => write!(f, "\\n")?,
'\r' => write!(f, "\\r")?,
'\t' => write!(f, "\\t")?,
'#' => write!(f, "\\#")?,
c => write!(f, "{}", c)?,
}
}
write!(f, "\"")
}
RubyLit::Bool(b) => write!(f, "{}", b),
RubyLit::Nil => write!(f, "nil"),
RubyLit::Symbol(name) => write!(f, ":{}", name),
}
}
}