Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub mod column_path;
|
|
|
|
mod convert;
|
|
|
|
mod debug;
|
|
|
|
pub mod dict;
|
|
|
|
pub mod evaluate;
|
|
|
|
pub mod primitive;
|
2019-12-04 22:14:52 +01:00
|
|
|
pub mod range;
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
mod serde_bigdecimal;
|
|
|
|
mod serde_bigint;
|
|
|
|
|
|
|
|
use crate::type_name::{ShellTypeName, SpannedTypeName};
|
|
|
|
use crate::value::dict::Dictionary;
|
|
|
|
use crate::value::evaluate::Evaluate;
|
|
|
|
use crate::value::primitive::Primitive;
|
2019-12-04 22:14:52 +01:00
|
|
|
use crate::value::range::{Range, RangeInclusion};
|
2019-12-04 20:52:31 +01:00
|
|
|
use crate::{ColumnPath, PathMember};
|
|
|
|
use bigdecimal::BigDecimal;
|
|
|
|
use indexmap::IndexMap;
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
use nu_errors::ShellError;
|
2019-12-04 22:14:52 +01:00
|
|
|
use nu_source::{AnchorLocation, HasSpan, Span, Spanned, Tag};
|
2019-12-04 20:52:31 +01:00
|
|
|
use num_bigint::BigInt;
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::path::PathBuf;
|
2019-12-04 20:52:31 +01:00
|
|
|
use std::time::SystemTime;
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// The core structured values that flow through a pipeline
|
2019-12-31 05:05:02 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)]
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub enum UntaggedValue {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// A primitive (or fundamental) type of values
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
Primitive(Primitive),
|
2020-01-18 20:42:36 +01:00
|
|
|
/// A table row
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
Row(Dictionary),
|
2020-01-18 20:42:36 +01:00
|
|
|
/// A full inner (or embedded) table
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
Table(Vec<Value>),
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// An error value that represents an error that occurred as the values in the pipeline were built
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
Error(ShellError),
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// A block of Nu code, eg `{ ls | get name }`
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
Block(Evaluate),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UntaggedValue {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Tags an UntaggedValue so that it can become a Value
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn retag(self, tag: impl Into<Tag>) -> Value {
|
|
|
|
Value {
|
|
|
|
value: self,
|
|
|
|
tag: tag.into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Get the corresponding descriptors (column names) associated with this value
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn data_descriptors(&self) -> Vec<String> {
|
|
|
|
match self {
|
|
|
|
UntaggedValue::Primitive(_) => vec![],
|
2019-12-31 08:36:08 +01:00
|
|
|
UntaggedValue::Row(columns) => columns.entries.keys().map(|x| x.to_string()).collect(),
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
UntaggedValue::Block(_) => vec![],
|
|
|
|
UntaggedValue::Table(_) => vec![],
|
|
|
|
UntaggedValue::Error(_) => vec![],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Convert this UntaggedValue to a Value with the given Tag
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn into_value(self, tag: impl Into<Tag>) -> Value {
|
|
|
|
Value {
|
|
|
|
value: self,
|
|
|
|
tag: tag.into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Convert this UntaggedValue into a Value with an empty Tag
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn into_untagged_value(self) -> Value {
|
|
|
|
Value {
|
|
|
|
value: self,
|
|
|
|
tag: Tag::unknown(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Returns true if this value represents boolean true
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn is_true(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
UntaggedValue::Primitive(Primitive::Boolean(true)) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Returns true if the value represents something other than Nothing
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn is_some(&self) -> bool {
|
|
|
|
!self.is_none()
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Returns true if the value represents Nothing
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn is_none(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
UntaggedValue::Primitive(Primitive::Nothing) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Returns true if the value represents an error
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn is_error(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
UntaggedValue::Error(_err) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Expect this value to be an error and return it
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn expect_error(&self) -> ShellError {
|
|
|
|
match self {
|
|
|
|
UntaggedValue::Error(err) => err.clone(),
|
|
|
|
_ => panic!("Don't call expect_error without first calling is_error"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Expect this value to be a string and return it
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn expect_string(&self) -> &str {
|
|
|
|
match self {
|
|
|
|
UntaggedValue::Primitive(Primitive::String(string)) => &string[..],
|
|
|
|
_ => panic!("expect_string assumes that the value must be a string"),
|
|
|
|
}
|
|
|
|
}
|
2019-12-04 20:52:31 +01:00
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating row values
|
2019-12-04 20:52:31 +01:00
|
|
|
#[allow(unused)]
|
|
|
|
pub fn row(entries: IndexMap<String, Value>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Row(entries.into())
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating table values
|
2019-12-31 08:36:08 +01:00
|
|
|
pub fn table(list: &[Value]) -> UntaggedValue {
|
2019-12-04 20:52:31 +01:00
|
|
|
UntaggedValue::Table(list.to_vec())
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating string values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn string(s: impl Into<String>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::String(s.into()))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating line values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn line(s: impl Into<String>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Line(s.into()))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating column-path values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn column_path(s: Vec<impl Into<PathMember>>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::ColumnPath(ColumnPath::new(
|
|
|
|
s.into_iter().map(|p| p.into()).collect(),
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating integer values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn int(i: impl Into<BigInt>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Int(i.into()))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating glob pattern values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn pattern(s: impl Into<String>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::String(s.into()))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating filepath values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn path(s: impl Into<PathBuf>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Path(s.into()))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating bytesize values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn bytes(s: impl Into<u64>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Bytes(s.into()))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating decimal values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn decimal(s: impl Into<BigDecimal>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Decimal(s.into()))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating binary (non-text) buffer values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn binary(binary: Vec<u8>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Binary(binary))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating range values
|
2019-12-04 22:14:52 +01:00
|
|
|
pub fn range(
|
|
|
|
left: (Spanned<Primitive>, RangeInclusion),
|
|
|
|
right: (Spanned<Primitive>, RangeInclusion),
|
|
|
|
) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Range(Box::new(Range::new(left, right))))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating boolean values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn boolean(s: impl Into<bool>) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Boolean(s.into()))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating date duration values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn duration(secs: u64) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Duration(secs))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating datatime values
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn system_date(s: SystemTime) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Date(s.into()))
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Helper for creating the Nothing value
|
2019-12-04 20:52:31 +01:00
|
|
|
pub fn nothing() -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::Nothing)
|
|
|
|
}
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// The fundamental structured value that flows through the pipeline, with associated metadata
|
2019-12-31 05:05:02 +01:00
|
|
|
#[derive(Debug, Clone, PartialOrd, PartialEq, Ord, Eq, Hash, Serialize, Deserialize)]
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub struct Value {
|
|
|
|
pub value: UntaggedValue,
|
|
|
|
pub tag: Tag,
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Overload deferencing to give back the UntaggedValue inside of a Value
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
impl std::ops::Deref for Value {
|
|
|
|
type Target = UntaggedValue;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Value {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Get the corresponding anchor (originating location) for the Value
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn anchor(&self) -> Option<AnchorLocation> {
|
|
|
|
self.tag.anchor()
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Get the name (url, filepath, etc) behind an anchor for the Value
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn anchor_name(&self) -> Option<String> {
|
|
|
|
self.tag.anchor_name()
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Get the metadata for the Value
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn tag(&self) -> Tag {
|
|
|
|
self.tag.clone()
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// View the Value as a string, if possible
|
2019-12-03 07:44:59 +01:00
|
|
|
pub fn as_string(&self) -> Result<String, ShellError> {
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
match &self.value {
|
2019-12-03 07:44:59 +01:00
|
|
|
UntaggedValue::Primitive(Primitive::String(string)) => Ok(string.clone()),
|
|
|
|
UntaggedValue::Primitive(Primitive::Line(line)) => Ok(line.clone() + "\n"),
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
_ => Err(ShellError::type_error("string", self.spanned_type_name())),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// View into the borrowed string contents of a Value, if possible
|
2019-12-02 17:14:05 +01:00
|
|
|
pub fn as_forgiving_string(&self) -> Result<&str, ShellError> {
|
|
|
|
match &self.value {
|
|
|
|
UntaggedValue::Primitive(Primitive::String(string)) => Ok(&string[..]),
|
|
|
|
_ => Err(ShellError::type_error("string", self.spanned_type_name())),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// View the Value as a path, if possible
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
pub fn as_path(&self) -> Result<PathBuf, ShellError> {
|
|
|
|
match &self.value {
|
|
|
|
UntaggedValue::Primitive(Primitive::Path(path)) => Ok(path.clone()),
|
2019-12-31 08:36:08 +01:00
|
|
|
UntaggedValue::Primitive(Primitive::String(path_str)) => Ok(PathBuf::from(&path_str)),
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
_ => Err(ShellError::type_error("Path", self.spanned_type_name())),
|
|
|
|
}
|
|
|
|
}
|
2019-12-04 22:14:52 +01:00
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// View the Value as a Primitive value, if possible
|
2019-12-04 22:14:52 +01:00
|
|
|
pub fn as_primitive(&self) -> Result<Primitive, ShellError> {
|
|
|
|
match &self.value {
|
|
|
|
UntaggedValue::Primitive(primitive) => Ok(primitive.clone()),
|
|
|
|
_ => Err(ShellError::type_error(
|
|
|
|
"Primitive",
|
|
|
|
self.spanned_type_name(),
|
|
|
|
)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// View the Value as unsigned 64-bit, if possible
|
2019-12-04 22:14:52 +01:00
|
|
|
pub fn as_u64(&self) -> Result<u64, ShellError> {
|
|
|
|
match &self.value {
|
|
|
|
UntaggedValue::Primitive(primitive) => primitive.as_u64(self.tag.span),
|
|
|
|
_ => Err(ShellError::type_error("integer", self.spanned_type_name())),
|
|
|
|
}
|
|
|
|
}
|
2020-01-17 23:46:18 +01:00
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// View the Value as boolean, if possible
|
2020-01-17 23:46:18 +01:00
|
|
|
pub fn as_bool(&self) -> Result<bool, ShellError> {
|
|
|
|
match &self.value {
|
|
|
|
UntaggedValue::Primitive(Primitive::Boolean(p)) => Ok(*p),
|
|
|
|
_ => Err(ShellError::type_error("boolean", self.spanned_type_name())),
|
|
|
|
}
|
|
|
|
}
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<UntaggedValue> for &str {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Convert a string slice into an UntaggedValue
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
fn into(self) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::String(self.to_string()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<UntaggedValue> for Value {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Convert a Value into an UntaggedValue
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
fn into(self) -> UntaggedValue {
|
|
|
|
self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Convert a borrowed Value into a borrowed UntaggedValue
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
impl<'a> Into<&'a UntaggedValue> for &'a Value {
|
|
|
|
fn into(self) -> &'a UntaggedValue {
|
|
|
|
&self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasSpan for Value {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Return the corresponding Span for the Value
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
fn span(&self) -> Span {
|
|
|
|
self.tag.span
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ShellTypeName for Value {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Get the type name for the Value
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
fn type_name(&self) -> &'static str {
|
|
|
|
ShellTypeName::type_name(&self.value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ShellTypeName for UntaggedValue {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Get the type name for the UntaggedValue
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
fn type_name(&self) -> &'static str {
|
|
|
|
match &self {
|
|
|
|
UntaggedValue::Primitive(p) => p.type_name(),
|
|
|
|
UntaggedValue::Row(_) => "row",
|
|
|
|
UntaggedValue::Table(_) => "table",
|
|
|
|
UntaggedValue::Error(_) => "error",
|
|
|
|
UntaggedValue::Block(_) => "block",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Primitive> for UntaggedValue {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Convert a Primitive to an UntaggedValue
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
fn from(input: Primitive) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(input)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for UntaggedValue {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Convert a String to an UntaggedValue
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
fn from(input: String) -> UntaggedValue {
|
|
|
|
UntaggedValue::Primitive(Primitive::String(input))
|
|
|
|
}
|
|
|
|
}
|