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 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)]);

View file

@ -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
} }
} }