forked from Orchid/orchid
A lot of stuff I'm not gonna enumerate
rule fundamentals
This commit is contained in:
53
src/main.rs
53
src/main.rs
@@ -1,17 +1,12 @@
|
||||
use core::ops::Range;
|
||||
use std::{env::current_dir, fs::read_to_string};
|
||||
use std::io;
|
||||
|
||||
use chumsky::prelude::end;
|
||||
use chumsky::{Parser, Stream};
|
||||
use parse::{LexerEntry, FileEntry};
|
||||
// use project::{rule_collector, file_loader, Loaded};
|
||||
use std::env::current_dir;
|
||||
|
||||
mod parse;
|
||||
mod project;
|
||||
mod utils;
|
||||
mod expression;
|
||||
pub use expression::*;
|
||||
mod rule;
|
||||
use project::{rule_collector, Loaded, file_loader};
|
||||
|
||||
fn literal(orig: &[&str]) -> Vec<String> {
|
||||
orig.iter().map(|&s| s.to_owned()).collect()
|
||||
@@ -27,37 +22,15 @@ export (match_sequence $lhs) >>= (match_sequence $rhs) =100=> (bind ($lhs) ($rhs
|
||||
"#;
|
||||
|
||||
fn main() {
|
||||
// let mut input = String::new();
|
||||
// let mut stdin = io::stdin();
|
||||
// stdin.read_to_string(&mut input).unwrap();
|
||||
let ops: Vec<&str> = vec!["...", ">>", ">>=", "[", "]", ",", "$"];
|
||||
let data = read_to_string("./main.orc").unwrap();
|
||||
let lexed = parse::lexer(&ops).parse(data).unwrap();
|
||||
println!("Lexed: {:?}", lexed);
|
||||
let parsr = parse::line_parser().then_ignore(end());
|
||||
// match parsr.parse(data) {
|
||||
// Ok(output) => println!("\nParsed:\n{:?}", output),
|
||||
// Err(e) => println!("\nErrored:\n{:?}", e)
|
||||
// }
|
||||
let lines = lexed.iter().filter_map(|v| {
|
||||
let parse::LexerEntry(_, Range{ end, .. }) = v.last().unwrap().clone();
|
||||
let tuples = v.into_iter().map(|LexerEntry(l, r)| (l.clone(), r.clone()));
|
||||
Some(parsr.parse_recovery_verbose(Stream::from_iter(end..end+1, tuples)))
|
||||
}).collect::<Vec<_>>();
|
||||
for (id, (out, errs)) in lines.into_iter().enumerate() {
|
||||
println!("Parsing line {}", id);
|
||||
if let Some(output) = out { println!("Parsed:\n{:?}", output) }
|
||||
else { println!("Failed to produce output")}
|
||||
if errs.len() > 0 { println!("Errored:\n{:?}", errs)}
|
||||
let cwd = current_dir().unwrap();
|
||||
let collect_rules = rule_collector(move |n| {
|
||||
if n == vec!["prelude"] { Ok(Loaded::Module(PRELUDE.to_string())) }
|
||||
else { file_loader(cwd.clone())(n) }
|
||||
}, literal(&["...", ">>", ">>=", "[", "]", ",", "$", "=", "=>"]));
|
||||
match collect_rules.try_find(&literal(&["main"])) {
|
||||
Ok(rules) => for rule in rules.iter() {
|
||||
println!("{rule:?}")
|
||||
}
|
||||
Err(err) => println!("{:#?}", err)
|
||||
}
|
||||
// let output = parse::file_parser(&ops, &ops).parse(data).unwrap();
|
||||
// let cwd = current_dir().unwrap();
|
||||
// let collect_rules = rule_collector(move |n| {
|
||||
// if n == vec!["prelude"] { Ok(Loaded::Module(PRELUDE.to_string())) }
|
||||
// else { file_loader(cwd.clone())(n) }
|
||||
// }, literal(&["...", ">>", ">>=", "[", "]", ","]));
|
||||
// let rules = collect_rules.try_find(&literal(&["main"])).unwrap();
|
||||
// for rule in rules.iter() {
|
||||
// println!("{:?} ={}=> {:?}", rule.source, rule.priority, rule.target)
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user