From fa997c1be21aeed3ac5f09992f51f00649e9e16b Mon Sep 17 00:00:00 2001 From: linsy king Date: Fri, 31 Mar 2023 18:37:29 +0800 Subject: [PATCH] sample --- examples/syn.meow | 9 +++++++++ src/main.rs | 20 ++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 examples/syn.meow diff --git a/examples/syn.meow b/examples/syn.meow new file mode 100644 index 0000000..2269c38 --- /dev/null +++ b/examples/syn.meow @@ -0,0 +1,9 @@ +hh() { "dd" } +sdf(hhs, fff) { + "fd" = hhg("ss"); + var ldk = { + var s = ("ff" + hhs + "d"); + "hhh" + }; + "ffs" +} diff --git a/src/main.rs b/src/main.rs index ae5b0b9..49146f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::env::args; + pub mod ast; #[macro_use] @@ -6,18 +8,12 @@ extern crate lalrpop_util; lalrpop_mod!(pub parse); // synthesized by LALRPOP fn main() { + let mut argv = args(); + argv.next(); + let fp = argv.next().expect("unknown file"); + let fc = std::fs::read_to_string(fp).expect("failed to open the file"); let res = parse::ProgramParser::new() - .parse( - r#"hh() { "dd" } - sdf(hhs, fff) { - "fd" = hhg("ss"); - var ldk = { - var s = ("ff" + hhs + "d"); - "hhh" - }; - "ffs" - }"#, - ) - .expect("Not expected!"); + .parse(fc.as_str()) + .expect("unexpected token!"); println!("{:?}", res); }