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_source::{DebugDocBuilder, HasSpan, Spanned, SpannedItem, Tagged};
|
2019-11-04 16:47:03 +01:00
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// A trait that allows structures to define a known .type_name() which pretty-prints the type
|
2019-11-04 16:47:03 +01:00
|
|
|
pub trait ShellTypeName {
|
|
|
|
fn type_name(&self) -> &'static str;
|
|
|
|
}
|
|
|
|
|
2019-11-21 15:33:14 +01:00
|
|
|
impl<T: ShellTypeName> ShellTypeName for Spanned<T> {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Return the type_name of the spanned item
|
2019-11-21 15:33:14 +01:00
|
|
|
fn type_name(&self) -> &'static str {
|
|
|
|
self.item.type_name()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-04 16:47:03 +01:00
|
|
|
impl<T: ShellTypeName> ShellTypeName for &T {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Return the type_name for the borrowed reference
|
2019-11-04 16:47:03 +01:00
|
|
|
fn type_name(&self) -> &'static str {
|
|
|
|
(*self).type_name()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// A trait that allows structures to define a known way to return a spanned type name
|
2019-11-04 16:47:03 +01:00
|
|
|
pub trait SpannedTypeName {
|
|
|
|
fn spanned_type_name(&self) -> Spanned<&'static str>;
|
|
|
|
}
|
|
|
|
|
2019-11-21 15:33:14 +01:00
|
|
|
impl<T: ShellTypeName + HasSpan> SpannedTypeName for T {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Return the type name as a spanned string
|
2019-11-04 16:47:03 +01:00
|
|
|
fn spanned_type_name(&self) -> Spanned<&'static str> {
|
2019-11-21 15:33:14 +01:00
|
|
|
self.type_name().spanned(self.span())
|
2019-11-04 16:47:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: ShellTypeName> SpannedTypeName for Tagged<T> {
|
2020-01-18 20:42:36 +01:00
|
|
|
/// Return the spanned type name for a Tagged value
|
2019-11-04 16:47:03 +01:00
|
|
|
fn spanned_type_name(&self) -> Spanned<&'static str> {
|
|
|
|
self.item.type_name().spanned(self.tag.span)
|
|
|
|
}
|
|
|
|
}
|
2019-07-24 00:22:11 +02:00
|
|
|
|
2020-01-18 20:42:36 +01:00
|
|
|
/// A trait to enable pretty-printing of type information
|
2019-11-04 16:47:03 +01:00
|
|
|
pub trait PrettyType {
|
|
|
|
fn pretty_type(&self) -> DebugDocBuilder;
|
|
|
|
}
|