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
//! A crate for reading files in the FOF dialect of the TPTP format.
//!
//! # Quickstart
//! ```rust
//! extern crate tptp;
//!
//! // propagate any errors encountered for handling later
//! fn example() -> Result<(), tptp::error::ErrorWithContext> {
//!
//! // stream TPTP statements, following include directives
//! for statement in tptp::stream("example.p")? {
//!
//! // reading each statement might involve an error
//! let statement = statement?;
//!
//! // process each statement as you see fit
//! println!("{:#?}", statement);
//!
//! }
//!
//! Ok(())
//! }
//! ```
/// Errors that might be raised during processing
pub mod error;
/// Follow include directives
pub mod follow;
/// Lexical analysis
pub mod lexer;
/// Parsing
pub mod parser;
/// Line/column reporting
pub mod position;
/// Resolve include() paths according to the TPTP spec
pub mod resolve;
/// Syntax trees
pub mod syntax;
/// Lexical tokens
pub mod token;
/// Convenient API to stream statements, following include directives recursively
pub fn stream(
path: &str,
) -> Result<impl Iterator<Item = Result<syntax::Statement, error::ErrorInfo>>, error::ErrorInfo> {
let mut follow = follow::Follow::new(|path| {
let stream = resolve::resolve(path)?;
let lexer = lexer::Lexer::new(stream);
let parser = parser::Parser::new(lexer);
Ok(parser)
});
follow.include(path.into(), None)?;
Ok(follow)
}