Skip to content

Commit

Permalink
Koifile support
Browse files Browse the repository at this point in the history
  • Loading branch information
eliaperantoni committed Mar 26, 2021
1 parent 79e15d7 commit 3ff3c4a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/target
.idea
/prog.koi
/Koifile
web/dist/
web/snippets/out
web/node_modules
47 changes: 39 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,36 @@ fn main() {
let matches = App::new("Koi")
.version("1.0.0")
.author("Elia Perantoni <[email protected]>")
.arg(Arg::with_name("PATH").help("Path to soure file. If omitted will read from STDIN."))
.arg(
Arg::with_name("path")
.value_name("PATH")
.index(1)
.takes_value(true)
.help("Path to source file.")
)
.arg(
Arg::with_name("stdin")
.short("s")
.long("stdin")
.takes_value(false)
.help("Read script from stdin.")
.conflicts_with("path")
)
.arg(
Arg::with_name("fn")
.short("f")
.long("--fn")
.takes_value(true)
.help("Function to call.")
)
.get_matches();

let source = match matches.value_of("PATH") {
Some(path) => fs::read_to_string(path).unwrap(),
None => {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer).unwrap();
buffer
}
let source = if matches.is_present("stdin") {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer).unwrap();
buffer
} else {
fs::read_to_string(matches.value_of("path").unwrap_or("Koifile")).unwrap()
};

let lexer = new_lexer(source);
Expand All @@ -40,4 +60,15 @@ fn main() {

let mut interpreter = interp::Interpreter::new();
interpreter.run(prog);

if let Some(f) = matches.value_of("fn") {
use ast::{Stmt, Expr};

interpreter.run(vec![
Stmt::Expr(Expr::Call {
func: Box::new(Expr::Get(f.to_string())),
args: vec![]
})
]);
}
}

0 comments on commit 3ff3c4a

Please sign in to comment.