svg-filters & basic parser #15
2 changed files with 36 additions and 13 deletions
|
@ -3,7 +3,10 @@ use std::{fs, path::PathBuf};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use lang::{
|
use lang::{
|
||||||
err_reporting::ErrorCollector,
|
err_reporting::ErrorCollector,
|
||||||
parser::ast::lossless::{lex, parser},
|
parser::ast::lossless::{
|
||||||
|
lex,
|
||||||
|
parser::{self, parser_to_events::to_events},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -17,8 +20,11 @@ fn main() {
|
||||||
let n = args.file.clone();
|
let n = args.file.clone();
|
||||||
let f = fs::read_to_string(n.clone()).expect("failed to read file");
|
let f = fs::read_to_string(n.clone()).expect("failed to read file");
|
||||||
println!("toks: {:?}", lex::lex(&f));
|
println!("toks: {:?}", lex::lex(&f));
|
||||||
let parse_res = parser::parse(&f);
|
println!("evs: {:?}", to_events(&f));
|
||||||
println!("parse: {:?}", parse_res);
|
|
||||||
|
// let parse_res = parser::parse(&f);
|
||||||
|
// println!("parse: {:?}", parse_res);
|
||||||
|
|
||||||
// dbg!(lex::lex(&f));
|
// dbg!(lex::lex(&f));
|
||||||
// let mut err_collector = ErrorCollector::new(vec![(n.to_str().unwrap(), &f)]);
|
// let mut err_collector = ErrorCollector::new(vec![(n.to_str().unwrap(), &f)]);
|
||||||
|
|
||||||
|
|
|
@ -11,20 +11,37 @@ use crate::parser::{
|
||||||
|
|
||||||
use super::lex::{self, SyntaxKind};
|
use super::lex::{self, SyntaxKind};
|
||||||
|
|
||||||
mod parsers {
|
pub mod parser_to_events {
|
||||||
use rowan::GreenNode;
|
use chumsky::Parser;
|
||||||
|
|
||||||
use crate::parser::ast::lossless::lex::SyntaxKind;
|
use crate::parser::ast::lossless::lex::SyntaxKind::{self, *};
|
||||||
|
|
||||||
use super::SyntaxError;
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub(super) enum Event {
|
||||||
struct ParseResult {
|
StartNode,
|
||||||
green_node: GreenNode,
|
StartErr(SyntaxError),
|
||||||
errors: Vec<SyntaxError>,
|
EatToken,
|
||||||
|
FinishNode,
|
||||||
|
FinishErr,
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Parser {
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
fn parse<'src>(input: &[(SyntaxKind, &'src str)]) -> ParseResult;
|
enum SyntaxError {
|
||||||
|
Expected(SyntaxKind),
|
||||||
|
AttrExpectedValue,
|
||||||
|
/// guessed if there's a newline and attr on next line without comma
|
||||||
|
/// should then suggest comma after attr
|
||||||
|
ExpectedCommaBetweenAttrs,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_events(src: &str) -> Vec<Event> {
|
||||||
|
let mut tokens = lex::lex(src);
|
||||||
|
parser().parse(tokens)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parser() -> impl Parser<'static, SyntaxKind, Vec<Event>> {
|
||||||
|
let whitespace = just(WHITESPACE).or(NEWLINE).repeated().collect::<Vec<_>>();
|
||||||
|
whitespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue