Kinda repl
This commit is contained in:
parent
2f74e5785c
commit
7069a70d70
@ -1,14 +1,32 @@
|
|||||||
mod parser;
|
mod parser;
|
||||||
|
|
||||||
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
fn main() {
|
fn repl() {
|
||||||
let args: Vec<String> = env::args().collect();
|
loop {
|
||||||
let mut file = File::open(&args[1]).expect("Could not read file");
|
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();
|
let mut prgm = String::new();
|
||||||
file.read_to_string(&mut prgm).unwrap();
|
file.read_to_string(&mut prgm).unwrap();
|
||||||
let tree = parser::parse(&prgm);
|
let tree = parser::parse(&prgm);
|
||||||
println!("{:?}", tree);
|
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()
|
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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
Loading…
Reference in New Issue
Block a user