-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79e15d7
commit 3ff3c4a
Showing
2 changed files
with
40 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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![] | ||
}) | ||
]); | ||
} | ||
} |