Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 3aa1e5f

Browse files
author
Emily Toop
committed
Address review comments r=nalexander.
* Bump rust version number. * Use `bail` when throwing errors. * Improve edn parser. * Remove references to unused `more` flag. * Improve naming of query and transact commands.
1 parent e0548e9 commit 3aa1e5f

3 files changed

Lines changed: 21 additions & 25 deletions

File tree

build/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_version::version_matches;
1616

1717
/// MIN_VERSION should be changed when there's a new minimum version of rustc required
1818
/// to build the project.
19-
static MIN_VERSION: &'static str = ">= 1.15.1";
19+
static MIN_VERSION: &'static str = ">= 1.17.0";
2020

2121
fn main() {
2222
if !version_matches(MIN_VERSION) {

tools/cli/src/mentat_cli/command_parser.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
// specific language governing permissions and limitations under the License.
1010

1111
use combine::{
12+
any,
1213
eof,
14+
look_ahead,
1315
many1,
1416
parser,
1517
satisfy,
@@ -36,10 +38,10 @@ use edn;
3638
pub static HELP_COMMAND: &'static str = &"help";
3739
pub static OPEN_COMMAND: &'static str = &"open";
3840
pub static CLOSE_COMMAND: &'static str = &"close";
39-
pub static QUERY_COMMAND: &'static str = &"query";
40-
pub static ALT_QUERY_COMMAND: &'static str = &"q";
41-
pub static TRANSACT_COMMAND: &'static str = &"transact";
42-
pub static ALT_TRANSACT_COMMAND: &'static str = &"t";
41+
pub static LONG_QUERY_COMMAND: &'static str = &"query";
42+
pub static SHORT_QUERY_COMMAND: &'static str = &"q";
43+
pub static LONG_TRANSACT_COMMAND: &'static str = &"transact";
44+
pub static SHORT_TRANSACT_COMMAND: &'static str = &"t";
4345

4446
#[derive(Clone, Debug, Eq, PartialEq)]
4547
pub enum Command {
@@ -83,10 +85,10 @@ pub fn command(s: &str) -> Result<Command, cli::Error> {
8385
.with(arguments())
8486
.map(|args| {
8587
if args.len() < 1 {
86-
return Err(cli::ErrorKind::CommandParse("Missing required argument".to_string()).into());
88+
bail!(cli::ErrorKind::CommandParse("Missing required argument".to_string()));
8789
}
8890
if args.len() > 1 {
89-
return Err(cli::ErrorKind::CommandParse(format!("Unrecognized argument {:?}", args[1])).into());
91+
bail!(cli::ErrorKind::CommandParse(format!("Unrecognized argument {:?}", args[1])));
9092
}
9193
Ok(Command::Open(args[0].clone()))
9294
});
@@ -97,29 +99,26 @@ pub fn command(s: &str) -> Result<Command, cli::Error> {
9799
.skip(eof())
98100
.map(|args| {
99101
if args.len() > 0 {
100-
return Err(cli::ErrorKind::CommandParse(format!("Unrecognized argument {:?}", args[0])).into());
102+
bail!(cli::ErrorKind::CommandParse(format!("Unrecognized argument {:?}", args[0])) );
101103
}
102104
Ok(Command::Close)
103105
});
104-
106+
105107
let edn_arg_parser = || spaces()
106-
.with(try(string("["))
107-
.or(try(string("{")))
108-
.then(|d| parser(move |input| {
109-
let _: &str = input;
110-
Ok((d.to_string() + input, Consumed::Empty(input)))
111-
})));
112-
113-
let query_parser = try(string(QUERY_COMMAND)).or(try(string(ALT_QUERY_COMMAND)))
108+
.with(look_ahead(string("[").or(string("{")))
109+
.with(many1::<Vec<_>, _>(try(any())))
110+
);
111+
112+
let query_parser = try(string(LONG_QUERY_COMMAND)).or(try(string(SHORT_QUERY_COMMAND)))
114113
.with(edn_arg_parser())
115114
.map(|x| {
116-
Ok(Command::Query(x))
115+
Ok(Command::Query(x.into_iter().collect()))
117116
});
118117

119-
let transact_parser = try(string(TRANSACT_COMMAND)).or(try(string(ALT_TRANSACT_COMMAND)))
118+
let transact_parser = try(string(LONG_TRANSACT_COMMAND)).or(try(string(SHORT_TRANSACT_COMMAND)))
120119
.with(edn_arg_parser())
121120
.map( |x| {
122-
Ok(Command::Transact(x))
121+
Ok(Command::Transact(x.into_iter().collect()))
123122
});
124123

125124
spaces()

tools/cli/src/mentat_cli/repl.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ impl Repl {
5252

5353
/// Runs the REPL interactively.
5454
pub fn run(&mut self) {
55-
let mut more = false;
5655
let mut input = InputReader::new();
5756

5857
loop {
@@ -61,13 +60,11 @@ impl Repl {
6160
match res {
6261
Ok(MetaCommand(cmd)) => {
6362
debug!("read command: {:?}", cmd);
64-
more = false;
6563
self.handle_command(cmd);
6664
},
67-
Ok(Empty) => more = false,
68-
Ok(More) => { more = true; },
65+
Ok(Empty) |
66+
Ok(More) => (),
6967
Ok(Eof) => {
70-
more = false;
7168
if input.is_tty() {
7269
println!("");
7370
}

0 commit comments

Comments
 (0)