From 7e78bb4af5cfc5b69e364181aeb2ae67df72b852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Sat, 13 Jul 2019 22:39:41 -0500 Subject: [PATCH 1/6] Informs passing flags is unimplemented instead of quitting. --- src/parser/hir/baseline_parse_tokens.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/hir/baseline_parse_tokens.rs b/src/parser/hir/baseline_parse_tokens.rs index 0a6068656b..12c604e70b 100644 --- a/src/parser/hir/baseline_parse_tokens.rs +++ b/src/parser/hir/baseline_parse_tokens.rs @@ -161,7 +161,7 @@ pub fn baseline_parse_semantic_token( TokenNode::Delimited(delimited) => baseline_parse_delimited(delimited, registry, source), TokenNode::Pipeline(_pipeline) => unimplemented!(), TokenNode::Operator(_op) => unreachable!(), - TokenNode::Flag(_flag) => unimplemented!(), + TokenNode::Flag(_flag) => Err(ShellError::unimplemented("passing flags is not supported yet.")), TokenNode::Identifier(_span) => unreachable!(), TokenNode::Whitespace(_span) => unreachable!(), TokenNode::Error(error) => Err(*error.item.clone()), From 720cc03649b7e014a2709939a9f8baa34d2feeb4 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 14 Jul 2019 16:59:36 +1200 Subject: [PATCH 2/6] Change 'file name' => 'name'. Same for type --- src/object/files.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/object/files.rs b/src/object/files.rs index 0e031b1544..7cea20a405 100644 --- a/src/object/files.rs +++ b/src/object/files.rs @@ -15,7 +15,7 @@ crate fn dir_entry_dict( ) -> Result, ShellError> { let mut dict = SpannedDictBuilder::new(span); let filename = entry.file_name(); - dict.insert("file name", Value::string(filename.to_string_lossy())); + dict.insert("name", Value::string(filename.to_string_lossy())); let metadata = entry.metadata()?; @@ -27,7 +27,7 @@ crate fn dir_entry_dict( FileType::Symlink }; - dict.insert("file type", Value::string(format!("{:?}", kind))); + dict.insert("type", Value::string(format!("{:?}", kind))); dict.insert( "readonly", Value::boolean(metadata.permissions().readonly()), From 2f7f78094d2ca77df996dee9b60a63a80a296360 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 14 Jul 2019 17:09:07 +1200 Subject: [PATCH 3/6] Fix test --- tests/unit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit.txt b/tests/unit.txt index 8804a0f7b0..e4b9829114 100644 --- a/tests/unit.txt +++ b/tests/unit.txt @@ -1,4 +1,4 @@ cd tests cd dirtest -ls | where size > 1kb | get "file name" | trim | echo $it +ls | where size > 1kb | get name | trim | echo $it exit \ No newline at end of file From 520ab55756eaf56359f56944a905879170c90b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Sun, 14 Jul 2019 22:47:01 -0500 Subject: [PATCH 4/6] K raw unit is a kilobyte. --- src/parser/parse/parser.rs | 2 ++ src/parser/parse/unit.rs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/parser/parse/parser.rs b/src/parser/parse/parser.rs index 795b980ee2..5bbd5fdfc7 100644 --- a/src/parser/parse/parser.rs +++ b/src/parser/parse/parser.rs @@ -217,6 +217,8 @@ pub fn raw_unit(input: NomSpan) -> IResult> { tag("KB"), tag("kb"), tag("Kb"), + tag("K"), + tag("k"), tag("MB"), tag("mb"), tag("Mb"), diff --git a/src/parser/parse/unit.rs b/src/parser/parse/unit.rs index 78f223bd99..f8294edc48 100644 --- a/src/parser/parse/unit.rs +++ b/src/parser/parse/unit.rs @@ -46,8 +46,8 @@ impl FromStr for Unit { type Err = (); fn from_str(input: &str) -> Result::Err> { match input { - "B" | "b" => Ok(Unit::B), - "KB" | "kb" | "Kb" => Ok(Unit::KB), + "B" | "b" => Ok(Unit::B), + "KB" | "kb" | "Kb" | "K" | "k" => Ok(Unit::KB), "MB" | "mb" | "Mb" => Ok(Unit::MB), "GB" | "gb" | "Gb" => Ok(Unit::GB), "TB" | "tb" | "Tb" => Ok(Unit::TB), From 5261d5f43fc5dcf936fe41e0c3a91c47c988a33b Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 15 Jul 2019 17:40:27 +1200 Subject: [PATCH 5/6] Fix space and escaped paren completions --- src/shell/completer.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/shell/completer.rs b/src/shell/completer.rs index 6501ff98b9..bcd8577af8 100644 --- a/src/shell/completer.rs +++ b/src/shell/completer.rs @@ -23,6 +23,24 @@ impl Completer for NuCompleter { let mut completions = self.file_completer.complete(line, pos, context)?.1; + for completion in &mut completions { + if completion.replacement.contains("\\ ") { + completion.replacement = completion.replacement.replace("\\ ", " "); + } + if completion.replacement.contains("\\(") { + completion.replacement = completion.replacement.replace("\\(", "("); + } + + if completion.replacement.contains(" ") || completion.replacement.contains("(") { + if !completion.replacement.starts_with("\"") { + completion.replacement = format!("\"{}", completion.replacement); + } + if !completion.replacement.ends_with("\"") { + completion.replacement = format!("{}\"", completion.replacement); + } + } + } + let line_chars: Vec<_> = line.chars().collect(); let mut replace_pos = pos; while replace_pos > 0 { From bb13c2e23487253d1a91bf25aa4c96fc9ad2fd6b Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Tue, 16 Jul 2019 05:48:06 +1200 Subject: [PATCH 6/6] Check for barewords that start with a number --- src/parser/parse/parser.rs | 39 +++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/parser/parse/parser.rs b/src/parser/parse/parser.rs index 795b980ee2..127961da39 100644 --- a/src/parser/parse/parser.rs +++ b/src/parser/parse/parser.rs @@ -80,7 +80,7 @@ pub fn raw_integer(input: NomSpan) -> IResult> { )) }) } - +/* pub fn integer(input: NomSpan) -> IResult { trace_step(input, "integer", move |input| { let (input, int) = raw_integer(input)?; @@ -88,6 +88,7 @@ pub fn integer(input: NomSpan) -> IResult { Ok((input, TokenTreeBuilder::spanned_int(*int, int.span))) }) } +*/ pub fn operator(input: NomSpan) -> IResult { trace_step(input, "operator", |input| { @@ -241,22 +242,37 @@ pub fn raw_unit(input: NomSpan) -> IResult> { pub fn size(input: NomSpan) -> IResult { trace_step(input, "size", move |input| { + let mut is_size = false; let start = input.offset; let (input, int) = raw_integer(input)?; - let (input, unit) = raw_unit(input)?; - let end = input.offset; + if let Ok((input, Some(size))) = opt(raw_unit)(input) { + let end = input.offset; - Ok(( - input, - TokenTreeBuilder::spanned_size((*int, *unit), (start, end)), - )) + // Check to make sure there is no trailing parseable characters + if let Ok((input, Some(extra))) = opt(bare)(input) { + return Err(nom::Err::Error((input, nom::error::ErrorKind::Char))); + } + + Ok(( + input, + TokenTreeBuilder::spanned_size((*int, *size), (start, end)), + )) + } else { + let end = input.offset; + + // Check to make sure there is no trailing parseable characters + if let Ok((input, Some(extra))) = opt(bare)(input) { + return Err(nom::Err::Error((input, nom::error::ErrorKind::Char))); + } + + Ok((input, TokenTreeBuilder::spanned_int((*int), (start, end)))) + } }) } pub fn leaf(input: NomSpan) -> IResult { trace_step(input, "leaf", move |input| { - let (input, node) = - alt((size, integer, string, operator, flag, shorthand, var, bare))(input)?; + let (input, node) = alt((size, string, operator, flag, shorthand, var, bare))(input)?; Ok((input, node)) }) @@ -513,6 +529,7 @@ fn int(frag: &str, neg: Option) -> i64 { fn is_start_bare_char(c: char) -> bool { match c { _ if c.is_alphabetic() => true, + _ if c.is_numeric() => true, '.' => true, '\\' => true, '/' => true, @@ -596,12 +613,12 @@ mod tests { #[test] fn test_integer() { assert_leaf! { - parsers [ integer ] + parsers [ size ] "123" -> 0..3 { Integer(123) } } assert_leaf! { - parsers [ integer ] + parsers [ size ] "-123" -> 0..4 { Integer(-123) } } }