pub extern crate num_bigint;
pub extern crate num_rational;
extern crate num_traits;
extern crate pest;
extern crate pest_derive;
mod ast;
use crate::parser::{DsdlParser, Rule};
use pest::Parser;
pub use crate::ast::types::*;
use pest::error::ErrorVariant;
pub use pest::Span;
mod parser {
use pest_derive::Parser;
#[derive(Parser)]
#[grammar = "dsdl.pest"]
pub struct DsdlParser;
}
#[derive(Debug, Clone)]
pub struct Error(Box<pest::error::Error<Rule>>);
pub fn parse<'i>(dsdl: &'i str) -> Result<Definition<'i>, Error> {
let parse_tree = DsdlParser::parse(Rule::definition, dsdl).map_err(|e| Error(Box::new(e)))?;
ast::parse_to_ast(parse_tree)
}
pub fn make_error<S>(message: S, span: Span<'_>) -> Error
where
S: Into<String>,
{
Error(Box::new(pest::error::Error::new_from_span(
ErrorVariant::CustomError {
message: message.into(),
},
span,
)))
}
mod error_impl {
use super::Error;
use std::fmt;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.0.source()
}
}
}