1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}
pub type Error = pest::error::Error<Rule>;
pub fn parse(dsdl: &str) -> Result<Definition<'_>, Error> {
let parse_tree = DsdlParser::parse(Rule::definition, dsdl)?;
ast::parse_to_ast(parse_tree)
}
pub fn make_error<S>(message: S, span: Span<'_>) -> Error
where
S: Into<String>,
{
Error::new_from_span(
ErrorVariant::CustomError {
message: message.into(),
},
span,
)
}