Merge branch 'master' into pixel_ascii

This commit is contained in:
Jonathan Turner 2019-07-16 08:04:47 +12:00
commit 49ddfa3940
6 changed files with 54 additions and 17 deletions

View File

@ -15,7 +15,7 @@ crate fn dir_entry_dict(
) -> Result<Spanned<Value>, ShellError> { ) -> Result<Spanned<Value>, ShellError> {
let mut dict = SpannedDictBuilder::new(span); let mut dict = SpannedDictBuilder::new(span);
let filename = entry.file_name(); 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()?; let metadata = entry.metadata()?;
@ -27,7 +27,7 @@ crate fn dir_entry_dict(
FileType::Symlink FileType::Symlink
}; };
dict.insert("file type", Value::string(format!("{:?}", kind))); dict.insert("type", Value::string(format!("{:?}", kind)));
dict.insert( dict.insert(
"readonly", "readonly",
Value::boolean(metadata.permissions().readonly()), Value::boolean(metadata.permissions().readonly()),

View File

@ -161,7 +161,7 @@ pub fn baseline_parse_semantic_token(
TokenNode::Delimited(delimited) => baseline_parse_delimited(delimited, registry, source), TokenNode::Delimited(delimited) => baseline_parse_delimited(delimited, registry, source),
TokenNode::Pipeline(_pipeline) => unimplemented!(), TokenNode::Pipeline(_pipeline) => unimplemented!(),
TokenNode::Operator(_op) => unreachable!(), 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::Identifier(_span) => unreachable!(),
TokenNode::Whitespace(_span) => unreachable!(), TokenNode::Whitespace(_span) => unreachable!(),
TokenNode::Error(error) => Err(*error.item.clone()), TokenNode::Error(error) => Err(*error.item.clone()),

View File

@ -80,7 +80,7 @@ pub fn raw_integer(input: NomSpan) -> IResult<NomSpan, Spanned<i64>> {
)) ))
}) })
} }
/*
pub fn integer(input: NomSpan) -> IResult<NomSpan, TokenNode> { pub fn integer(input: NomSpan) -> IResult<NomSpan, TokenNode> {
trace_step(input, "integer", move |input| { trace_step(input, "integer", move |input| {
let (input, int) = raw_integer(input)?; let (input, int) = raw_integer(input)?;
@ -88,6 +88,7 @@ pub fn integer(input: NomSpan) -> IResult<NomSpan, TokenNode> {
Ok((input, TokenTreeBuilder::spanned_int(*int, int.span))) Ok((input, TokenTreeBuilder::spanned_int(*int, int.span)))
}) })
} }
*/
pub fn operator(input: NomSpan) -> IResult<NomSpan, TokenNode> { pub fn operator(input: NomSpan) -> IResult<NomSpan, TokenNode> {
trace_step(input, "operator", |input| { trace_step(input, "operator", |input| {
@ -217,6 +218,8 @@ pub fn raw_unit(input: NomSpan) -> IResult<NomSpan, Spanned<Unit>> {
tag("KB"), tag("KB"),
tag("kb"), tag("kb"),
tag("Kb"), tag("Kb"),
tag("K"),
tag("k"),
tag("MB"), tag("MB"),
tag("mb"), tag("mb"),
tag("Mb"), tag("Mb"),
@ -241,22 +244,37 @@ pub fn raw_unit(input: NomSpan) -> IResult<NomSpan, Spanned<Unit>> {
pub fn size(input: NomSpan) -> IResult<NomSpan, TokenNode> { pub fn size(input: NomSpan) -> IResult<NomSpan, TokenNode> {
trace_step(input, "size", move |input| { trace_step(input, "size", move |input| {
let mut is_size = false;
let start = input.offset; let start = input.offset;
let (input, int) = raw_integer(input)?; let (input, int) = raw_integer(input)?;
let (input, unit) = raw_unit(input)?; if let Ok((input, Some(size))) = opt(raw_unit)(input) {
let end = input.offset; 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(( Ok((
input, input,
TokenTreeBuilder::spanned_size((*int, *unit), (start, end)), 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<NomSpan, TokenNode> { pub fn leaf(input: NomSpan) -> IResult<NomSpan, TokenNode> {
trace_step(input, "leaf", move |input| { trace_step(input, "leaf", move |input| {
let (input, node) = let (input, node) = alt((size, string, operator, flag, shorthand, var, bare))(input)?;
alt((size, integer, string, operator, flag, shorthand, var, bare))(input)?;
Ok((input, node)) Ok((input, node))
}) })
@ -513,6 +531,7 @@ fn int<T>(frag: &str, neg: Option<T>) -> i64 {
fn is_start_bare_char(c: char) -> bool { fn is_start_bare_char(c: char) -> bool {
match c { match c {
_ if c.is_alphabetic() => true, _ if c.is_alphabetic() => true,
_ if c.is_numeric() => true,
'.' => true, '.' => true,
'\\' => true, '\\' => true,
'/' => true, '/' => true,
@ -596,12 +615,12 @@ mod tests {
#[test] #[test]
fn test_integer() { fn test_integer() {
assert_leaf! { assert_leaf! {
parsers [ integer ] parsers [ size ]
"123" -> 0..3 { Integer(123) } "123" -> 0..3 { Integer(123) }
} }
assert_leaf! { assert_leaf! {
parsers [ integer ] parsers [ size ]
"-123" -> 0..4 { Integer(-123) } "-123" -> 0..4 { Integer(-123) }
} }
} }

View File

@ -47,7 +47,7 @@ impl FromStr for Unit {
fn from_str(input: &str) -> Result<Self, <Self as std::str::FromStr>::Err> { fn from_str(input: &str) -> Result<Self, <Self as std::str::FromStr>::Err> {
match input { match input {
"B" | "b" => Ok(Unit::B), "B" | "b" => Ok(Unit::B),
"KB" | "kb" | "Kb" => Ok(Unit::KB), "KB" | "kb" | "Kb" | "K" | "k" => Ok(Unit::KB),
"MB" | "mb" | "Mb" => Ok(Unit::MB), "MB" | "mb" | "Mb" => Ok(Unit::MB),
"GB" | "gb" | "Gb" => Ok(Unit::GB), "GB" | "gb" | "Gb" => Ok(Unit::GB),
"TB" | "tb" | "Tb" => Ok(Unit::TB), "TB" | "tb" | "Tb" => Ok(Unit::TB),

View File

@ -23,6 +23,24 @@ impl Completer for NuCompleter {
let mut completions = self.file_completer.complete(line, pos, context)?.1; 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 line_chars: Vec<_> = line.chars().collect();
let mut replace_pos = pos; let mut replace_pos = pos;
while replace_pos > 0 { while replace_pos > 0 {

View File

@ -1,4 +1,4 @@
cd tests cd tests
cd dirtest cd dirtest
ls | where size > 1kb | get "file name" | trim | echo $it ls | where size > 1kb | get name | trim | echo $it
exit exit