orql 0.1.0

A toy SQL parser for a subset of the Oracle dialect.
Documentation
//! Parser code for a SELECT statement.

use super::{MetaTracker, ParserInner, Result};
use crate::{
    ast::{Query, Select},
    parser::Error,
    scanner::{Keyword, Token, TokenType},
};

mod joins;
mod limit;
mod locks;
mod query;

impl<'s, M> ParserInner<'s, M>
where
    M: MetaTracker<'s>,
{
    /// Parses a select statement _not_ consuming the final semicolon - if any
    pub(super) fn parse_select(&mut self) -> Result<Select<'s, M::NodeId>> {
        let query = self.parse_query()?;
        let for_update = self.parse_for_update()?;
        Ok(Select { query, for_update })
    }

    /// Looks ahead in the token stream to determine if a query might be parsed using [ParserInner::parse_query].
    pub(super) fn can_parse_query(&mut self) -> Result<bool> {
        Ok(matches!(
            self.peek_token()?,
            Some(Token {
                ttype: TokenType::Keyword(Keyword::SELECT | Keyword::WITH),
                ..
            })
        ))
    }

    /// Parses a (sub-)query; See <https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6__I2126435>
    pub(super) fn parse_query(&mut self) -> Result<Query<'s, M::NodeId>> {
        Ok(Query {
            with: self.parse_query_with()?,
            body: self.parse_query_body()?,
        })
    }
}