Add none value 🧫

This commit is contained in:
Laurenz 2020-10-04 19:26:27 +02:00
parent f4460f8abd
commit 105f70867d

View File

@ -17,6 +17,8 @@ use crate::{DynFuture, Feedback};
/// A computational value. /// A computational value.
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub enum Value { pub enum Value {
/// The value that indicates the absence of a meaningful value.
None,
/// An identifier: `ident`. /// An identifier: `ident`.
Ident(Ident), Ident(Ident),
/// A boolean: `true, false`. /// A boolean: `true, false`.
@ -57,9 +59,10 @@ impl Value {
/// messages. /// messages.
pub fn ty(&self) -> &'static str { pub fn ty(&self) -> &'static str {
match self { match self {
Self::Ident(_) => "identifier", Self::None => "none",
Self::Ident(_) => "ident",
Self::Bool(_) => "bool", Self::Bool(_) => "bool",
Self::Int(_) => "integer", Self::Int(_) => "int",
Self::Float(_) => "float", Self::Float(_) => "float",
Self::Relative(_) => "relative", Self::Relative(_) => "relative",
Self::Length(_) => "length", Self::Length(_) => "length",
@ -82,6 +85,10 @@ impl Spanned<Value> {
/// the value is represented as layoutable content in a reasonable way. /// the value is represented as layoutable content in a reasonable way.
pub fn into_commands(self) -> Commands { pub fn into_commands(self) -> Commands {
match self.v { match self.v {
// Pass-through.
Value::Commands(commands) => commands,
Value::Content(tree) => vec![Command::LayoutSyntaxTree(tree)],
// Forward to each entry, separated with spaces. // Forward to each entry, separated with spaces.
Value::Dict(dict) => { Value::Dict(dict) => {
let mut commands = vec![]; let mut commands = vec![];
@ -99,8 +106,8 @@ impl Spanned<Value> {
commands commands
} }
Value::Content(tree) => vec![Command::LayoutSyntaxTree(tree)], // Don't print out none values.
Value::Commands(commands) => commands, Value::None => vec![],
// Format with debug. // Format with debug.
val => { val => {
@ -115,7 +122,7 @@ impl Spanned<Value> {
impl Debug for Value { impl Debug for Value {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self { match self {
Self::Error => f.pad("<error>"), Self::None => f.pad("none"),
Self::Ident(v) => v.fmt(f), Self::Ident(v) => v.fmt(f),
Self::Bool(v) => v.fmt(f), Self::Bool(v) => v.fmt(f),
Self::Int(v) => v.fmt(f), Self::Int(v) => v.fmt(f),
@ -129,6 +136,7 @@ impl Debug for Value {
Self::Content(v) => v.fmt(f), Self::Content(v) => v.fmt(f),
Self::Func(v) => v.fmt(f), Self::Func(v) => v.fmt(f),
Self::Commands(v) => v.fmt(f), Self::Commands(v) => v.fmt(f),
Self::Error => f.pad("<error>"),
} }
} }
} }