use crate::lexer::Loc;
use frodobuf_schema::model::Schema;
use crate::parser::Parser;
pub use crate::parser::ParserError;
pub use crate::parser::ParserErrorWithLocation;
#[derive(Debug, Clone, PartialEq)]
pub struct WithLoc<T> {
pub loc: Loc,
pub t: T,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ImportVis {
Default,
Public,
Weak,
}
impl Default for ImportVis {
fn default() -> Self {
ImportVis::Default
}
}
#[derive(Debug, Default, Clone)]
pub struct Import {
pub path: String,
pub vis: ImportVis,
}
#[derive(Debug, Default, Clone)]
pub struct FileDescriptor {
pub imports: Vec<Import>,
pub schema: Schema,
}
impl FileDescriptor {
pub fn parse<S: AsRef<str>>(file: S) -> Result<Self, ParserErrorWithLocation> {
let mut parser = Parser::new(file.as_ref());
match parser.next_proto() {
Ok(r) => Ok(r),
Err(error) => {
let Loc { line, col } = parser.tokenizer.loc();
Err(ParserErrorWithLocation { error, line, col })
}
}
}
}