Overhaul the coloring system
This commit replaces the previous naive coloring system with a coloring
system that is more aligned with the parser.
The main benefit of this change is that it allows us to use parsing
rules to decide how to color tokens.
For example, consider the following syntax:
```
$ ps | where cpu > 10
```
Ideally, we could color `cpu` like a column name and not a string,
because `cpu > 10` is a shorthand block syntax that expands to
`{ $it.cpu > 10 }`.
The way that we know that it's a shorthand block is that the `where`
command declares that its first parameter is a `SyntaxShape::Block`,
which allows the shorthand block form.
In order to accomplish this, we need to color the tokens in a way that
corresponds to their expanded semantics, which means that high-fidelity
coloring requires expansion.
This commit adds a `ColorSyntax` trait that corresponds to the
`ExpandExpression` trait. The semantics are fairly similar, with a few
differences.
First `ExpandExpression` consumes N tokens and returns a single
`hir::Expression`. `ColorSyntax` consumes N tokens and writes M
`FlatShape` tokens to the output.
Concretely, for syntax like `[1 2 3]`
- `ExpandExpression` takes a single token node and produces a single
`hir::Expression`
- `ColorSyntax` takes the same token node and emits 7 `FlatShape`s
(open delimiter, int, whitespace, int, whitespace, int, close
delimiter)
Second, `ColorSyntax` is more willing to plow through failures than
`ExpandExpression`.
In particular, consider syntax like
```
$ ps | where cpu >
```
In this case
- `ExpandExpression` will see that the `where` command is expecting a
block, see that it's not a literal block and try to parse it as a
shorthand block. It will successfully find a member followed by an
infix operator, but not a following expression. That means that the
entire pipeline part fails to parse and is a syntax error.
- `ColorSyntax` will also try to parse it as a shorthand block and
ultimately fail, but it will fall back to "backoff coloring mode",
which parsing any unidentified tokens in an unfallible, simple way. In
this case, `cpu` will color as a string and `>` will color as an
operator.
Finally, it's very important that coloring a pipeline infallibly colors
the entire string, doesn't fail, and doesn't get stuck in an infinite
loop.
In order to accomplish this, this PR separates `ColorSyntax`, which is
infallible from `FallibleColorSyntax`, which might fail. This allows the
type system to let us know if our coloring rules bottom out at at an
infallible rule.
It's not perfect: it's still possible for the coloring process to get
stuck or consume tokens non-atomically. I intend to reduce the
opportunity for those problems in a future commit. In the meantime, the
current system catches a number of mistakes (like trying to use a
fallible coloring rule in a loop without thinking about the possibility
that it will never terminate).
2019-10-06 22:22:50 +02:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! return_err {
|
|
|
|
($expr:expr) => {
|
|
|
|
match $expr {
|
|
|
|
Err(_) => return,
|
|
|
|
Ok(expr) => expr,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! stream {
|
|
|
|
($($expr:expr),*) => {{
|
|
|
|
let mut v = VecDeque::new();
|
|
|
|
|
|
|
|
$(
|
|
|
|
v.push_back($expr);
|
|
|
|
)*
|
|
|
|
|
|
|
|
v
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! trace_stream {
|
2019-11-21 15:33:14 +01:00
|
|
|
(target: $target:tt, $desc:tt = $expr:expr) => {{
|
2019-07-12 21:22:08 +02:00
|
|
|
if log::log_enabled!(target: $target, log::Level::Trace) {
|
2019-07-03 22:31:15 +02:00
|
|
|
use futures::stream::StreamExt;
|
|
|
|
|
Move external closer to internal (#1611)
* Refactor InputStream and affected commands.
First, making `values` private and leaning on the `Stream` implementation makes
consumes of `InputStream` less likely to have to change in the future, if we
change what an `InputStream` is internally.
Second, we're dropping `Option<InputStream>` as the input to pipelines,
internals, and externals. Instead, `InputStream.is_empty` can be used to check
for "emptiness". Empty streams are typically only ever used as the first input
to a pipeline.
* Add run_external internal command.
We want to push external commands closer to internal commands, eventually
eliminating the concept of "external" completely. This means we can consolidate
a couple of things:
- Variable evaluation (for example, `$it`, `$nu`, alias vars)
- Behaviour of whole stream vs per-item external execution
It should also make it easier for us to start introducing argument signatures
for external commands,
* Update run_external.rs
* Update run_external.rs
* Update run_external.rs
* Update run_external.rs
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
2020-04-20 05:30:44 +02:00
|
|
|
let objects = $expr.inspect(move |o| {
|
2019-11-21 15:33:14 +01:00
|
|
|
trace!(
|
|
|
|
target: $target,
|
|
|
|
"{} = {}",
|
|
|
|
$desc,
|
|
|
|
nu_source::PrettyDebug::plain_string(o, 70)
|
|
|
|
);
|
2019-07-03 22:31:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$crate::stream::InputStream::from_stream(objects.boxed())
|
|
|
|
} else {
|
|
|
|
$expr
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
Add support for ~ expansion
This ended up being a bit of a yak shave. The basic idea in this commit is to
expand `~` in paths, but only in paths.
The way this is accomplished is by doing the expansion inside of the code that
parses literal syntax for `SyntaxType::Path`.
As a quick refresher: every command is entitled to expand its arguments in a
custom way. While this could in theory be used for general-purpose macros,
today the expansion facility is limited to syntactic hints.
For example, the syntax `where cpu > 0` expands under the hood to
`where { $it.cpu > 0 }`. This happens because the first argument to `where`
is defined as a `SyntaxType::Block`, and the parser coerces binary expressions
whose left-hand-side looks like a member into a block when the command is
expecting one.
This is mildly more magical than what most programming languages would do,
but we believe that it makes sense to allow commands to fine-tune the syntax
because of the domain nushell is in (command-line shells).
The syntactic expansions supported by this facility are relatively limited.
For example, we don't allow `$it` to become a bare word, simply because the
command asks for a string in the relevant position. That would quickly
become more confusing than it's worth.
This PR adds a new `SyntaxType` rule: `SyntaxType::Path`. When a command
declares a parameter as a `SyntaxType::Path`, string literals and bare
words passed as an argument to that parameter are processed using the
path expansion rules. Right now, that only means that `~` is expanded into
the home directory, but additional rules are possible in the future.
By restricting this expansion to a syntactic expansion when passed as an
argument to a command expecting a path, we avoid making `~` a generally
reserved character. This will also allow us to give good tab completion
for paths with `~` characters in them when a command is expecting a path.
In order to accomplish the above, this commit changes the parsing functions
to take a `Context` instead of just a `CommandRegistry`. From the perspective
of macro expansion, you can think of the `CommandRegistry` as a dictionary
of in-scope macros, and the `Context` as the compile-time state used in
expansion. This could gain additional functionality over time as we find
more uses for the expansion system.
2019-08-26 21:21:03 +02:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! trace_out_stream {
|
2019-11-21 15:33:14 +01:00
|
|
|
(target: $target:tt, $desc:tt = $expr:expr) => {{
|
Add support for ~ expansion
This ended up being a bit of a yak shave. The basic idea in this commit is to
expand `~` in paths, but only in paths.
The way this is accomplished is by doing the expansion inside of the code that
parses literal syntax for `SyntaxType::Path`.
As a quick refresher: every command is entitled to expand its arguments in a
custom way. While this could in theory be used for general-purpose macros,
today the expansion facility is limited to syntactic hints.
For example, the syntax `where cpu > 0` expands under the hood to
`where { $it.cpu > 0 }`. This happens because the first argument to `where`
is defined as a `SyntaxType::Block`, and the parser coerces binary expressions
whose left-hand-side looks like a member into a block when the command is
expecting one.
This is mildly more magical than what most programming languages would do,
but we believe that it makes sense to allow commands to fine-tune the syntax
because of the domain nushell is in (command-line shells).
The syntactic expansions supported by this facility are relatively limited.
For example, we don't allow `$it` to become a bare word, simply because the
command asks for a string in the relevant position. That would quickly
become more confusing than it's worth.
This PR adds a new `SyntaxType` rule: `SyntaxType::Path`. When a command
declares a parameter as a `SyntaxType::Path`, string literals and bare
words passed as an argument to that parameter are processed using the
path expansion rules. Right now, that only means that `~` is expanded into
the home directory, but additional rules are possible in the future.
By restricting this expansion to a syntactic expansion when passed as an
argument to a command expecting a path, we avoid making `~` a generally
reserved character. This will also allow us to give good tab completion
for paths with `~` characters in them when a command is expecting a path.
In order to accomplish the above, this commit changes the parsing functions
to take a `Context` instead of just a `CommandRegistry`. From the perspective
of macro expansion, you can think of the `CommandRegistry` as a dictionary
of in-scope macros, and the `Context` as the compile-time state used in
expansion. This could gain additional functionality over time as we find
more uses for the expansion system.
2019-08-26 21:21:03 +02:00
|
|
|
if log::log_enabled!(target: $target, log::Level::Trace) {
|
|
|
|
use futures::stream::StreamExt;
|
|
|
|
|
Move external closer to internal (#1611)
* Refactor InputStream and affected commands.
First, making `values` private and leaning on the `Stream` implementation makes
consumes of `InputStream` less likely to have to change in the future, if we
change what an `InputStream` is internally.
Second, we're dropping `Option<InputStream>` as the input to pipelines,
internals, and externals. Instead, `InputStream.is_empty` can be used to check
for "emptiness". Empty streams are typically only ever used as the first input
to a pipeline.
* Add run_external internal command.
We want to push external commands closer to internal commands, eventually
eliminating the concept of "external" completely. This means we can consolidate
a couple of things:
- Variable evaluation (for example, `$it`, `$nu`, alias vars)
- Behaviour of whole stream vs per-item external execution
It should also make it easier for us to start introducing argument signatures
for external commands,
* Update run_external.rs
* Update run_external.rs
* Update run_external.rs
* Update run_external.rs
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
2020-04-20 05:30:44 +02:00
|
|
|
let objects = $expr.inspect(move |o| {
|
2019-11-21 15:33:14 +01:00
|
|
|
trace!(
|
|
|
|
target: $target,
|
|
|
|
"{} = {}",
|
|
|
|
$desc,
|
|
|
|
match o {
|
|
|
|
Err(err) => format!("{:?}", err),
|
|
|
|
Ok(value) => value.display(),
|
|
|
|
}
|
|
|
|
);
|
Add support for ~ expansion
This ended up being a bit of a yak shave. The basic idea in this commit is to
expand `~` in paths, but only in paths.
The way this is accomplished is by doing the expansion inside of the code that
parses literal syntax for `SyntaxType::Path`.
As a quick refresher: every command is entitled to expand its arguments in a
custom way. While this could in theory be used for general-purpose macros,
today the expansion facility is limited to syntactic hints.
For example, the syntax `where cpu > 0` expands under the hood to
`where { $it.cpu > 0 }`. This happens because the first argument to `where`
is defined as a `SyntaxType::Block`, and the parser coerces binary expressions
whose left-hand-side looks like a member into a block when the command is
expecting one.
This is mildly more magical than what most programming languages would do,
but we believe that it makes sense to allow commands to fine-tune the syntax
because of the domain nushell is in (command-line shells).
The syntactic expansions supported by this facility are relatively limited.
For example, we don't allow `$it` to become a bare word, simply because the
command asks for a string in the relevant position. That would quickly
become more confusing than it's worth.
This PR adds a new `SyntaxType` rule: `SyntaxType::Path`. When a command
declares a parameter as a `SyntaxType::Path`, string literals and bare
words passed as an argument to that parameter are processed using the
path expansion rules. Right now, that only means that `~` is expanded into
the home directory, but additional rules are possible in the future.
By restricting this expansion to a syntactic expansion when passed as an
argument to a command expecting a path, we avoid making `~` a generally
reserved character. This will also allow us to give good tab completion
for paths with `~` characters in them when a command is expecting a path.
In order to accomplish the above, this commit changes the parsing functions
to take a `Context` instead of just a `CommandRegistry`. From the perspective
of macro expansion, you can think of the `CommandRegistry` as a dictionary
of in-scope macros, and the `Context` as the compile-time state used in
expansion. This could gain additional functionality over time as we find
more uses for the expansion system.
2019-08-26 21:21:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$crate::stream::OutputStream::new(objects)
|
|
|
|
} else {
|
|
|
|
$expr
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2020-10-20 11:07:13 +02:00
|
|
|
pub(crate) use nu_protocol::{errln, out, outln, row};
|
Restructure and streamline token expansion (#1123)
Restructure and streamline token expansion
The purpose of this commit is to streamline the token expansion code, by
removing aspects of the code that are no longer relevant, removing
pointless duplication, and eliminating the need to pass the same
arguments to `expand_syntax`.
The first big-picture change in this commit is that instead of a handful
of `expand_` functions, which take a TokensIterator and ExpandContext, a
smaller number of methods on the `TokensIterator` do the same job.
The second big-picture change in this commit is fully eliminating the
coloring traits, making coloring a responsibility of the base expansion
implementations. This also means that the coloring tracer is merged into
the expansion tracer, so you can follow a single expansion and see how
the expansion process produced colored tokens.
One side effect of this change is that the expander itself is marginally
more error-correcting. The error correction works by switching from
structured expansion to `BackoffColoringMode` when an unexpected token
is found, which guarantees that all spans of the source are colored, but
may not be the most optimal error recovery strategy.
That said, because `BackoffColoringMode` only extends as far as a
closing delimiter (`)`, `]`, `}`) or pipe (`|`), it does result in
fairly granular correction strategy.
The current code still produces an `Err` (plus a complete list of
colored shapes) from the parsing process if any errors are encountered,
but this could easily be addressed now that the underlying expansion is
error-correcting.
This commit also colors any spans that are syntax errors in red, and
causes the parser to include some additional information about what
tokens were expected at any given point where an error was encountered,
so that completions and hinting could be more robust in the future.
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
Co-authored-by: Andrés N. Robalino <andres@androbtech.com>
2020-01-21 23:45:03 +01:00
|
|
|
use nu_source::HasFallibleSpan;
|
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-09-19 23:29:51 +02:00
|
|
|
pub(crate) use crate::command_registry::CommandRegistry;
|
2020-04-27 04:04:54 +02:00
|
|
|
pub(crate) use crate::commands::command::{CommandArgs, RawCommandArgs, RunnableContext};
|
2020-05-12 03:00:55 +02:00
|
|
|
pub(crate) use crate::commands::Example;
|
2020-09-19 23:29:51 +02:00
|
|
|
pub(crate) use crate::evaluation_context::EvaluationContext;
|
2020-08-18 09:00:02 +02:00
|
|
|
pub(crate) use nu_data::config;
|
|
|
|
pub(crate) use nu_data::value;
|
2020-06-20 05:41:53 +02:00
|
|
|
// pub(crate) use crate::env::host::handle_unexpected;
|
2019-08-29 13:08:28 +02:00
|
|
|
pub(crate) use crate::env::Host;
|
|
|
|
pub(crate) use crate::shell::filesystem_shell::FilesystemShell;
|
2019-09-05 18:23:42 +02:00
|
|
|
pub(crate) use crate::shell::help_shell::HelpShell;
|
2019-08-29 13:08:28 +02:00
|
|
|
pub(crate) use crate::shell::shell_manager::ShellManager;
|
|
|
|
pub(crate) use crate::shell::value_shell::ValueShell;
|
2020-03-29 16:55:54 +02:00
|
|
|
pub(crate) use crate::stream::{InputStream, InterruptibleStream, OutputStream};
|
2019-09-01 18:20:31 +02:00
|
|
|
pub(crate) use bigdecimal::BigDecimal;
|
2019-08-29 13:08:28 +02:00
|
|
|
pub(crate) use futures::stream::BoxStream;
|
2020-05-16 05:18:24 +02:00
|
|
|
pub(crate) use futures::{Stream, StreamExt};
|
2019-11-21 15:33:14 +01:00
|
|
|
pub(crate) use nu_source::{
|
2020-04-06 09:16:14 +02:00
|
|
|
b, AnchorLocation, DebugDocBuilder, PrettyDebug, PrettyDebugWithSource, Span, SpannedItem, Tag,
|
|
|
|
TaggedItem, Text,
|
2019-11-21 15:33:14 +01:00
|
|
|
};
|
2019-12-09 19:52:01 +01:00
|
|
|
pub(crate) use nu_value_ext::ValueExt;
|
2019-09-01 18:20:31 +02:00
|
|
|
pub(crate) use num_bigint::BigInt;
|
2019-11-30 01:21:05 +01:00
|
|
|
pub(crate) use num_traits::cast::ToPrimitive;
|
2019-09-01 18:20:31 +02:00
|
|
|
pub(crate) use serde::Deserialize;
|
2019-08-29 13:08:28 +02:00
|
|
|
pub(crate) use std::collections::VecDeque;
|
|
|
|
pub(crate) use std::future::Future;
|
2020-03-29 16:55:54 +02:00
|
|
|
pub(crate) use std::sync::atomic::AtomicBool;
|
2020-01-04 07:44:17 +01:00
|
|
|
pub(crate) use std::sync::Arc;
|
2019-07-03 22:31:15 +02:00
|
|
|
|
2020-05-29 10:22:52 +02:00
|
|
|
pub(crate) use async_trait::async_trait;
|
2020-05-27 06:50:26 +02:00
|
|
|
pub(crate) use indexmap::IndexMap;
|
2019-10-28 15:46:50 +01:00
|
|
|
pub(crate) use itertools::Itertools;
|
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
pub trait FromInputStream {
|
|
|
|
fn from_input_stream(self) -> OutputStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> FromInputStream for T
|
|
|
|
where
|
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
|
|
|
T: Stream<Item = nu_protocol::Value> + Send + 'static,
|
2019-07-03 22:31:15 +02:00
|
|
|
{
|
|
|
|
fn from_input_stream(self) -> OutputStream {
|
|
|
|
OutputStream {
|
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
|
|
|
values: self.map(nu_protocol::ReturnSuccess::value).boxed(),
|
2019-07-03 22:31:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-13 06:12:43 +02:00
|
|
|
pub trait ToInputStream {
|
|
|
|
fn to_input_stream(self) -> InputStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, U> ToInputStream for T
|
|
|
|
where
|
|
|
|
T: Stream<Item = U> + Send + 'static,
|
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
|
|
|
U: Into<Result<nu_protocol::Value, nu_errors::ShellError>>,
|
2019-10-13 06:12:43 +02:00
|
|
|
{
|
|
|
|
fn to_input_stream(self) -> InputStream {
|
Move external closer to internal (#1611)
* Refactor InputStream and affected commands.
First, making `values` private and leaning on the `Stream` implementation makes
consumes of `InputStream` less likely to have to change in the future, if we
change what an `InputStream` is internally.
Second, we're dropping `Option<InputStream>` as the input to pipelines,
internals, and externals. Instead, `InputStream.is_empty` can be used to check
for "emptiness". Empty streams are typically only ever used as the first input
to a pipeline.
* Add run_external internal command.
We want to push external commands closer to internal commands, eventually
eliminating the concept of "external" completely. This means we can consolidate
a couple of things:
- Variable evaluation (for example, `$it`, `$nu`, alias vars)
- Behaviour of whole stream vs per-item external execution
It should also make it easier for us to start introducing argument signatures
for external commands,
* Update run_external.rs
* Update run_external.rs
* Update run_external.rs
* Update run_external.rs
Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
2020-04-20 05:30:44 +02:00
|
|
|
InputStream::from_stream(self.map(|item| match item.into() {
|
|
|
|
Ok(result) => result,
|
|
|
|
Err(err) => match HasFallibleSpan::maybe_span(&err) {
|
|
|
|
Some(span) => nu_protocol::UntaggedValue::Error(err).into_value(span),
|
|
|
|
None => nu_protocol::UntaggedValue::Error(err).into_untagged_value(),
|
|
|
|
},
|
|
|
|
}))
|
2019-10-13 06:12:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
pub trait ToOutputStream {
|
|
|
|
fn to_output_stream(self) -> OutputStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, U> ToOutputStream for T
|
|
|
|
where
|
|
|
|
T: Stream<Item = U> + Send + 'static,
|
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
|
|
|
U: Into<nu_protocol::ReturnValue>,
|
2019-07-03 22:31:15 +02:00
|
|
|
{
|
|
|
|
fn to_output_stream(self) -> OutputStream {
|
|
|
|
OutputStream {
|
|
|
|
values: self.map(|item| item.into()).boxed(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-29 16:55:54 +02:00
|
|
|
|
|
|
|
pub trait Interruptible<V> {
|
|
|
|
fn interruptible(self, ctrl_c: Arc<AtomicBool>) -> InterruptibleStream<V>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<S, V> Interruptible<V> for S
|
|
|
|
where
|
|
|
|
S: Stream<Item = V> + Send + 'static,
|
|
|
|
{
|
|
|
|
fn interruptible(self, ctrl_c: Arc<AtomicBool>) -> InterruptibleStream<V> {
|
|
|
|
InterruptibleStream::new(self, ctrl_c)
|
|
|
|
}
|
|
|
|
}
|