Move internal terminology to tables/rows

This commit is contained in:
Jonathan Turner 2019-09-06 04:23:42 +12:00
parent 0a9897c5ca
commit dcd97b6346
70 changed files with 220 additions and 219 deletions

View File

@ -7,9 +7,9 @@ use crate::commands::plugin::JsonRpc;
use crate::commands::plugin::{PluginCommand, PluginSink};
use crate::commands::whole_stream_command;
use crate::context::Context;
use crate::data::Value;
pub(crate) use crate::errors::ShellError;
use crate::git::current_branch;
use crate::object::Value;
use crate::parser::registry::Signature;
use crate::parser::{hir, CallNode, Pipeline, PipelineElement, TokenNode};
use crate::prelude::*;
@ -265,7 +265,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
context.shell_manager.clone(),
)));
let edit_mode = crate::object::config::config(Span::unknown())?
let edit_mode = crate::data::config::config(Span::unknown())?
.get("edit_mode")
.map(|s| match s.as_string().unwrap().as_ref() {
"vi" => EditMode::Vi,

View File

@ -1,4 +1,4 @@
use crate::object::Value;
use crate::data::Value;
#[derive(Debug)]
pub enum LogLevel {}

View File

@ -1,7 +1,7 @@
use crate::context::{SourceMap, SpanSource};
use crate::errors::ShellError;
use crate::evaluate::Scope;
use crate::object::Value;
use crate::data::Value;
use crate::parser::hir;
use crate::parser::{registry, ConfigDeserializer};
use crate::prelude::*;

View File

@ -2,7 +2,7 @@ use crate::prelude::*;
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{config, Value};
use crate::data::{config, Value};
use crate::parser::hir::SyntaxType;
use crate::parser::registry::{self};
use std::iter::FromIterator;
@ -55,7 +55,7 @@ pub fn config(
}: ConfigArgs,
RunnableContext { name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
let mut result = crate::object::config::config(name)?;
let mut result = crate::data::config::config(name)?;
if let Some(v) = get {
let key = v.to_string();
@ -74,7 +74,7 @@ pub fn config(
config::write_config(&result)?;
return Ok(stream![Tagged::from_simple_spanned_item(
Value::Object(result.into()),
Value::Row(result.into()),
value.span()
)]
.from_input_stream());
@ -90,7 +90,7 @@ pub fn config(
config::write_config(&result)?;
return Ok(stream![Tagged::from_simple_spanned_item(
Value::Object(result.into()),
Value::Row(result.into()),
span
)]
.from_input_stream());
@ -123,9 +123,9 @@ pub fn config(
)));
}
let obj = VecDeque::from_iter(vec![Value::Object(result.into()).simple_spanned(v.span())]);
let obj = VecDeque::from_iter(vec![Value::Row(result.into()).simple_spanned(v.span())]);
return Ok(obj.from_input_stream());
}
return Ok(vec![Value::Object(result.into()).simple_spanned(name)].into());
return Ok(vec![Value::Row(result.into()).simple_spanned(name)].into());
}

View File

@ -1,5 +1,5 @@
use crate::errors::ShellError;
use crate::object::{Dictionary, Value};
use crate::data::{Dictionary, Value};
use crate::prelude::*;
use chrono::{DateTime, Local, Utc};
@ -17,9 +17,7 @@ impl WholeStreamCommand for Date {
}
fn signature(&self) -> Signature {
Signature::build("date")
.switch("utc")
.switch("local")
Signature::build("date").switch("utc").switch("local")
}
fn usage(&self) -> &str {
@ -72,7 +70,7 @@ where
Tagged::from_simple_spanned_item(Value::string(format!("{}", tz)), span),
);
Tagged::from_simple_spanned_item(Value::Object(Dictionary::from(indexmap)), span)
Tagged::from_simple_spanned_item(Value::Row(Dictionary::from(indexmap)), span)
}
pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {

View File

@ -1,7 +1,7 @@
use crate::commands::UnevaluatedCallInfo;
use crate::context::SpanSource;
use crate::data::Value;
use crate::errors::ShellError;
use crate::object::Value;
use crate::parser::hir::SyntaxType;
use crate::parser::registry::Signature;
use crate::prelude::*;
@ -106,7 +106,7 @@ fn run(
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
for res in result_vec {
match res {
Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => {
Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => {
for l in list {
yield Ok(ReturnSuccess::Value(l));
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ExpectedRange;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use bson::{decode_document, spec::BinarySubtype, Bson};
use std::str::FromStr;
@ -48,7 +48,7 @@ fn convert_bson_value_to_nu_value(
Ok(match v {
Bson::FloatingPoint(n) => Value::Primitive(Primitive::from(*n)).tagged(tag),
Bson::String(s) => Value::Primitive(Primitive::String(String::from(s))).tagged(tag),
Bson::Array(a) => Value::List(bson_array(a, tag)?).tagged(tag),
Bson::Array(a) => Value::Table(bson_array(a, tag)?).tagged(tag),
Bson::Document(doc) => {
let mut collected = TaggedDictBuilder::new(tag);
for (k, v) in doc.iter() {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use csv::ReaderBuilder;
@ -16,8 +16,7 @@ impl WholeStreamCommand for FromCSV {
}
fn signature(&self) -> Signature {
Signature::build("from-csv")
.switch("headerless")
Signature::build("from-csv").switch("headerless")
}
fn usage(&self) -> &str {
@ -78,7 +77,7 @@ pub fn from_csv_string_to_value(
}
}
Ok(Tagged::from_item(Value::List(rows), tag))
Ok(Tagged::from_item(Value::Table(rows), tag))
}
fn from_csv(
@ -116,7 +115,7 @@ fn from_csv(
match from_csv_string_to_value(concat_string, skip_headers, name_span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use std::collections::HashMap;
@ -94,7 +94,7 @@ fn from_ini(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
match from_ini_string_to_value(concat_string, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct FromJSON;
@ -15,8 +15,7 @@ impl WholeStreamCommand for FromJSON {
}
fn signature(&self) -> Signature {
Signature::build("from-json")
.switch("objects")
Signature::build("from-json").switch("objects")
}
fn usage(&self) -> &str {
@ -44,7 +43,7 @@ fn convert_json_value_to_nu_value(v: &serde_hjson::Value, tag: impl Into<Tag>) -
serde_hjson::Value::String(s) => {
Value::Primitive(Primitive::String(String::from(s))).tagged(tag)
}
serde_hjson::Value::Array(a) => Value::List(
serde_hjson::Value::Array(a) => Value::Table(
a.iter()
.map(|x| convert_json_value_to_nu_value(x, tag))
.collect(),
@ -126,7 +125,7 @@ fn from_json(
match from_json_string_to_value(concat_string, name_span) {
Ok(x) =>
match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::errors::ShellError;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use rusqlite::{types::ValueRef, Connection, Row, NO_PARAMS};
use std::io::Write;
@ -76,11 +76,11 @@ pub fn convert_sqlite_file_to_nu_value(
"table_name".to_string(),
Value::Primitive(Primitive::String(table_name)).tagged(tag.clone()),
);
meta_dict.insert_tagged("table_values", Value::List(out).tagged(tag.clone()));
meta_dict.insert_tagged("table_values", Value::Table(out).tagged(tag.clone()));
meta_out.push(meta_dict.into_tagged_value());
}
let tag = tag.into();
Ok(Value::List(meta_out).tagged(tag))
Ok(Value::Table(meta_out).tagged(tag))
}
fn convert_sqlite_row_to_nu_value(
@ -140,7 +140,7 @@ fn from_sqlite(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputSt
Value::Binary(vb) =>
match from_sqlite_bytes_to_value(vb, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct FromTOML;
@ -34,7 +34,7 @@ pub fn convert_toml_value_to_nu_value(v: &toml::Value, tag: impl Into<Tag>) -> T
toml::Value::Integer(n) => Value::number(n).tagged(tag),
toml::Value::Float(n) => Value::number(n).tagged(tag),
toml::Value::String(s) => Value::Primitive(Primitive::String(String::from(s))).tagged(tag),
toml::Value::Array(a) => Value::List(
toml::Value::Array(a) => Value::Table(
a.iter()
.map(|x| convert_toml_value_to_nu_value(x, tag))
.collect(),
@ -98,7 +98,7 @@ pub fn from_toml(
match from_toml_string_to_value(concat_string, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use csv::ReaderBuilder;
@ -78,7 +78,7 @@ pub fn from_tsv_string_to_value(
}
}
Ok(Tagged::from_item(Value::List(rows), tag))
Ok(Tagged::from_item(Value::Table(rows), tag))
}
fn from_tsv(
@ -116,7 +116,7 @@ fn from_tsv(
match from_tsv_string_to_value(concat_string, skip_headers, name_span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct FromXML;
@ -55,7 +55,7 @@ fn from_node_to_value<'a, 'd>(n: &roxmltree::Node<'a, 'd>, tag: impl Into<Tag>)
.collect();
let mut collected = TaggedDictBuilder::new(tag);
collected.insert(name.clone(), Value::List(children_values));
collected.insert(name.clone(), Value::Table(children_values));
collected.into_tagged_value()
} else if n.is_comment() {
@ -113,7 +113,7 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
match from_xml_string_to_value(concat_string, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct FromYAML;
@ -62,7 +62,7 @@ fn convert_yaml_value_to_nu_value(v: &serde_yaml::Value, tag: impl Into<Tag>) ->
Value::Primitive(Primitive::from(n.as_f64().unwrap())).tagged(tag)
}
serde_yaml::Value::String(s) => Value::string(s).tagged(tag),
serde_yaml::Value::Sequence(a) => Value::List(
serde_yaml::Value::Sequence(a) => Value::Table(
a.iter()
.map(|x| convert_yaml_value_to_nu_value(x, tag))
.collect(),
@ -127,7 +127,7 @@ fn from_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStre
match from_yaml_string_to_value(concat_string, span) {
Ok(x) => match x {
Tagged { item: Value::List(list), .. } => {
Tagged { item: Value::Table(list), .. } => {
for l in list {
yield ReturnSuccess::value(l);
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::prelude::*;
pub struct Get;
@ -73,7 +73,7 @@ pub fn get(
for field in &fields {
match get_member(field, &item) {
Ok(Tagged {
item: Value::List(l),
item: Value::Table(l),
..
}) => {
for item in l {

View File

@ -1,7 +1,7 @@
use crate::commands::command::CommandAction;
use crate::commands::PerItemCommand;
use crate::errors::ShellError;
use crate::object::{command_dict, TaggedDictBuilder};
use crate::data::{command_dict, TaggedDictBuilder};
use crate::parser::registry;
use crate::prelude::*;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
use log::trace;

View File

@ -266,7 +266,7 @@ macro_rules! command {
Extract {
$($extract:tt)* {
use $crate::object::types::ExtractType;
use $crate::data::types::ExtractType;
let value = $args.expect_nth($($positional_count)*)?;
Block::extract(value)?
}
@ -321,7 +321,7 @@ macro_rules! command {
Extract {
$($extract:tt)* {
use $crate::object::types::ExtractType;
use $crate::data::types::ExtractType;
let value = $args.expect_nth($($positional_count)*)?;
<$param_kind>::extract(&value)?
}

View File

@ -1,7 +1,7 @@
use crate::commands::UnevaluatedCallInfo;
use crate::context::SpanSource;
use crate::data::Value;
use crate::errors::ShellError;
use crate::object::Value;
use crate::parser::hir::SyntaxType;
use crate::parser::registry::Signature;
use crate::prelude::*;
@ -107,7 +107,7 @@ fn run(
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
for res in result_vec {
match res {
Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => {
Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => {
for l in list {
yield Ok(ReturnSuccess::Value(l));
}

View File

@ -1,7 +1,7 @@
use crate::commands::WholeStreamCommand;
use crate::context::CommandRegistry;
use crate::errors::ShellError;
use crate::object::base::select_fields;
use crate::data::base::select_fields;
use crate::prelude::*;
#[derive(Deserialize)]

View File

@ -1,7 +1,7 @@
use crate::commands::UnevaluatedCallInfo;
use crate::context::SpanSource;
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::parser::hir::SyntaxType;
use crate::parser::registry::Signature;
use crate::prelude::*;
@ -116,7 +116,7 @@ fn run(
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
for res in result_vec {
match res {
Ok(ReturnSuccess::Value(Tagged { item: Value::List(list), ..})) => {
Ok(ReturnSuccess::Value(Tagged { item: Value::Table(list), ..})) => {
for l in list {
yield Ok(ReturnSuccess::Value(l));
}

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::TaggedDictBuilder;
use crate::data::TaggedDictBuilder;
use crate::prelude::*;
use std::time::Duration;
use std::usize;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::base::reject_fields;
use crate::data::base::reject_fields;
use crate::prelude::*;
#[derive(Deserialize)]

View File

@ -1,6 +1,6 @@
use crate::commands::{UnevaluatedCallInfo, WholeStreamCommand};
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::prelude::*;
use std::path::{Path, PathBuf};

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::TaggedDictBuilder;
use crate::data::TaggedDictBuilder;
use crate::prelude::*;
pub struct Shells;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{TaggedDictBuilder, Value};
use crate::data::{TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct Size;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::data::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use log::trace;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
use log::trace;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{TaggedDictBuilder, Value};
use crate::data::{TaggedDictBuilder, Value};
use crate::prelude::*;
pub struct Tags;

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Dictionary, Primitive, Value};
use crate::data::{Dictionary, Primitive, Value};
use crate::prelude::*;
use bson::{encode_document, oid::ObjectId, spec::BinarySubtype, Bson, Document};
use std::convert::TryInto;
@ -51,14 +51,14 @@ pub fn value_to_bson_value(v: &Tagged<Value>) -> Result<Bson, ShellError> {
Value::Primitive(Primitive::Nothing) => Bson::Null,
Value::Primitive(Primitive::String(s)) => Bson::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => Bson::String(s.display().to_string()),
Value::List(l) => Bson::Array(
Value::Table(l) => Bson::Array(
l.iter()
.map(|x| value_to_bson_value(x))
.collect::<Result<_, _>>()?,
),
Value::Block(_) => Bson::Null,
Value::Binary(b) => Bson::Binary(BinarySubtype::Generic, b.clone()),
Value::Object(o) => object_value_to_bson(o)?,
Value::Row(o) => object_value_to_bson(o)?,
})
}
@ -241,7 +241,7 @@ fn to_bson(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
use csv::WriterBuilder;
@ -39,8 +39,8 @@ pub fn value_to_csv_value(v: &Value) -> Value {
Value::Primitive(Primitive::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())),
Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(b.clone())),
Value::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())),
Value::Object(o) => Value::Object(o.clone()),
Value::List(l) => Value::List(l.clone()),
Value::Row(o) => Value::Row(o.clone()),
Value::Table(l) => Value::Table(l.clone()),
Value::Block(_) => Value::Primitive(Primitive::Nothing),
_ => Value::Primitive(Primitive::Nothing),
}
@ -51,8 +51,8 @@ fn to_string_helper(v: &Value) -> Result<String, ShellError> {
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
Value::List(_) => return Ok(String::from("[list list]")),
Value::Object(_) => return Ok(String::from("[object]")),
Value::Table(_) => return Ok(String::from("[list list]")),
Value::Row(_) => return Ok(String::from("[object]")),
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
_ => return Err(ShellError::string("Unexpected value")),
}
@ -72,7 +72,7 @@ fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
pub fn to_string(v: &Value) -> Result<String, ShellError> {
match v {
Value::Object(o) => {
Value::Row(o) => {
let mut wtr = WriterBuilder::new().from_writer(vec![]);
let mut fields: VecDeque<String> = VecDeque::new();
let mut values: VecDeque<String> = VecDeque::new();
@ -92,7 +92,7 @@ pub fn to_string(v: &Value) -> Result<String, ShellError> {
)
.map_err(|_| ShellError::string("Could not convert record"))?);
}
Value::List(list) => {
Value::Table(list) => {
let mut wtr = WriterBuilder::new().from_writer(vec![]);
let merged_descriptors = merge_descriptors(&list);
@ -134,7 +134,7 @@ fn to_csv(
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
pub struct ToJSON;
@ -48,7 +48,7 @@ pub fn value_to_json_value(v: &Tagged<Value>) -> Result<serde_json::Value, Shell
Value::Primitive(Primitive::String(s)) => serde_json::Value::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => serde_json::Value::String(s.display().to_string()),
Value::List(l) => serde_json::Value::Array(json_list(l)?),
Value::Table(l) => serde_json::Value::Array(json_list(l)?),
Value::Block(_) => serde_json::Value::Null,
Value::Binary(b) => serde_json::Value::Array(
b.iter()
@ -57,7 +57,7 @@ pub fn value_to_json_value(v: &Tagged<Value>) -> Result<serde_json::Value, Shell
})
.collect(),
),
Value::Object(o) => {
Value::Row(o) => {
let mut m = serde_json::Map::new();
for (k, v) in o.entries.iter() {
m.insert(k.clone(), value_to_json_value(v)?);
@ -85,7 +85,7 @@ fn to_json(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Dictionary, Primitive, Value};
use crate::data::{Dictionary, Primitive, Value};
use crate::prelude::*;
use hex::encode;
use rusqlite::{Connection, NO_PARAMS};
@ -71,7 +71,7 @@ fn comma_concat(acc: String, current: String) -> String {
fn get_columns(rows: &Vec<Tagged<Value>>) -> Result<String, std::io::Error> {
match &rows[0].item {
Value::Object(d) => Ok(d
Value::Row(d) => Ok(d
.entries
.iter()
.map(|(k, _v)| k.clone())
@ -107,7 +107,7 @@ fn get_insert_values(rows: Vec<Tagged<Value>>) -> Result<String, std::io::Error>
let values: Result<Vec<_>, _> = rows
.into_iter()
.map(|value| match value.item {
Value::Object(d) => Ok(format!(
Value::Row(d) => Ok(format!(
"({})",
d.entries
.iter()
@ -139,7 +139,7 @@ fn generate_statements(table: Dictionary) -> Result<(String, String), std::io::E
};
let (columns, insert_values) = match table.entries.get("table_values") {
Some(Tagged {
item: Value::List(l),
item: Value::Table(l),
..
}) => (get_columns(l), get_insert_values(l.to_vec())),
_ => {
@ -169,7 +169,7 @@ fn sqlite_input_stream_to_bytes(
let tag = values[0].tag.clone();
for value in values.into_iter() {
match value.item() {
Value::Object(d) => {
Value::Row(d) => {
let (create, insert) = generate_statements(d.to_owned())?;
match conn
.execute(&create, NO_PARAMS)

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
pub struct ToTOML;
@ -47,12 +47,12 @@ pub fn value_to_toml_value(v: &Tagged<Value>) -> Result<toml::Value, ShellError>
Value::Primitive(Primitive::String(s)) => toml::Value::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => toml::Value::String(s.display().to_string()),
Value::List(l) => toml::Value::Array(collect_values(l)?),
Value::Table(l) => toml::Value::Array(collect_values(l)?),
Value::Block(_) => toml::Value::String("<Block>".to_string()),
Value::Binary(b) => {
toml::Value::Array(b.iter().map(|x| toml::Value::Integer(*x as i64)).collect())
}
Value::Object(o) => {
Value::Row(o) => {
let mut m = toml::map::Map::new();
for (k, v) in o.entries.iter() {
m.insert(k.clone(), value_to_toml_value(v)?);
@ -80,7 +80,7 @@ fn to_toml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
use csv::WriterBuilder;
@ -39,8 +39,8 @@ pub fn value_to_tsv_value(v: &Value) -> Value {
Value::Primitive(Primitive::Boolean(b)) => Value::Primitive(Primitive::Boolean(b.clone())),
Value::Primitive(Primitive::Bytes(b)) => Value::Primitive(Primitive::Bytes(b.clone())),
Value::Primitive(Primitive::Date(d)) => Value::Primitive(Primitive::Date(d.clone())),
Value::Object(o) => Value::Object(o.clone()),
Value::List(l) => Value::List(l.clone()),
Value::Row(o) => Value::Row(o.clone()),
Value::Table(l) => Value::Table(l.clone()),
Value::Block(_) => Value::Primitive(Primitive::Nothing),
_ => Value::Primitive(Primitive::Nothing),
}
@ -51,8 +51,8 @@ fn to_string_helper(v: &Value) -> Result<String, ShellError> {
Value::Primitive(Primitive::Date(d)) => Ok(d.to_string()),
Value::Primitive(Primitive::Bytes(b)) => Ok(format!("{}", b)),
Value::Primitive(Primitive::Boolean(_)) => Ok(v.as_string()?),
Value::List(_) => return Ok(String::from("[table]")),
Value::Object(_) => return Ok(String::from("[row]")),
Value::Table(_) => return Ok(String::from("[table]")),
Value::Row(_) => return Ok(String::from("[row]")),
Value::Primitive(Primitive::String(s)) => return Ok(s.to_string()),
_ => Err(ShellError::string("Unexpected value")),
}
@ -72,7 +72,7 @@ fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
pub fn to_string(v: &Value) -> Result<String, ShellError> {
match v {
Value::Object(o) => {
Value::Row(o) => {
let mut wtr = WriterBuilder::new().delimiter(b'\t').from_writer(vec![]);
let mut fields: VecDeque<String> = VecDeque::new();
let mut values: VecDeque<String> = VecDeque::new();
@ -91,7 +91,7 @@ pub fn to_string(v: &Value) -> Result<String, ShellError> {
)
.map_err(|_| ShellError::string("Could not convert record"))?);
}
Value::List(list) => {
Value::Table(list) => {
let mut wtr = WriterBuilder::new().delimiter(b'\t').from_writer(vec![]);
let merged_descriptors = merge_descriptors(&list);
@ -133,7 +133,7 @@ fn to_tsv(
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,5 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
pub struct ToYAML;
@ -45,7 +45,7 @@ pub fn value_to_yaml_value(v: &Tagged<Value>) -> Result<serde_yaml::Value, Shell
Value::Primitive(Primitive::String(s)) => serde_yaml::Value::String(s.clone()),
Value::Primitive(Primitive::Path(s)) => serde_yaml::Value::String(s.display().to_string()),
Value::List(l) => {
Value::Table(l) => {
let mut out = vec![];
for value in l {
@ -60,7 +60,7 @@ pub fn value_to_yaml_value(v: &Tagged<Value>) -> Result<serde_yaml::Value, Shell
.map(|x| serde_yaml::Value::Number(serde_yaml::Number::from(*x)))
.collect(),
),
Value::Object(o) => {
Value::Row(o) => {
let mut m = serde_yaml::Mapping::new();
for (k, v) in o.entries.iter() {
m.insert(
@ -81,7 +81,7 @@ fn to_yaml(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
let to_process_input = if input.len() > 1 {
let tag = input[0].tag;
vec![Tagged { item: Value::List(input), tag } ]
vec![Tagged { item: Value::Table(input), tag } ]
} else if input.len() == 1 {
input
} else {

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::prelude::*;
pub struct Trim;

View File

@ -1,6 +1,6 @@
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::{Dictionary, Value};
use crate::data::{Dictionary, Value};
use crate::parser::registry::Signature;
use crate::prelude::*;
use indexmap::IndexMap;
@ -39,6 +39,6 @@ pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStrea
Tagged::from_simple_spanned_item(Value::string(clap::crate_version!()), span),
);
let value = Tagged::from_simple_spanned_item(Value::Object(Dictionary::from(indexmap)), span);
let value = Tagged::from_simple_spanned_item(Value::Row(Dictionary::from(indexmap)), span);
Ok(OutputStream::one(value))
}

View File

@ -1,5 +1,5 @@
use crate::errors::ShellError;
use crate::object::Value;
use crate::data::Value;
use crate::prelude::*;
use crate::commands::WholeStreamCommand;

View File

@ -1,7 +1,7 @@
use crate::context::CommandRegistry;
use crate::data::TaggedDictBuilder;
use crate::errors::ShellError;
use crate::evaluate::{evaluate_baseline_expr, Scope};
use crate::object::TaggedDictBuilder;
use crate::parser::{hir, Operator};
use crate::prelude::*;
use crate::Text;
@ -170,10 +170,10 @@ impl Block {
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Serialize, Deserialize)]
pub enum Value {
Primitive(Primitive),
Object(crate::object::Dictionary),
Row(crate::data::Dictionary),
#[serde(with = "serde_bytes")]
Binary(Vec<u8>),
List(Vec<Tagged<Value>>),
Table(Vec<Tagged<Value>>),
Block(Block),
}
@ -220,8 +220,8 @@ impl fmt::Debug for ValueDebug<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.value.item() {
Value::Primitive(p) => p.debug(f),
Value::Object(o) => o.debug(f),
Value::List(l) => debug_list(l).fmt(f),
Value::Row(o) => o.debug(f),
Value::Table(l) => debug_list(l).fmt(f),
Value::Block(_) => write!(f, "[[block]]"),
Value::Binary(_) => write!(f, "[[binary]]"),
}
@ -293,12 +293,12 @@ impl std::convert::TryFrom<&Tagged<Value>> for Vec<u8> {
}
}
impl<'a> std::convert::TryFrom<&'a Tagged<Value>> for &'a crate::object::Dictionary {
impl<'a> std::convert::TryFrom<&'a Tagged<Value>> for &'a crate::data::Dictionary {
type Error = ShellError;
fn try_from(value: &'a Tagged<Value>) -> Result<&'a crate::object::Dictionary, ShellError> {
fn try_from(value: &'a Tagged<Value>) -> Result<&'a crate::data::Dictionary, ShellError> {
match value.item() {
Value::Object(d) => Ok(d),
Value::Row(d) => Ok(d),
v => Err(ShellError::type_error(
"Dictionary",
value.copy_span(v.type_name()),
@ -340,8 +340,8 @@ impl Value {
pub(crate) fn type_name(&self) -> String {
match self {
Value::Primitive(p) => p.type_name(),
Value::Object(_) => format!("object"),
Value::List(_) => format!("list"),
Value::Row(_) => format!("object"),
Value::Table(_) => format!("list"),
Value::Block(_) => format!("block"),
Value::Binary(_) => format!("binary"),
}
@ -351,26 +351,26 @@ impl Value {
pub fn data_descriptors(&self) -> Vec<String> {
match self {
Value::Primitive(_) => vec![],
Value::Object(o) => o
Value::Row(o) => o
.entries
.keys()
.into_iter()
.map(|x| x.to_string())
.collect(),
Value::Block(_) => vec![],
Value::List(_) => vec![],
Value::Table(_) => vec![],
Value::Binary(_) => vec![],
}
}
pub(crate) fn get_data_by_key(&self, name: &str) -> Option<&Tagged<Value>> {
match self {
Value::Object(o) => o.get_data_by_key(name),
Value::List(l) => {
Value::Row(o) => o.get_data_by_key(name),
Value::Table(l) => {
for item in l {
match item {
Tagged {
item: Value::Object(o),
item: Value::Row(o),
..
} => match o.get_data_by_key(name) {
Some(v) => return Some(v),
@ -407,7 +407,7 @@ impl Value {
let split_path: Vec<_> = path.split(".").collect();
if let Value::Object(ref mut o) = new_obj {
if let Value::Row(ref mut o) = new_obj {
let mut current = o;
if split_path.len() == 1 {
@ -423,7 +423,7 @@ impl Value {
Some(next) => {
if idx == (split_path.len() - 2) {
match &mut next.item {
Value::Object(o) => {
Value::Row(o) => {
o.entries.insert(
split_path[idx + 1].to_string(),
Tagged::from_item(new_value, tag),
@ -435,7 +435,7 @@ impl Value {
return Some(Tagged::from_item(new_obj, tag));
} else {
match next.item {
Value::Object(ref mut o) => {
Value::Row(ref mut o) => {
current = o;
}
_ => return None,
@ -460,7 +460,7 @@ impl Value {
let split_path: Vec<_> = path.split(".").collect();
if let Value::Object(ref mut o) = new_obj {
if let Value::Row(ref mut o) = new_obj {
let mut current = o;
for idx in 0..split_path.len() {
match current.entries.get_mut(split_path[idx]) {
@ -470,7 +470,7 @@ impl Value {
return Some(Tagged::from_item(new_obj, tag));
} else {
match next.item {
Value::Object(ref mut o) => {
Value::Row(ref mut o) => {
current = o;
}
_ => return None,
@ -488,9 +488,9 @@ impl Value {
pub fn get_data(&self, desc: &String) -> MaybeOwned<'_, Value> {
match self {
p @ Value::Primitive(_) => MaybeOwned::Borrowed(p),
Value::Object(o) => o.get_data(desc),
Value::Row(o) => o.get_data(desc),
Value::Block(_) => MaybeOwned::Owned(Value::nothing()),
Value::List(_) => MaybeOwned::Owned(Value::nothing()),
Value::Table(_) => MaybeOwned::Owned(Value::nothing()),
Value::Binary(_) => MaybeOwned::Owned(Value::nothing()),
}
}
@ -504,8 +504,8 @@ impl Value {
.map(|e| e.source(&b.source).to_string()),
"; ",
),
Value::Object(_) => format!("[table: 1 row]"),
Value::List(l) => format!(
Value::Row(_) => format!("[table: 1 row]"),
Value::Table(l) => format!(
"[table: {} {}]",
l.len(),
if l.len() == 1 { "row" } else { "rows" }

View File

@ -1,5 +1,5 @@
use crate::commands::command::Command;
use crate::object::{TaggedDictBuilder, TaggedListBuilder, Value};
use crate::data::{TaggedDictBuilder, TaggedListBuilder, Value};
use crate::parser::registry::{NamedType, PositionalType, Signature};
use crate::prelude::*;
use std::ops::Deref;
@ -32,7 +32,10 @@ fn for_spec(name: &str, ty: &str, required: bool, tag: impl Into<Tag>) -> Tagged
spec.insert("name", Value::string(name));
spec.insert("type", Value::string(ty));
spec.insert("required", Value::string(if required { "yes" } else { "no" }));
spec.insert(
"required",
Value::string(if required { "yes" } else { "no" }),
);
spec.into_tagged_value()
}
@ -43,8 +46,8 @@ fn signature_dict(signature: Signature, tag: impl Into<Tag>) -> Tagged<Value> {
for arg in signature.positional.iter() {
let is_required = match arg {
PositionalType::Mandatory(_,_) => true,
PositionalType::Optional(_,_) => false,
PositionalType::Mandatory(_, _) => true,
PositionalType::Optional(_, _) => false,
};
sig.insert_tagged(for_spec(arg.name(), "argument", is_required, tag));

View File

@ -1,7 +1,7 @@
use crate::commands::from_toml::convert_toml_value_to_nu_value;
use crate::commands::to_toml::value_to_toml_value;
use crate::data::{Dictionary, Value};
use crate::errors::ShellError;
use crate::object::{Dictionary, Value};
use crate::prelude::*;
use app_dirs::*;
use indexmap::IndexMap;
@ -37,7 +37,7 @@ pub(crate) fn write_config(config: &IndexMap<String, Tagged<Value>>) -> Result<(
touch(&filename)?;
let contents =
value_to_toml_value(&Value::Object(Dictionary::new(config.clone())).tagged_unknown())?;
value_to_toml_value(&Value::Row(Dictionary::new(config.clone())).tagged_unknown())?;
let contents = toml::to_string(&contents)?;
@ -67,7 +67,7 @@ pub(crate) fn config(span: impl Into<Span>) -> Result<IndexMap<String, Tagged<Va
let value = convert_toml_value_to_nu_value(&parsed, Tag::unknown_origin(span));
let tag = value.tag();
match value.item {
Value::Object(Dictionary { entries }) => Ok(entries),
Value::Row(Dictionary { entries }) => Ok(entries),
other => Err(ShellError::type_error(
"Dictionary",
other.type_name().tagged(tag),

View File

@ -1,5 +1,5 @@
use crate::data::{Primitive, Value};
use crate::prelude::*;
use crate::object::{Primitive, Value};
use derive_new::new;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
@ -64,7 +64,7 @@ impl PartialOrd<Value> for Dictionary {
impl PartialEq<Value> for Dictionary {
fn eq(&self, other: &Value) -> bool {
match other {
Value::Object(d) => self == d,
Value::Row(d) => self == d,
_ => false,
}
}
@ -123,7 +123,7 @@ impl TaggedListBuilder {
}
pub fn into_tagged_value(self) -> Tagged<Value> {
Value::List(self.list).tagged(self.tag)
Value::Table(self.list).tagged(self.tag)
}
}
@ -163,7 +163,7 @@ impl TaggedDictBuilder {
}
pub fn into_tagged_value(self) -> Tagged<Value> {
self.into_tagged_dict().map(Value::Object)
self.into_tagged_dict().map(Value::Row)
}
pub fn into_tagged_dict(self) -> Tagged<Dictionary> {

View File

@ -1,5 +1,5 @@
use crate::data::{TaggedDictBuilder, Value};
use crate::errors::ShellError;
use crate::object::{TaggedDictBuilder, Value};
use crate::prelude::*;
#[derive(Debug)]

View File

@ -1,4 +1,4 @@
use crate::object::{Primitive, Value};
use crate::data::{Primitive, Value};
use crate::prelude::*;
impl From<Primitive> for Value {

View File

@ -1,4 +1,4 @@
use crate::object::{TaggedDictBuilder, Value};
use crate::data::{TaggedDictBuilder, Value};
use crate::prelude::*;
use itertools::join;
use sysinfo::ProcessExt;

View File

@ -1,5 +1,5 @@
use crate::data::base::Block;
use crate::errors::Description;
use crate::object::base::Block;
use crate::parser::{
hir::{self, Expression, RawExpression},
CommandRegistry, Text,
@ -66,7 +66,7 @@ pub(crate) fn evaluate_baseline_expr(
exprs.push(expr);
}
Ok(Value::List(exprs).tagged(Tag::unknown_origin(expr.span())))
Ok(Value::Table(exprs).tagged(Tag::unknown_origin(expr.span())))
}
RawExpression::Block(block) => Ok(Tagged::from_simple_spanned_item(
Value::Block(Block::new(block.clone(), source.clone(), expr.span())),

View File

@ -1,5 +1,5 @@
use crate::data::Value;
use crate::format::{EntriesView, RenderView, TableView};
use crate::object::Value;
use crate::prelude::*;
use derive_new::new;
@ -13,7 +13,7 @@ impl RenderView for GenericView<'_> {
fn render_view(&self, host: &mut dyn Host) -> Result<(), ShellError> {
match self.value {
Value::Primitive(p) => Ok(host.stdout(&p.format(None))),
Value::List(l) => {
Value::Table(l) => {
let view = TableView::from_list(l);
if let Some(view) = view {
@ -23,7 +23,7 @@ impl RenderView for GenericView<'_> {
Ok(())
}
o @ Value::Object(_) => {
o @ Value::Row(_) => {
let view = EntriesView::from_value(o);
view.render_view(host)?;
Ok(())

View File

@ -1,5 +1,5 @@
use crate::data::Value;
use crate::format::RenderView;
use crate::object::Value;
use crate::prelude::*;
use derive_new::new;
use textwrap::fill;
@ -45,7 +45,7 @@ impl TableView {
for (idx, value) in values.iter().enumerate() {
let mut row: Vec<(String, &'static str)> = match value {
Tagged {
item: Value::Object(..),
item: Value::Row(..),
..
} => headers
.iter()

View File

@ -1,5 +1,5 @@
use crate::data::Value;
use crate::format::RenderView;
use crate::object::Value;
use crate::prelude::*;
use derive_new::new;

View File

@ -7,12 +7,12 @@ mod prelude;
mod cli;
mod commands;
mod context;
mod data;
mod env;
mod errors;
mod evaluate;
mod format;
mod git;
mod object;
mod parser;
mod plugin;
mod shell;
@ -28,10 +28,10 @@ pub use crate::parser::parse::token_tree_builder::TokenTreeBuilder;
pub use crate::plugin::{serve_plugin, Plugin};
pub use crate::utils::{AbsoluteFile, AbsolutePath, RelativePath};
pub use cli::cli;
pub use data::base::{Primitive, Value};
pub use data::dict::{Dictionary, TaggedDictBuilder};
pub use data::meta::{Span, Tag, Tagged, TaggedItem};
pub use errors::{CoerceInto, ShellError};
pub use num_traits::cast::ToPrimitive;
pub use object::base::{Primitive, Value};
pub use object::dict::{Dictionary, TaggedDictBuilder};
pub use object::meta::{Span, Tag, Tagged, TaggedItem};
pub use parser::parse::text::Text;
pub use parser::registry::{EvaluatedArgs, NamedType, PositionalType, Signature};

View File

@ -37,7 +37,7 @@ impl<'de> ConfigDeserializer<'de> {
let value: Option<Tagged<Value>> = if name == "rest" {
let positional = self.call.args.slice_from(self.position);
self.position += positional.len();
Some(Value::List(positional).tagged_unknown()) // TODO: correct span
Some(Value::Table(positional).tagged_unknown()) // TODO: correct span
} else {
if self.call.args.has(name) {
self.call.args.get(name).map(|x| x.clone())
@ -240,14 +240,11 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
trace!("<Vec> Extracting {:?} for vec", value.val);
match value.val.into_parts() {
(Value::List(items), _) => {
(Value::Table(items), _) => {
let de = SeqDeserializer::new(&mut self, items.into_iter());
visitor.visit_seq(de)
}
(other, tag) => Err(ShellError::type_error(
"Vec",
other.type_name().tagged(tag),
)),
(other, tag) => Err(ShellError::type_error("Vec", other.type_name().tagged(tag))),
}
}
fn deserialize_tuple<V>(mut self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
@ -255,10 +252,14 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
V: Visitor<'de>,
{
let value = self.pop();
trace!("<Tuple> Extracting {:?} for tuple with {} elements", value.val, len);
trace!(
"<Tuple> Extracting {:?} for tuple with {} elements",
value.val,
len
);
match value.val.into_parts() {
(Value::List(items), _) => {
(Value::Table(items), _) => {
let de = SeqDeserializer::new(&mut self, items.into_iter());
visitor.visit_seq(de)
}
@ -298,7 +299,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
val: T,
name: &'static str,
fields: &'static [&'static str],
visitor: V
visitor: V,
) -> Result<V::Value, ShellError>
where
T: serde::Serialize,
@ -364,7 +365,7 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
} => {
let i: i64 = int.tagged(value.val.tag).coerce_into("converting to i64")?;
visit::<Tagged<i64>, _>(i.tagged(tag), name, fields, visitor)
},
}
Tagged {
item: Value::Primitive(Primitive::String(string)),
..
@ -398,21 +399,20 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut ConfigDeserializer<'de> {
}
}
struct SeqDeserializer<'a, 'de: 'a, I: Iterator<Item=Tagged<Value>>> {
struct SeqDeserializer<'a, 'de: 'a, I: Iterator<Item = Tagged<Value>>> {
de: &'a mut ConfigDeserializer<'de>,
vals: I,
}
impl<'a, 'de: 'a, I: Iterator<Item=Tagged<Value>>> SeqDeserializer<'a, 'de, I> {
impl<'a, 'de: 'a, I: Iterator<Item = Tagged<Value>>> SeqDeserializer<'a, 'de, I> {
fn new(de: &'a mut ConfigDeserializer<'de>, vals: I) -> Self {
SeqDeserializer {
de,
vals,
}
SeqDeserializer { de, vals }
}
}
impl<'a, 'de: 'a, I: Iterator<Item=Tagged<Value>>> de::SeqAccess<'de> for SeqDeserializer<'a, 'de, I> {
impl<'a, 'de: 'a, I: Iterator<Item = Tagged<Value>>> de::SeqAccess<'de>
for SeqDeserializer<'a, 'de, I>
{
type Error = ShellError;
fn next_element_seed<T>(&mut self, seed: T) -> Result<Option<T::Value>, Self::Error>
@ -441,10 +441,7 @@ struct StructDeserializer<'a, 'de: 'a> {
impl<'a, 'de: 'a> StructDeserializer<'a, 'de> {
fn new(de: &'a mut ConfigDeserializer<'de>, fields: &'static [&'static str]) -> Self {
StructDeserializer {
de,
fields,
}
StructDeserializer { de, fields }
}
}

View File

@ -1,4 +1,4 @@
use crate::object::base::Value;
use crate::data::base::Value;
use crate::prelude::*;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

View File

@ -18,7 +18,7 @@ impl Add {
fn add(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
let value_tag = value.tag();
match (value.item, self.value.clone()) {
(obj @ Value::Object(_), Some(v)) => match &self.field {
(obj @ Value::Row(_), Some(v)) => match &self.field {
Some(f) => match obj.insert_data_at_path(value_tag, &f, v) {
Some(v) => return Ok(v),
None => {

View File

@ -18,7 +18,7 @@ impl Edit {
fn edit(&self, value: Tagged<Value>) -> Result<Tagged<Value>, ShellError> {
let value_tag = value.tag();
match (value.item, self.value.clone()) {
(obj @ Value::Object(_), Some(v)) => match &self.field {
(obj @ Value::Row(_), Some(v)) => match &self.field {
Some(f) => match obj.replace_data_at_path(value_tag, &f, v) {
Some(v) => return Ok(v),
None => {

View File

@ -74,7 +74,7 @@ impl Plugin for Embed {
root.insert_tagged(
self.field.as_ref().unwrap(),
Tagged {
item: Value::List(self.values.clone()),
item: Value::Table(self.values.clone()),
tag: Tag::unknown(),
},
);

View File

@ -83,7 +83,7 @@ impl Inc {
Value::Primitive(Primitive::String(ref s)) => {
Ok(Tagged::from_item(self.apply(&s)?, value.tag()))
}
Value::Object(_) => match self.field {
Value::Row(_) => match self.field {
Some(ref f) => {
let replacement = match value.item.get_data_by_path(value.tag(), f) {
Some(result) => self.inc(result.map(|x| x.clone()))?,
@ -333,7 +333,7 @@ mod tests {
match output[0].as_ref().unwrap() {
ReturnSuccess::Value(Tagged {
item: Value::Object(o),
item: Value::Row(o),
..
}) => assert_eq!(
*o.get_data(&String::from("version")).borrow(),
@ -361,7 +361,7 @@ mod tests {
match output[0].as_ref().unwrap() {
ReturnSuccess::Value(Tagged {
item: Value::Object(o),
item: Value::Row(o),
..
}) => assert_eq!(
*o.get_data(&String::from("version")).borrow(),
@ -390,7 +390,7 @@ mod tests {
match output[0].as_ref().unwrap() {
ReturnSuccess::Value(Tagged {
item: Value::Object(o),
item: Value::Row(o),
..
}) => assert_eq!(
*o.get_data(&field).borrow(),

View File

@ -135,7 +135,7 @@ impl Str {
Value::Primitive(Primitive::String(ref s)) => {
Ok(Tagged::from_item(self.apply(&s)?, value.tag()))
}
Value::Object(_) => match self.field {
Value::Row(_) => match self.field {
Some(ref f) => {
let replacement = match value.item.get_data_by_path(value.tag(), f) {
Some(result) => self.strutils(result.map(|x| x.clone()))?,
@ -479,7 +479,7 @@ mod tests {
match output[0].as_ref().unwrap() {
ReturnSuccess::Value(Tagged {
item: Value::Object(o),
item: Value::Row(o),
..
}) => assert_eq!(
*o.get_data(&String::from("name")).borrow(),
@ -527,7 +527,7 @@ mod tests {
match output[0].as_ref().unwrap() {
ReturnSuccess::Value(Tagged {
item: Value::Object(o),
item: Value::Row(o),
..
}) => assert_eq!(
*o.get_data(&String::from("name")).borrow(),
@ -575,7 +575,7 @@ mod tests {
match output[0].as_ref().unwrap() {
ReturnSuccess::Value(Tagged {
item: Value::Object(o),
item: Value::Row(o),
..
}) => assert_eq!(
*o.get_data(&String::from("Nu_birthday")).borrow(),
@ -624,7 +624,7 @@ mod tests {
match output[0].as_ref().unwrap() {
ReturnSuccess::Value(Tagged {
item: Value::Object(o),
item: Value::Row(o),
..
}) => assert_eq!(
*o.get_data(&String::from("rustconf")).borrow(),
@ -679,7 +679,7 @@ mod tests {
match output[0].as_ref().unwrap() {
ReturnSuccess::Value(Tagged {
item: Value::Object(o),
item: Value::Row(o),
..
}) => assert_eq!(
*o.get_data(&String::from("staff")).borrow(),

View File

@ -119,7 +119,7 @@ async fn host(tag: Tag) -> Tagged<Value> {
user_vec.push(Tagged::from_item(Value::string(user.username()), tag));
}
}
let user_list = Value::List(user_vec);
let user_list = Value::Table(user_vec);
dict.insert("users", user_list);
dict.into_tagged_value()
@ -163,7 +163,7 @@ async fn disks(tag: Tag) -> Option<Value> {
}
if !output.is_empty() {
Some(Value::List(output))
Some(Value::Table(output))
} else {
None
}
@ -205,7 +205,7 @@ async fn battery(tag: Tag) -> Option<Value> {
}
if !output.is_empty() {
Some(Value::List(output))
Some(Value::Table(output))
} else {
None
}
@ -248,7 +248,7 @@ async fn temp(tag: Tag) -> Option<Value> {
}
if !output.is_empty() {
Some(Value::List(output))
Some(Value::Table(output))
} else {
None
}
@ -273,7 +273,7 @@ async fn net(tag: Tag) -> Option<Value> {
}
}
if !output.is_empty() {
Some(Value::List(output))
Some(Value::Table(output))
} else {
None
}

View File

@ -17,14 +17,14 @@ impl TreeView {
Value::Primitive(p) => {
let _ = builder.add_empty_child(p.format(None));
}
Value::Object(o) => {
Value::Row(o) => {
for (k, v) in o.entries.iter() {
builder = builder.begin_child(k.clone());
Self::from_value_helper(v, builder);
builder = builder.end_child();
}
}
Value::List(l) => {
Value::Table(l) => {
for elem in l.iter() {
Self::from_value_helper(elem, builder);
}

View File

@ -55,20 +55,20 @@ pub(crate) use crate::commands::PerItemCommand;
pub(crate) use crate::commands::RawCommandArgs;
pub(crate) use crate::context::CommandRegistry;
pub(crate) use crate::context::{Context, SpanSource};
pub(crate) use crate::data::base as value;
pub(crate) use crate::data::meta::{Tag, Tagged, TaggedItem};
pub(crate) use crate::data::types::ExtractType;
pub(crate) use crate::data::{Primitive, Value};
pub(crate) use crate::env::host::handle_unexpected;
pub(crate) use crate::env::Host;
pub(crate) use crate::errors::{CoerceInto, ShellError};
pub(crate) use crate::object::base as value;
pub(crate) use crate::object::meta::{Tag, Tagged, TaggedItem};
pub(crate) use crate::object::types::ExtractType;
pub(crate) use crate::object::{Primitive, Value};
pub(crate) use crate::parser::hir::SyntaxType;
pub(crate) use crate::parser::parse::parser::Number;
pub(crate) use crate::parser::registry::Signature;
pub(crate) use crate::shell::filesystem_shell::FilesystemShell;
pub(crate) use crate::shell::help_shell::HelpShell;
pub(crate) use crate::shell::shell_manager::ShellManager;
pub(crate) use crate::shell::value_shell::ValueShell;
pub(crate) use crate::shell::help_shell::HelpShell;
pub(crate) use crate::stream::{InputStream, OutputStream};
pub(crate) use crate::traits::{HasSpan, ToDebug};
pub(crate) use crate::Span;

View File

@ -4,7 +4,7 @@ use crate::commands::mkdir::MkdirArgs;
use crate::commands::mv::MoveArgs;
use crate::commands::rm::RemoveArgs;
use crate::context::SourceMap;
use crate::object::dir_entry_dict;
use crate::data::dir_entry_dict;
use crate::prelude::*;
use crate::shell::completer::NuCompleter;
use crate::shell::shell::Shell;

View File

@ -4,7 +4,7 @@ use crate::commands::mkdir::MkdirArgs;
use crate::commands::mv::MoveArgs;
use crate::commands::rm::RemoveArgs;
use crate::context::SourceMap;
use crate::object::{TaggedDictBuilder, command_dict};
use crate::data::{command_dict, TaggedDictBuilder};
use crate::prelude::*;
use crate::shell::shell::Shell;
use std::ffi::OsStr;
@ -26,13 +26,16 @@ impl HelpShell {
let value = command_dict(registry.get_command(&cmd).unwrap(), Tag::unknown());
spec.insert("name", cmd);
spec.insert("description", value.get_data_by_key("usage").unwrap().as_string().unwrap());
spec.insert(
"description",
value.get_data_by_key("usage").unwrap().as_string().unwrap(),
);
spec.insert_tagged("details", value);
specs.push(spec.into_tagged_value());
}
cmds.insert("help", Value::List(specs));
cmds.insert("help", Value::Table(specs));
Ok(HelpShell {
path: "/help".to_string(),
@ -47,8 +50,10 @@ impl HelpShell {
let mut sh = HelpShell::index(&registry)?;
if let Tagged {
item: Value::Primitive(Primitive::String(name)), ..
} = cmd {
item: Value::Primitive(Primitive::String(name)),
..
} = cmd
{
sh.set_path(format!("/help/{:}/details", name));
}
@ -76,7 +81,7 @@ impl HelpShell {
}
match viewed {
Tagged {
item: Value::List(l),
item: Value::Table(l),
..
} => {
for item in l {

View File

@ -43,7 +43,7 @@ impl ValueShell {
}
match viewed {
Tagged {
item: Value::List(l),
item: Value::Table(l),
..
} => {
for item in l {
@ -55,7 +55,7 @@ impl ValueShell {
}
}
shell_entries
shell_entries
}
fn members(&self) -> VecDeque<Tagged<Value>> {

View File

@ -1,6 +1,6 @@
use crate::data::meta::Tagged;
use crate::data::Value;
use crate::errors::ShellError;
use crate::object::meta::Tagged;
use crate::object::Value;
use std::fmt;
use std::ops::Div;
use std::path::{Component, Path, PathBuf};
@ -150,14 +150,14 @@ impl<'a> Iterator for TaggedValueIter<'a> {
impl Tagged<Value> {
fn is_dir(&self) -> bool {
match self.item() {
Value::Object(_) | Value::List(_) => true,
Value::Row(_) | Value::Table(_) => true,
_ => false,
}
}
fn entries(&self) -> TaggedValueIter<'_> {
match self.item() {
Value::Object(o) => {
Value::Row(o) => {
let iter = o.entries.iter();
TaggedValueIter::List(iter)
}
@ -321,8 +321,8 @@ impl FileStructure {
#[cfg(test)]
mod tests {
use super::{FileStructure, Res, ValueResource, ValueStructure};
use crate::object::meta::{Tag, Tagged};
use crate::object::{TaggedDictBuilder, Value};
use crate::data::meta::{Tag, Tagged};
use crate::data::{TaggedDictBuilder, Value};
use pretty_assertions::assert_eq;
use std::path::PathBuf;