//!
//! This crate serves as the syntactical analyser (parser) for the Simple Object Machine.
//!
//! This particular version of the parser works with the tokens outputted by the lexical analyser, instead of directly reading text.
//!
/// SOM-specific parser combinators.
pub mod lang;
use som_core::ast::ClassDef;
use som_lexer::Token;
use som_parser_core::Parser;
/// Parses the input of an entire file into an AST.
pub fn parse_file(input: &[Token]) -> Option<ClassDef> {
self::apply(lang::file(), input)
}
/// Applies a parser and returns the output value if the entirety of the input has been parsed successfully.
pub fn apply<'a, A, P>(mut parser: P, input: &'a [Token]) -> Option<A>
where
P: Parser<A, &'a [Token]>,
{
match parser.parse(input) {
Some((output, tail)) if tail.is_empty() => Some(output),
Some(_) | None => None,
}
}