Marginally better path and expression handling.
This commit is contained in:
parent
17c4aba9c0
commit
36ba81e4c4
15
src/main.rs
15
src/main.rs
|
@ -63,7 +63,8 @@ fn needs_compilation(script_name: &str) -> bool {
|
|||
true
|
||||
}
|
||||
fn output_filename(script_name: &str) -> String {
|
||||
format!(".{}.compiled", script_name.replace("./", ""))
|
||||
let (dir, base_filename) = script_name.rsplit_once("/").unwrap();
|
||||
format!("{}/.{}.compiled", dir, base_filename)
|
||||
}
|
||||
|
||||
fn run_compiled(script_name: &str) {
|
||||
|
@ -88,7 +89,7 @@ fn parse_bash_command(
|
|||
}
|
||||
code.push_str("\")");
|
||||
let peek = iter.peek();
|
||||
if peek.is_none() || peek.contains(&&' ') || peek.contains(&&'\n') {
|
||||
if !is_expr && (peek.is_none() || peek.contains(&&' ') || peek.contains(&&'\n')) {
|
||||
code.push(';');
|
||||
}
|
||||
Ok(())
|
||||
|
@ -138,6 +139,12 @@ fn main() {
|
|||
if (c == 'i' && iter.peek().contains(&&'f'))
|
||||
|| (c == '=' && !iter.peek().contains(&&'=')) {
|
||||
is_expr = true;
|
||||
} else if c == 'f' && iter.peek().contains(&&'o') {
|
||||
iter.next();
|
||||
code.push('o');
|
||||
if iter.peek().contains(&&'r') {
|
||||
is_expr = true;
|
||||
}
|
||||
} else if (c == '{' || c == ';') && is_expr {
|
||||
is_expr = false;
|
||||
} else if c == '\n' && iter.peek().is_some() {
|
||||
|
@ -156,9 +163,11 @@ fn main() -> Result<()> {
|
|||
run_compiled(&script_name);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let script_base_filename = script_name.split("/").last().unwrap();
|
||||
let code = collect_code(&script_name)?;
|
||||
let code_filename = format!("/tmp/{}-rush.rs",
|
||||
script_name.replace("./", "").replace(".", "-"));
|
||||
script_base_filename.replace(".", "-"));
|
||||
let mut file = File::create(&code_filename)?;
|
||||
file.write_all(code.as_bytes())?;
|
||||
|
||||
|
|
Loading…
Reference in New Issue