diff --git a/build/version.rs b/build/version.rs index 54f8b2a4..6ad73157 100644 --- a/build/version.rs +++ b/build/version.rs @@ -16,7 +16,7 @@ use rustc_version::version_matches; /// MIN_VERSION should be changed when there's a new minimum version of rustc required /// to build the project. -static MIN_VERSION: &'static str = ">= 1.15.1"; +static MIN_VERSION: &'static str = ">= 1.17.0"; fn main() { if !version_matches(MIN_VERSION) { diff --git a/tools/cli/src/mentat_cli/command_parser.rs b/tools/cli/src/mentat_cli/command_parser.rs index d925a907..58a1d4bf 100644 --- a/tools/cli/src/mentat_cli/command_parser.rs +++ b/tools/cli/src/mentat_cli/command_parser.rs @@ -9,7 +9,9 @@ // specific language governing permissions and limitations under the License. use combine::{ + any, eof, + look_ahead, many1, parser, satisfy, @@ -36,10 +38,10 @@ use edn; pub static HELP_COMMAND: &'static str = &"help"; pub static OPEN_COMMAND: &'static str = &"open"; pub static CLOSE_COMMAND: &'static str = &"close"; -pub static QUERY_COMMAND: &'static str = &"query"; -pub static ALT_QUERY_COMMAND: &'static str = &"q"; -pub static TRANSACT_COMMAND: &'static str = &"transact"; -pub static ALT_TRANSACT_COMMAND: &'static str = &"t"; +pub static LONG_QUERY_COMMAND: &'static str = &"query"; +pub static SHORT_QUERY_COMMAND: &'static str = &"q"; +pub static LONG_TRANSACT_COMMAND: &'static str = &"transact"; +pub static SHORT_TRANSACT_COMMAND: &'static str = &"t"; #[derive(Clone, Debug, Eq, PartialEq)] pub enum Command { @@ -83,10 +85,10 @@ pub fn command(s: &str) -> Result { .with(arguments()) .map(|args| { if args.len() < 1 { - return Err(cli::ErrorKind::CommandParse("Missing required argument".to_string()).into()); + bail!(cli::ErrorKind::CommandParse("Missing required argument".to_string())); } if args.len() > 1 { - return Err(cli::ErrorKind::CommandParse(format!("Unrecognized argument {:?}", args[1])).into()); + bail!(cli::ErrorKind::CommandParse(format!("Unrecognized argument {:?}", args[1]))); } Ok(Command::Open(args[0].clone())) }); @@ -97,26 +99,26 @@ pub fn command(s: &str) -> Result { .skip(eof()) .map(|args| { if args.len() > 0 { - return Err(cli::ErrorKind::CommandParse(format!("Unrecognized argument {:?}", args[0])).into()); + bail!(cli::ErrorKind::CommandParse(format!("Unrecognized argument {:?}", args[0])) ); } Ok(Command::Close) }); - - let edn_arg_parser = || spaces() - .with(try(string("[")) - .or(try(string("{"))) - .then(|d| parser(move |input| { - let _: &str = input; - Ok((d.to_string() + input, Consumed::Empty(input))) - }))); - let query_parser = try(string(QUERY_COMMAND)).or(try(string(ALT_QUERY_COMMAND))) + let edn_arg_parser = || spaces() + .with(look_ahead(string("[").or(string("{"))) + .with(many1::, _>(try(any()))) + .and_then(|args| -> Result { + Ok(args.iter().collect()) + }) + ); + + let query_parser = try(string(LONG_QUERY_COMMAND)).or(try(string(SHORT_QUERY_COMMAND))) .with(edn_arg_parser()) .map(|x| { Ok(Command::Query(x)) }); - let transact_parser = try(string(TRANSACT_COMMAND)).or(try(string(ALT_TRANSACT_COMMAND))) + let transact_parser = try(string(LONG_TRANSACT_COMMAND)).or(try(string(SHORT_TRANSACT_COMMAND))) .with(edn_arg_parser()) .map( |x| { Ok(Command::Transact(x)) diff --git a/tools/cli/src/mentat_cli/repl.rs b/tools/cli/src/mentat_cli/repl.rs index 6c002525..9507e7ed 100644 --- a/tools/cli/src/mentat_cli/repl.rs +++ b/tools/cli/src/mentat_cli/repl.rs @@ -52,7 +52,6 @@ impl Repl { /// Runs the REPL interactively. pub fn run(&mut self) { - let mut more = false; let mut input = InputReader::new(); loop { @@ -61,13 +60,11 @@ impl Repl { match res { Ok(MetaCommand(cmd)) => { debug!("read command: {:?}", cmd); - more = false; self.handle_command(cmd); }, - Ok(Empty) => more = false, - Ok(More) => { more = true; }, + Ok(Empty) | + Ok(More) => (), Ok(Eof) => { - more = false; if input.is_tty() { println!(""); }