1use pest::{
2 error::{Error, ErrorVariant},
3 iterators::Pair,
4 Parser, Position,
5};
6use pest_derive;
7
8#[derive(pest_derive::Parser)]
9#[grammar = "wdl.pest"]
10pub struct PestParser;
11
12pub fn parse_document<'a>(text: &'a str) -> Result<Pair<'a, Rule>, Error<Rule>> {
13 let mut root_pairs = PestParser::parse(Rule::document, text)?;
14 root_pairs.next().ok_or_else(|| {
15 Error::new_from_pos(
16 ErrorVariant::CustomError {
17 message: String::from("Empty WDL document"),
18 },
19 Position::from_start(text),
20 )
21 })
22}