WIP: Re-implement parser in pest
Parser implementation is kind of iffy. Let's try to re-implement it using pest. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
53
src/syn/peg.rs
Normal file
53
src/syn/peg.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user