diff --git a/demo/buildup.dee b/demo/buildup.dee index 16f3d39..f600893 100644 --- a/demo/buildup.dee +++ b/demo/buildup.dee @@ -28,4 +28,4 @@ obj <- { field <- "hello" method <- x -> x * 2 } -## Object creation \ No newline at end of file +## Object creation diff --git a/rust/src/main.rs b/rust/src/main.rs index f2bb78f..47891a9 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -1,5 +1,14 @@ mod parser; +use std::io::prelude::*; +use std::env; +use std::fs::File; + fn main() { - println!("Hello, world!"); + let args: Vec = env::args().collect(); + let mut file = File::open(&args[1]).expect("Could not read file"); + let mut prgm = String::new(); + file.read_to_string(&mut prgm).unwrap(); + let tree = parser::parse(&prgm); + println!("{:?}", tree); } diff --git a/rust/src/parser.rs b/rust/src/parser.rs index 94c89a0..b547a05 100644 --- a/rust/src/parser.rs +++ b/rust/src/parser.rs @@ -90,6 +90,7 @@ fn preprocess(input: &str) -> String { } else if curr > &count { while stack.last().unwrap() > &count { output.push_str("<<<"); + output.push('\n'); stack.pop(); } } @@ -99,9 +100,17 @@ fn preprocess(input: &str) -> String { output.push_str(line.trim()); output.push('\n'); } + println!("{}", output); output } +pub fn parse<'a>(prgm: &'a str) -> Vec> { + let prgm = preprocess(prgm); + let prgm = Box::new(prgm); + let prgm = Box::leak(prgm); + deelang_parser::program(prgm).unwrap() +} + #[cfg(test)] mod test { @@ -109,7 +118,7 @@ mod test { #[test] fn test_comments() { - let prgm = "## This is a comment + let prgm = r"## This is a comment apple <- 1 ## This is too ## This comment ends the file"; let expected = vec![Stmt::Assignment("apple", Expr::Num(1.0))]; @@ -251,9 +260,12 @@ foo <- x -> y -> x * y"; let expected = r" >>>. >>>. -<<<. +<<< +. >>>. -<<<<<<. +<<< +<<< +. ## Hello World "; assert_eq!(preprocess(prgm), expected);