use crate::{
parser::{statements, streaming_statements},
Block, Error, NomResult, Span, Spanned,
};
use core::fmt;
#[derive(Debug, Clone)]
pub struct Features {
pub tuples: bool,
pub type_annotations: bool,
pub fn_definitions: bool,
pub blocks: bool,
pub methods: bool,
}
impl Features {
pub const fn all() -> Self {
Self {
tuples: true,
type_annotations: true,
fn_definitions: true,
blocks: true,
methods: true,
}
}
pub const fn none() -> Self {
Self {
tuples: false,
type_annotations: false,
fn_definitions: false,
blocks: false,
methods: false,
}
}
}
impl Default for Features {
fn default() -> Self {
Self::all()
}
}
pub trait Grammar: 'static {
type Lit: Clone + fmt::Debug;
type Type: Clone + fmt::Debug;
const FEATURES: Features;
fn parse_literal(input: Span<'_>) -> NomResult<'_, Self::Lit>;
fn parse_type(input: Span<'_>) -> NomResult<'_, Self::Type>;
}
pub trait GrammarExt: Grammar {
fn parse_statements(input: Span<'_>) -> Result<Block<'_, Self>, Spanned<'_, Error<'_>>>
where
Self: Sized;
fn parse_streaming_statements(
input: Span<'_>,
) -> Result<Block<'_, Self>, Spanned<'_, Error<'_>>>
where
Self: Sized;
}
impl<T: Grammar> GrammarExt for T {
fn parse_statements(input: Span<'_>) -> Result<Block<'_, Self>, Spanned<'_, Error<'_>>>
where
Self: Sized,
{
statements(input)
}
fn parse_streaming_statements(
input: Span<'_>,
) -> Result<Block<'_, Self>, Spanned<'_, Error<'_>>>
where
Self: Sized,
{
streaming_statements(input)
}
}