Improvments to interpreter directives parsing
This commit is contained in:
parent
d7181afa91
commit
1f50fcc620
67
src/main.rs
67
src/main.rs
@ -89,7 +89,6 @@ type LineReader = linefeed::Reader<linefeed::terminal::DefaultTerminal>;
|
|||||||
struct Repl<'a> {
|
struct Repl<'a> {
|
||||||
show_tokens: bool,
|
show_tokens: bool,
|
||||||
show_parse: bool,
|
show_parse: bool,
|
||||||
show_eval: bool,
|
|
||||||
evaluator: Evaluator<'a>,
|
evaluator: Evaluator<'a>,
|
||||||
interpreter_directive_sigil: char,
|
interpreter_directive_sigil: char,
|
||||||
reader: LineReader,
|
reader: LineReader,
|
||||||
@ -102,7 +101,6 @@ impl<'a> Repl<'a> {
|
|||||||
Repl {
|
Repl {
|
||||||
show_tokens: false,
|
show_tokens: false,
|
||||||
show_parse: false,
|
show_parse: false,
|
||||||
show_eval: false,
|
|
||||||
evaluator: Evaluator::new_with_opts(None, trace_evaluation),
|
evaluator: Evaluator::new_with_opts(None, trace_evaluation),
|
||||||
interpreter_directive_sigil: '.',
|
interpreter_directive_sigil: '.',
|
||||||
reader: reader,
|
reader: reader,
|
||||||
@ -168,50 +166,47 @@ impl<'a> Repl<'a> {
|
|||||||
_ => return false
|
_ => return false
|
||||||
}
|
}
|
||||||
|
|
||||||
let trimmed_sigil: String = input.chars()
|
let mut iter = input.chars();
|
||||||
.skip(1)
|
iter.next();
|
||||||
.collect();
|
let trimmed_sigil: &str = iter.as_str();
|
||||||
|
|
||||||
let commands: Vec<&str> = trimmed_sigil
|
let commands: Vec<&str> = trimmed_sigil
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let cmd: &str = match commands.get(0).clone() { None => return true, Some(s) => s };
|
let cmd: &str = match commands.get(0).clone() {
|
||||||
|
None => return true,
|
||||||
|
Some(s) => s
|
||||||
|
};
|
||||||
|
|
||||||
match cmd {
|
match cmd {
|
||||||
"exit" | "quit" => process::exit(0),
|
"exit" | "quit" => process::exit(0),
|
||||||
"history" => {
|
"history" => {
|
||||||
},
|
for item in self.reader.history() {
|
||||||
"output_history" => {
|
println!("{}", item);
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
self.update_state(&commands);
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"set" => {
|
||||||
|
let show = match commands[1] {
|
||||||
|
"show" => true,
|
||||||
|
"hide" => false,
|
||||||
|
e => {
|
||||||
|
println!("Bad `set` argument: {}", e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match commands[2] {
|
||||||
|
"tokens" => self.show_tokens = show,
|
||||||
|
"parse" => self.show_parse = show,
|
||||||
|
"eval" => self.evaluator.trace_evaluation = show,
|
||||||
|
e => {
|
||||||
|
println!("Bad `show`/`hide` argument: {}", e);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_state(&mut self, input: &Vec<&str>) {
|
|
||||||
match input[..] {
|
|
||||||
["set", "show", "tokens", "true"] => {
|
|
||||||
self.show_tokens = true;
|
|
||||||
}
|
|
||||||
["set", "show", "tokens", "false"] => {
|
|
||||||
self.show_tokens = false;
|
|
||||||
}
|
|
||||||
["set", "show", "parse", "true"] => {
|
|
||||||
self.show_parse = true;
|
|
||||||
}
|
|
||||||
["set", "show", "parse", "false"] => {
|
|
||||||
self.show_parse = false;
|
|
||||||
}
|
|
||||||
["set", "show", "eval", "true"] => {
|
|
||||||
self.evaluator.trace_evaluation = true;
|
|
||||||
}
|
|
||||||
["set", "show", "eval", "false"] => {
|
|
||||||
self.evaluator.trace_evaluation = false;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user