orql 0.1.0

A toy SQL parser for a subset of the Oracle dialect.
Documentation
//! Declares the Abstract Syntax Tree (AST) types as produced by the [parser](crate::parser).

mod condition;
mod duplicates;
mod expression;
mod function;
mod hint;
mod order;
mod select;
mod statement;
mod value;
mod window;

use std::ops::Deref;

pub use crate::scanner::{CommentStyle, Ident, NationalStyle, Text};
pub use condition::*;
pub use duplicates::*;
pub use expression::*;
pub use function::*;
pub use hint::*;
pub use order::*;
pub use select::*;
pub use statement::*;
pub use value::*;
pub use window::*;

/// A node in the AST (along with an ID)
///
/// The second tuple element represents an abstract identifier allowing to
/// access metadata, e.g. node location or associated comments.
///
/// Note: the parser keeps track of and publishes metadata only when asked to
/// do so.  Parsing without metadata should result in IDs being a `()`, making
/// a `Node` merely a wrapper struct around the AST element and, hence,
/// requiring no additional space.
#[derive(Debug)]
pub struct Node<T, ID>(
    /// A parsed AST element, e.g. an expression
    pub T,
    /// A parsed AST element's abstract identifier allowing access to metadata
    pub ID,
);

impl<T, ID> Deref for Node<T, ID> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl<T, ID> Node<T, ID> {
    /// Maps `f` over `self.0`
    pub fn map<R, F: FnOnce(T) -> R>(self, f: F) -> Node<R, ID> {
        Node(f(self.0), self.1)
    }
}