54 lines
1.2 KiB
Rust
54 lines
1.2 KiB
Rust
|
|
use crate::syn::ast::*;
|
||
|
|
use crate::syn::token::*;
|
||
|
|
use pest::{error::Error, iterators::Pair, Parser};
|
||
|
|
|
||
|
|
#[derive(pest_derive::Parser)]
|
||
|
|
#[grammar = "syn/parser.pest"]
|
||
|
|
pub struct SybilParser;
|
||
|
|
|
||
|
|
pub type Result<T, E = Error<Rule>> = std::result::Result<T, E>;
|
||
|
|
|
||
|
|
fn parse_atom(pair: Pair<Rule>) -> Result<SpAtom> {
|
||
|
|
match pair.as_rule() {
|
||
|
|
Rule::float => todo!(),
|
||
|
|
Rule::int => todo!(),
|
||
|
|
Rule::assign => todo!(),
|
||
|
|
Rule::word => todo!(),
|
||
|
|
Rule::str => todo!(),
|
||
|
|
_ => unreachable!(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
fn parse_expr(pair: Pair<Rule>) -> Result<SpExpr> {
|
||
|
|
match pair.as_rule() {
|
||
|
|
Rule::atom => {
|
||
|
|
todo!()
|
||
|
|
}
|
||
|
|
Rule::quote => {
|
||
|
|
todo!()
|
||
|
|
}
|
||
|
|
Rule::apply => {
|
||
|
|
todo!()
|
||
|
|
}
|
||
|
|
_ => unreachable!(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
fn parse_stmt(pair: Pair<Rule>) -> Result<SpStmt> {
|
||
|
|
match pair.as_rule() {
|
||
|
|
Rule::expr => {
|
||
|
|
todo!()
|
||
|
|
}
|
||
|
|
_ => unreachable!(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn parse_file(text: &str) -> Result<Vec<SpStmt>> {
|
||
|
|
let input = SybilParser::parse(Rule::file, text)?.next().unwrap();
|
||
|
|
let mut stmts = Vec::new();
|
||
|
|
for pair in input.into_inner() {
|
||
|
|
stmts.push(parse_stmt(pair)?);
|
||
|
|
}
|
||
|
|
Ok(stmts)
|
||
|
|
}
|