Kinda repl
This commit is contained in:
parent
2f74e5785c
commit
7069a70d70
@ -1,14 +1,32 @@
|
||||
mod parser;
|
||||
|
||||
use std::io;
|
||||
use std::io::prelude::*;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let mut file = File::open(&args[1]).expect("Could not read file");
|
||||
fn repl() {
|
||||
loop {
|
||||
let mut line = String::new();
|
||||
io::stdin().read_line(&mut line).unwrap();
|
||||
let tree = parser::parse_stmt(&line);
|
||||
println!("{:?}", tree);
|
||||
}
|
||||
}
|
||||
|
||||
fn script(filename: &str) {
|
||||
let mut file = File::open(filename).expect("Could not read file");
|
||||
let mut prgm = String::new();
|
||||
file.read_to_string(&mut prgm).unwrap();
|
||||
let tree = parser::parse(&prgm);
|
||||
println!("{:?}", tree);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() == 1 {
|
||||
repl();
|
||||
} else {
|
||||
script(&args[1]);
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,13 @@ pub fn parse<'a>(prgm: &'a str) -> Vec<Stmt<'a>> {
|
||||
deelang_parser::program(prgm).unwrap()
|
||||
}
|
||||
|
||||
pub fn parse_stmt<'a>(stmt: &'a str) -> Stmt<'a> {
|
||||
let stmt = preprocess(stmt);
|
||||
let stmt = Box::new(stmt);
|
||||
let stmt = Box::leak(stmt);
|
||||
deelang_parser::stmt(stmt).unwrap()
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
Loading…
Reference in New Issue
Block a user