ron_reboot/utf8_parser/
mod.rs

1use crate::{ast, ast::Ron, Error, utf8_parser::ok::IOk};
2
3use self::{
4    containers::{list, rmap, tuple, untagged_struct},
5    error::{BaseErrorKind, Expectation, InputParseErr},
6    input::Input,
7    primitive::{bool, decimal, escaped_string, signed_integer, unescaped_str, unsigned_integer},
8    ron::expr,
9};
10pub use self::error::{ErrorTree, InputParseError};
11
12//pub type IResultFatal<'a, O> = Result<(Input<'a>, O), InputParseError<'a>>;
13type IResultLookahead<'a, O> = Result<IOk<'a, O>, InputParseErr<'a>>;
14type OutputResult<'a, O> = Result<O, InputParseErr<'a>>;
15
16/// Basic parsers which receive `Input`
17mod basic;
18/// Parser combinators which take one or more parsers and modify / combine them
19mod combinators;
20/// RON container parsers
21mod containers;
22/// Parser error collection
23mod error;
24mod error_fmt;
25/// `Input` abstraction to slice the input that is being parsed and keep track of the line + column
26mod input;
27mod ok;
28/// RON primitive parsers
29mod primitive;
30/// IR for parsing which will then be converted to the AST
31mod pt;
32/// Parsers for arbitrary RON expression & top-level RON
33mod ron;
34#[cfg(feature = "utf8_parser_serde1")]
35pub mod serde;
36#[cfg(test)]
37mod tests;
38/// Utility functions for parsing
39mod util;
40// Integration tests cannot import this without the feature gate
41// (not sure why that is...)
42#[cfg(any(test, feature = "test"))]
43pub mod test_util;
44
45pub fn ast_from_str(input: &str) -> Result<Ron, crate::error::Error> {
46    let pt: pt::Ron = ron::ron(input)
47        .map_err(ErrorTree::calc_locations)
48        .map_err(Error::from)
49        .map_err(|e| e.context_file_content(input.to_owned()))?;
50    let ast: ast::Ron = pt.into();
51
52    Ok(ast)
53}