idk some parsing
parent
4c892e1d65
commit
069c64a865
83
src/main.rs
83
src/main.rs
|
|
@ -1,8 +1,11 @@
|
||||||
// mod scene;
|
|
||||||
|
|
||||||
// use crate::scene::Scene;
|
use bnf::{Grammar, ParseTree};
|
||||||
use bnf::Grammar;
|
|
||||||
|
|
||||||
|
const IGNORE: [&'static str; 3] = [
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
];
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
|
|
@ -17,27 +20,71 @@ fn main() {
|
||||||
println!("{}", vm_file);
|
println!("{}", vm_file);
|
||||||
println!("---");
|
println!("---");
|
||||||
|
|
||||||
for tree in parsed {
|
let trees: Vec<ParseTree> = parsed.collect();
|
||||||
println!("{}", tree.lhs);
|
|
||||||
|
if trees.len() == 0 {
|
||||||
|
println!("No parse trees");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Computed {} {} for program", trees.len(), pluralize(trees.len(), "tree", "trees"));
|
||||||
|
|
||||||
|
let tree = trees.get(0).expect("lmao how");
|
||||||
|
|
||||||
|
let program = Program::new(tree);
|
||||||
|
|
||||||
|
println!("{:?}", program);
|
||||||
|
|
||||||
println!("---");
|
println!("---");
|
||||||
|
|
||||||
// println!("{:?}", );
|
|
||||||
|
|
||||||
// let sentence = grammar.generate();
|
|
||||||
// match sentence {
|
|
||||||
// Ok(s) => println!(" --- random program\n{}\n ---", s),
|
|
||||||
// Err(e) => println!("something went wrong: {}!", e)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let scene = Scene::new();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Program {
|
#[derive(Debug)]
|
||||||
declarations: Vec<&dyn Declaration>
|
struct Program<'a> {
|
||||||
|
uses: Vec<UseDeclaration<'a>>
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Declaration {
|
trait TermDigestor {
|
||||||
|
fn get_term_str(&self) -> &'static str;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TermDigestor for Program<'_> {
|
||||||
|
fn get_term_str(&self) -> &'static str {
|
||||||
|
return "<program>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Program<'_> {
|
||||||
|
pub fn new(tree: &ParseTree) -> Self {
|
||||||
|
let program = Program {
|
||||||
|
uses: vec![]
|
||||||
|
};
|
||||||
|
program.digest(tree);
|
||||||
|
return program
|
||||||
|
}
|
||||||
|
|
||||||
|
fn digest(&self, mut tree: &ParseTree) {
|
||||||
|
// println!("digest {}", );
|
||||||
|
// mut because that recursion could get nasty.
|
||||||
|
|
||||||
|
tree.lhs.to_string() == self.get_term_str()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct UseDeclaration<'a> {
|
||||||
|
namespace: Vec<&'a str>
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_namespace(tree: ParseTree) -> Vec<&str> {
|
||||||
|
println!("{}", tree.lhs);
|
||||||
|
return vec![""]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pluralize<'a>(n: usize, singular: &'a str, plural: &'a str) -> &'a str {
|
||||||
|
if n == 1 {
|
||||||
|
return singular;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return plural;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue