svg-filters & basic parser #15

Merged
schrottkatze merged 67 commits from schrottkatze/iowo:svg-filters into main 2024-07-08 18:29:05 +00:00
2 changed files with 36 additions and 13 deletions
Showing only changes of commit f7b61f9e0e - Show all commits

View file

@ -3,7 +3,10 @@ use std::{fs, path::PathBuf};
use clap::Parser;
use lang::{
err_reporting::ErrorCollector,
parser::ast::lossless::{lex, parser},
parser::ast::lossless::{
lex,
parser::{self, parser_to_events::to_events},
},
};
#[derive(Parser)]
@ -17,8 +20,11 @@ fn main() {
let n = args.file.clone();
let f = fs::read_to_string(n.clone()).expect("failed to read file");
println!("toks: {:?}", lex::lex(&f));
let parse_res = parser::parse(&f);
println!("parse: {:?}", parse_res);
println!("evs: {:?}", to_events(&f));
// let parse_res = parser::parse(&f);
// println!("parse: {:?}", parse_res);
// dbg!(lex::lex(&f));
// let mut err_collector = ErrorCollector::new(vec![(n.to_str().unwrap(), &f)]);

View file

@ -11,20 +11,37 @@ use crate::parser::{
use super::lex::{self, SyntaxKind};
mod parsers {
use rowan::GreenNode;
pub mod parser_to_events {
use chumsky::Parser;
use crate::parser::ast::lossless::lex::SyntaxKind;
use crate::parser::ast::lossless::lex::SyntaxKind::{self, *};
use super::SyntaxError;
struct ParseResult {
green_node: GreenNode,
errors: Vec<SyntaxError>,
#[derive(Debug, PartialEq, Eq)]
pub(super) enum Event {
StartNode,
StartErr(SyntaxError),
EatToken,
FinishNode,
FinishErr,
}
trait Parser {
fn parse<'src>(input: &[(SyntaxKind, &'src str)]) -> ParseResult;
#[derive(Debug, PartialEq, Eq)]
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
}
}