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 crate::type_name::ShellTypeName;
|
|
|
|
use crate::value::column_path::ColumnPath;
|
|
|
|
use crate::value::{serde_bigdecimal, serde_bigint};
|
|
|
|
use bigdecimal::BigDecimal;
|
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
use num_bigint::BigInt;
|
|
|
|
use num_traits::cast::FromPrimitive;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Deserialize, Serialize)]
|
|
|
|
pub enum Primitive {
|
|
|
|
Nothing,
|
|
|
|
#[serde(with = "serde_bigint")]
|
|
|
|
Int(BigInt),
|
|
|
|
#[serde(with = "serde_bigdecimal")]
|
|
|
|
Decimal(BigDecimal),
|
|
|
|
Bytes(u64),
|
|
|
|
String(String),
|
2019-12-03 07:44:59 +01:00
|
|
|
Line(String),
|
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
|
|
|
ColumnPath(ColumnPath),
|
|
|
|
Pattern(String),
|
|
|
|
Boolean(bool),
|
|
|
|
Date(DateTime<Utc>),
|
|
|
|
Duration(u64), // Duration in seconds
|
|
|
|
Path(PathBuf),
|
|
|
|
#[serde(with = "serde_bytes")]
|
|
|
|
Binary(Vec<u8>),
|
|
|
|
|
|
|
|
// Stream markers (used as bookend markers rather than actual values)
|
|
|
|
BeginningOfStream,
|
|
|
|
EndOfStream,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<BigDecimal> for Primitive {
|
|
|
|
fn from(decimal: BigDecimal) -> Primitive {
|
|
|
|
Primitive::Decimal(decimal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<f64> for Primitive {
|
|
|
|
fn from(float: f64) -> Primitive {
|
|
|
|
Primitive::Decimal(BigDecimal::from_f64(float).unwrap())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ShellTypeName for Primitive {
|
|
|
|
fn type_name(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
Primitive::Nothing => "nothing",
|
|
|
|
Primitive::Int(_) => "integer",
|
|
|
|
Primitive::Decimal(_) => "decimal",
|
|
|
|
Primitive::Bytes(_) => "bytes",
|
|
|
|
Primitive::String(_) => "string",
|
2019-12-03 07:44:59 +01:00
|
|
|
Primitive::Line(_) => "line",
|
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::ColumnPath(_) => "column path",
|
|
|
|
Primitive::Pattern(_) => "pattern",
|
|
|
|
Primitive::Boolean(_) => "boolean",
|
|
|
|
Primitive::Date(_) => "date",
|
|
|
|
Primitive::Duration(_) => "duration",
|
|
|
|
Primitive::Path(_) => "file path",
|
|
|
|
Primitive::Binary(_) => "binary",
|
|
|
|
Primitive::BeginningOfStream => "marker<beginning of stream>",
|
|
|
|
Primitive::EndOfStream => "marker<end of stream>",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|