orql 0.1.0

A toy SQL parser for a subset of the Oracle dialect.
Documentation
use super::{Ident, NationalStyle, Text};

// XXX DATE and TIMESTAMPs

/// An atomic value
#[derive(Debug)]
pub enum Value<'s> {
    /// a `NULL` literal
    Null,
    /// an integer literal
    Integer(&'s str),
    /// a floating point literal
    Float(&'s str),
    /// a string literal
    Text(Text<'s>, NationalStyle),
    /// a name-less (ie. `?`) or named (eg. `:name`) placeholder
    Placeholder(Option<Ident<'s>>),
}

impl<'s> std::fmt::Display for Value<'s> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        crate::fmt::Display::fmt(self, f)
    }
}

impl<'s> crate::fmt::Display for Value<'s> {
    fn fmt(&self, f: &mut impl crate::fmt::Formatter) -> std::fmt::Result {
        match self {
            Value::Null => f.write_str("NULL"),
            Value::Integer(n) => f.write_str(n),
            Value::Float(n) => f.write_str(n),
            Value::Text(text, national_style) => {
                match national_style {
                    NationalStyle::None => {}
                    NationalStyle::National => f.write_char('N')?,
                }
                crate::fmt::Display::fmt(text, f)
            }
            Value::Placeholder(ident) => match ident {
                Some(ident) => {
                    f.write_char(':')?;
                    crate::fmt::Display::fmt(ident, f)
                }
                None => f.write_char('?'),
            },
        }
    }
}