Skip to content

Commit

Permalink
Support array and tuple input (#1200)
Browse files Browse the repository at this point in the history
This PR reworks the variable input mechanism to use nom as a parser; allowing us to parse array inputs and other complex inputs.

Arrays and tuples are parsed using edgeql syntactic conventions. Inside of arrays and tuples,
strings must be quoted using edgeql conventions.

A good follow-up might be to support parsing things like uuids as `<uuid>'acb53d04-184e-11ef-aaab-cb2f1138c5d7'` and similar, as well as using more abbreviated syntax.

Fixes #714

---------

Co-authored-by: Michael J. Sullivan <sully@msully.net>
  • Loading branch information
quinchs and msullivan committed May 23, 2024
1 parent 19c2cf3 commit 8156248
Show file tree
Hide file tree
Showing 5 changed files with 1,275 additions and 103 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ dissimilar = "1.0.6"
notify = "5.0.0"
gethostname = "0.4.1"
bitvec = "1.0.1"
nom = "7.1.3"
bitflags = "1.3.2"

[dev-dependencies]
assert_cmd = "2.0.8"
Expand Down
19 changes: 15 additions & 4 deletions src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustyline::highlight::{Highlighter, PromptInfo};
use rustyline::hint::Hinter;
use rustyline::history::History;
use rustyline::validate::{ValidationContext, ValidationResult, Validator};
use rustyline::{error::ReadlineError, Cmd, KeyEvent, Modifiers};
use rustyline::{self, error::ReadlineError, Cmd, KeyEvent, Modifiers};
use rustyline::{Config, Context, Editor, Helper};
use tokio::sync::mpsc::Receiver;
use tokio::sync::oneshot::Sender;
Expand All @@ -24,7 +24,7 @@ use crate::highlight;
use crate::platform::editor_path;
use crate::print::style::Styler;
use crate::print::Highlight;
use crate::prompt::variable::VariableInput;
use crate::prompt::variable::{InputFlags, VariableInput};
use crate::repl::{FAILURE_MARKER, TX_MARKER};
use edgedb_protocol::value::Value;
use edgeql_parser::preparser::full_statement;
Expand Down Expand Up @@ -361,8 +361,19 @@ pub fn main(mut control: Receiver<Control>) -> Result<(), anyhow::Error> {
}
Err(e) => Err(e)?,
};
match var_type.parse(&text) {
Ok(value) => break (text, value),
match var_type.parse(&text, InputFlags::NONE) {
Ok(parse_result) => {
if !parse_result.0.is_empty() {
// remaining input
println!(
"Bad value: remaining text '{}' is unparsed",
parse_result.0
);
initial = text;
} else {
break (text.to_owned(), parse_result.1);
}
}
Err(e) => {
println!("Bad value: {}", e);
initial = text;
Expand Down
Loading

0 comments on commit 8156248

Please sign in to comment.