sysml_parser/
parser.rs

1// This is free and unencumbered software released into the public domain.
2
3use crate::{grammar::model, ParseError, ParseResult, ParsedModel};
4
5#[cfg(feature = "std")]
6extern crate std;
7
8#[cfg(feature = "std")]
9pub fn parse_from_file(pathname: impl AsRef<std::path::Path>) -> ParseResult<ParsedModel> {
10    parse_from_string(&std::fs::read_to_string(pathname)?)
11}
12
13#[cfg(feature = "std")]
14pub fn parse_from_reader(reader: impl std::io::Read) -> ParseResult<ParsedModel> {
15    parse_from_string(&std::io::read_to_string(reader)?)
16}
17
18pub fn parse_from_string(input: &str) -> ParseResult<ParsedModel> {
19    let (_, model) = model(input).map_err(|err| match err {
20        nom::Err::Error(error) | nom::Err::Failure(error) => ParseError::from(error),
21        nom::Err::Incomplete(_) => unreachable!(),
22    })?;
23    Ok(model)
24}