2019-07-24 00:22:11 +02:00
|
|
|
// TODO: Temporary redirect
|
2019-08-29 13:08:28 +02:00
|
|
|
pub(crate) use crate::context::CommandRegistry;
|
2019-06-22 03:36:57 +02:00
|
|
|
use crate::evaluate::{evaluate_baseline_expr, Scope};
|
Overhaul the expansion system
The main thrust of this (very large) commit is an overhaul of the
expansion system.
The parsing pipeline is:
- Lightly parse the source file for atoms, basic delimiters and pipeline
structure into a token tree
- Expand the token tree into a HIR (high-level intermediate
representation) based upon the baseline syntax rules for expressions
and the syntactic shape of commands.
Somewhat non-traditionally, nu doesn't have an AST at all. It goes
directly from the token tree, which doesn't represent many important
distinctions (like the difference between `hello` and `5KB`) directly
into a high-level representation that doesn't have a direct
correspondence to the source code.
At a high level, nu commands work like macros, in the sense that the
syntactic shape of the invocation of a command depends on the
definition of a command.
However, commands do not have the ability to perform unrestricted
expansions of the token tree. Instead, they describe their arguments in
terms of syntactic shapes, and the expander expands the token tree into
HIR based upon that definition.
For example, the `where` command says that it takes a block as its first
required argument, and the description of the block syntactic shape
expands the syntax `cpu > 10` into HIR that represents
`{ $it.cpu > 10 }`.
This commit overhauls that system so that the syntactic shapes are
described in terms of a few new traits (`ExpandSyntax` and
`ExpandExpression` are the primary ones) that are more composable than
the previous system.
The first big win of this new system is the addition of the `ColumnPath`
shape, which looks like `cpu."max ghz"` or `package.version`.
Previously, while a variable path could look like `$it.cpu."max ghz"`,
the tail of a variable path could not be easily reused in other
contexts. Now, that tail is its own syntactic shape, and it can be used
as part of a command's signature.
This cleans up commands like `inc`, `add` and `edit` as well as
shorthand blocks, which can now look like `| where cpu."max ghz" > 10`
2019-09-18 00:26:27 +02:00
|
|
|
use crate::parser::{hir, hir::SyntaxShape};
|
2019-05-28 08:45:18 +02:00
|
|
|
use crate::prelude::*;
|
2019-06-22 03:36:57 +02:00
|
|
|
use derive_new::new;
|
2019-05-26 08:54:41 +02:00
|
|
|
use indexmap::IndexMap;
|
Overhaul the expansion system
The main thrust of this (very large) commit is an overhaul of the
expansion system.
The parsing pipeline is:
- Lightly parse the source file for atoms, basic delimiters and pipeline
structure into a token tree
- Expand the token tree into a HIR (high-level intermediate
representation) based upon the baseline syntax rules for expressions
and the syntactic shape of commands.
Somewhat non-traditionally, nu doesn't have an AST at all. It goes
directly from the token tree, which doesn't represent many important
distinctions (like the difference between `hello` and `5KB`) directly
into a high-level representation that doesn't have a direct
correspondence to the source code.
At a high level, nu commands work like macros, in the sense that the
syntactic shape of the invocation of a command depends on the
definition of a command.
However, commands do not have the ability to perform unrestricted
expansions of the token tree. Instead, they describe their arguments in
terms of syntactic shapes, and the expander expands the token tree into
HIR based upon that definition.
For example, the `where` command says that it takes a block as its first
required argument, and the description of the block syntactic shape
expands the syntax `cpu > 10` into HIR that represents
`{ $it.cpu > 10 }`.
This commit overhauls that system so that the syntactic shapes are
described in terms of a few new traits (`ExpandSyntax` and
`ExpandExpression` are the primary ones) that are more composable than
the previous system.
The first big win of this new system is the addition of the `ColumnPath`
shape, which looks like `cpu."max ghz"` or `package.version`.
Previously, while a variable path could look like `$it.cpu."max ghz"`,
the tail of a variable path could not be easily reused in other
contexts. Now, that tail is its own syntactic shape, and it can be used
as part of a command's signature.
This cleans up commands like `inc`, `add` and `edit` as well as
shorthand blocks, which can now look like `| where cpu."max ghz" > 10`
2019-09-18 00:26:27 +02:00
|
|
|
|
2019-07-02 09:56:20 +02:00
|
|
|
use serde::{Deserialize, Serialize};
|
2019-06-22 03:36:57 +02:00
|
|
|
use std::fmt;
|
2019-05-26 08:54:41 +02:00
|
|
|
|
2019-07-16 09:08:35 +02:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
2019-05-28 08:45:18 +02:00
|
|
|
pub enum NamedType {
|
2019-06-01 07:50:16 +02:00
|
|
|
Switch,
|
2019-09-14 18:30:24 +02:00
|
|
|
Mandatory(SyntaxShape),
|
|
|
|
Optional(SyntaxShape),
|
2019-05-26 08:54:41 +02:00
|
|
|
}
|
|
|
|
|
2019-07-02 09:56:20 +02:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
2019-05-28 08:45:18 +02:00
|
|
|
pub enum PositionalType {
|
2019-09-14 18:30:24 +02:00
|
|
|
Mandatory(String, SyntaxShape),
|
|
|
|
Optional(String, SyntaxShape),
|
2019-05-28 08:45:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PositionalType {
|
2019-09-14 18:30:24 +02:00
|
|
|
pub fn mandatory(name: &str, ty: SyntaxShape) -> PositionalType {
|
2019-07-15 23:16:27 +02:00
|
|
|
PositionalType::Mandatory(name.to_string(), ty)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mandatory_any(name: &str) -> PositionalType {
|
2019-09-14 18:30:24 +02:00
|
|
|
PositionalType::Mandatory(name.to_string(), SyntaxShape::Any)
|
2019-07-13 04:07:06 +02:00
|
|
|
}
|
|
|
|
|
2019-07-16 21:10:25 +02:00
|
|
|
pub fn mandatory_block(name: &str) -> PositionalType {
|
2019-09-14 18:30:24 +02:00
|
|
|
PositionalType::Mandatory(name.to_string(), SyntaxShape::Block)
|
2019-07-16 21:10:25 +02:00
|
|
|
}
|
|
|
|
|
2019-09-14 18:30:24 +02:00
|
|
|
pub fn optional(name: &str, ty: SyntaxShape) -> PositionalType {
|
2019-07-16 09:25:48 +02:00
|
|
|
PositionalType::Optional(name.to_string(), ty)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn optional_any(name: &str) -> PositionalType {
|
2019-09-14 18:30:24 +02:00
|
|
|
PositionalType::Optional(name.to_string(), SyntaxShape::Any)
|
2019-07-16 09:25:48 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 13:08:28 +02:00
|
|
|
pub(crate) fn name(&self) -> &str {
|
2019-06-30 08:14:40 +02:00
|
|
|
match self {
|
2019-07-03 22:31:15 +02:00
|
|
|
PositionalType::Mandatory(s, _) => s,
|
|
|
|
PositionalType::Optional(s, _) => s,
|
2019-06-30 08:14:40 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-15 23:16:27 +02:00
|
|
|
|
2019-09-14 18:30:24 +02:00
|
|
|
pub(crate) fn syntax_type(&self) -> SyntaxShape {
|
2019-07-15 23:16:27 +02:00
|
|
|
match *self {
|
|
|
|
PositionalType::Mandatory(_, t) => t,
|
|
|
|
PositionalType::Optional(_, t) => t,
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 08:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-08-02 21:15:07 +02:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone, new)]
|
|
|
|
pub struct Signature {
|
2019-07-02 09:56:20 +02:00
|
|
|
pub name: String,
|
2019-08-02 21:15:07 +02:00
|
|
|
#[new(default)]
|
2019-08-30 00:52:32 +02:00
|
|
|
pub usage: String,
|
|
|
|
#[new(default)]
|
2019-07-13 04:07:06 +02:00
|
|
|
pub positional: Vec<PositionalType>,
|
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
|
|
|
#[new(value = "None")]
|
2019-09-14 18:30:24 +02:00
|
|
|
pub rest_positional: Option<SyntaxShape>,
|
2019-08-02 21:15:07 +02:00
|
|
|
#[new(default)]
|
2019-07-02 09:56:20 +02:00
|
|
|
pub named: IndexMap<String, NamedType>,
|
2019-08-02 21:15:07 +02:00
|
|
|
#[new(value = "false")]
|
2019-07-02 09:56:20 +02:00
|
|
|
pub is_filter: bool,
|
2019-05-28 08:45:18 +02:00
|
|
|
}
|
|
|
|
|
2019-08-02 21:15:07 +02:00
|
|
|
impl Signature {
|
|
|
|
pub fn build(name: impl Into<String>) -> Signature {
|
|
|
|
Signature::new(name.into())
|
2019-07-24 06:10:48 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 00:52:32 +02:00
|
|
|
pub fn desc(mut self, usage: impl Into<String>) -> Signature {
|
|
|
|
self.usage = usage.into();
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-09-14 18:30:24 +02:00
|
|
|
pub fn required(mut self, name: impl Into<String>, ty: impl Into<SyntaxShape>) -> Signature {
|
2019-07-24 06:10:48 +02:00
|
|
|
self.positional
|
|
|
|
.push(PositionalType::Mandatory(name.into(), ty.into()));
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-09-14 18:30:24 +02:00
|
|
|
pub fn optional(mut self, name: impl Into<String>, ty: impl Into<SyntaxShape>) -> Signature {
|
2019-07-24 06:10:48 +02:00
|
|
|
self.positional
|
|
|
|
.push(PositionalType::Optional(name.into(), ty.into()));
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-09-14 18:30:24 +02:00
|
|
|
pub fn named(mut self, name: impl Into<String>, ty: impl Into<SyntaxShape>) -> Signature {
|
2019-08-02 21:15:07 +02:00
|
|
|
self.named
|
|
|
|
.insert(name.into(), NamedType::Optional(ty.into()));
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn required_named(
|
|
|
|
mut self,
|
|
|
|
name: impl Into<String>,
|
2019-09-14 18:30:24 +02:00
|
|
|
ty: impl Into<SyntaxShape>,
|
2019-08-02 21:15:07 +02:00
|
|
|
) -> Signature {
|
|
|
|
self.named
|
|
|
|
.insert(name.into(), NamedType::Mandatory(ty.into()));
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn switch(mut self, name: impl Into<String>) -> Signature {
|
|
|
|
self.named.insert(name.into(), NamedType::Switch);
|
2019-07-24 06:10:48 +02:00
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:15:07 +02:00
|
|
|
pub fn filter(mut self) -> Signature {
|
|
|
|
self.is_filter = true;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2019-09-14 18:30:24 +02:00
|
|
|
pub fn rest(mut self, ty: SyntaxShape) -> Signature {
|
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
|
|
|
self.rest_positional = Some(ty);
|
2019-08-02 21:15:07 +02:00
|
|
|
self
|
|
|
|
}
|
2019-07-24 06:10:48 +02:00
|
|
|
}
|
|
|
|
|
2019-07-27 09:45:00 +02:00
|
|
|
#[derive(Debug, Default, new, Serialize, Deserialize, Clone)]
|
2019-07-24 00:22:11 +02:00
|
|
|
pub struct EvaluatedArgs {
|
2019-08-01 03:58:42 +02:00
|
|
|
pub positional: Option<Vec<Tagged<Value>>>,
|
|
|
|
pub named: Option<IndexMap<String, Tagged<Value>>>,
|
2019-06-22 03:36:57 +02:00
|
|
|
}
|
|
|
|
|
2019-08-17 05:53:39 +02:00
|
|
|
impl EvaluatedArgs {
|
|
|
|
pub fn slice_from(&self, from: usize) -> Vec<Tagged<Value>> {
|
|
|
|
let positional = &self.positional;
|
|
|
|
|
|
|
|
match positional {
|
|
|
|
None => vec![],
|
|
|
|
Some(list) => list[from..].to_vec(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-22 03:36:57 +02:00
|
|
|
#[derive(new)]
|
2019-07-24 00:22:11 +02:00
|
|
|
pub struct DebugEvaluatedPositional<'a> {
|
2019-08-01 03:58:42 +02:00
|
|
|
positional: &'a Option<Vec<Tagged<Value>>>,
|
2019-06-22 03:36:57 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 14:16:11 +02:00
|
|
|
impl fmt::Debug for DebugEvaluatedPositional<'_> {
|
2019-06-22 03:36:57 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match &self.positional {
|
|
|
|
None => write!(f, "None"),
|
|
|
|
Some(positional) => f
|
|
|
|
.debug_list()
|
2019-07-09 06:31:26 +02:00
|
|
|
.entries(positional.iter().map(|p| p.debug()))
|
2019-06-22 03:36:57 +02:00
|
|
|
.finish(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(new)]
|
2019-07-24 00:22:11 +02:00
|
|
|
pub struct DebugEvaluatedNamed<'a> {
|
2019-08-01 03:58:42 +02:00
|
|
|
named: &'a Option<IndexMap<String, Tagged<Value>>>,
|
2019-06-22 03:36:57 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 14:16:11 +02:00
|
|
|
impl fmt::Debug for DebugEvaluatedNamed<'_> {
|
2019-06-22 03:36:57 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match &self.named {
|
|
|
|
None => write!(f, "None"),
|
|
|
|
Some(named) => f
|
|
|
|
.debug_map()
|
2019-07-09 06:31:26 +02:00
|
|
|
.entries(named.iter().map(|(k, v)| (k, v.debug())))
|
2019-06-22 03:36:57 +02:00
|
|
|
.finish(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 00:22:11 +02:00
|
|
|
pub struct DebugEvaluatedArgs<'a> {
|
|
|
|
args: &'a EvaluatedArgs,
|
2019-06-22 03:36:57 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 14:16:11 +02:00
|
|
|
impl fmt::Debug for DebugEvaluatedArgs<'_> {
|
2019-06-22 03:36:57 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let mut s = f.debug_struct("Args");
|
|
|
|
|
2019-07-24 00:22:11 +02:00
|
|
|
s.field(
|
|
|
|
"positional",
|
|
|
|
&DebugEvaluatedPositional::new(&self.args.positional),
|
|
|
|
);
|
|
|
|
s.field("named", &DebugEvaluatedNamed::new(&self.args.named));
|
2019-06-22 03:36:57 +02:00
|
|
|
|
|
|
|
s.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 00:22:11 +02:00
|
|
|
impl EvaluatedArgs {
|
2019-08-29 14:16:11 +02:00
|
|
|
pub fn debug(&self) -> DebugEvaluatedArgs<'_> {
|
2019-07-24 00:22:11 +02:00
|
|
|
DebugEvaluatedArgs { args: self }
|
2019-06-22 03:36:57 +02:00
|
|
|
}
|
|
|
|
|
2019-08-01 03:58:42 +02:00
|
|
|
pub fn nth(&self, pos: usize) -> Option<&Tagged<Value>> {
|
2019-06-22 03:36:57 +02:00
|
|
|
match &self.positional {
|
|
|
|
None => None,
|
|
|
|
Some(array) => array.iter().nth(pos),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 03:58:42 +02:00
|
|
|
pub fn expect_nth(&self, pos: usize) -> Result<&Tagged<Value>, ShellError> {
|
2019-06-22 03:36:57 +02:00
|
|
|
match &self.positional {
|
|
|
|
None => Err(ShellError::unimplemented("Better error: expect_nth")),
|
|
|
|
Some(array) => match array.iter().nth(pos) {
|
|
|
|
None => Err(ShellError::unimplemented("Better error: expect_nth")),
|
|
|
|
Some(item) => Ok(item),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn len(&self) -> usize {
|
|
|
|
match &self.positional {
|
|
|
|
None => 0,
|
|
|
|
Some(array) => array.len(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has(&self, name: &str) -> bool {
|
|
|
|
match &self.named {
|
|
|
|
None => false,
|
|
|
|
Some(named) => named.contains_key(name),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 03:58:42 +02:00
|
|
|
pub fn get(&self, name: &str) -> Option<&Tagged<Value>> {
|
2019-06-22 03:36:57 +02:00
|
|
|
match &self.named {
|
|
|
|
None => None,
|
|
|
|
Some(named) => named.get(name),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:16:11 +02:00
|
|
|
pub fn positional_iter(&self) -> PositionalIter<'_> {
|
2019-06-22 03:36:57 +02:00
|
|
|
match &self.positional {
|
|
|
|
None => PositionalIter::Empty,
|
|
|
|
Some(v) => {
|
|
|
|
let iter = v.iter();
|
|
|
|
PositionalIter::Array(iter)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum PositionalIter<'a> {
|
|
|
|
Empty,
|
2019-08-01 03:58:42 +02:00
|
|
|
Array(std::slice::Iter<'a, Tagged<Value>>),
|
2019-06-22 03:36:57 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 14:16:11 +02:00
|
|
|
impl<'a> Iterator for PositionalIter<'a> {
|
2019-08-01 03:58:42 +02:00
|
|
|
type Item = &'a Tagged<Value>;
|
2019-06-22 03:36:57 +02:00
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
match self {
|
|
|
|
PositionalIter::Empty => None,
|
|
|
|
PositionalIter::Array(iter) => iter.next(),
|
|
|
|
}
|
|
|
|
}
|
2019-06-01 07:50:16 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 13:08:28 +02:00
|
|
|
pub(crate) fn evaluate_args(
|
2019-07-24 00:22:11 +02:00
|
|
|
call: &hir::Call,
|
|
|
|
registry: &CommandRegistry,
|
2019-06-22 03:36:57 +02:00
|
|
|
scope: &Scope,
|
2019-06-22 22:46:16 +02:00
|
|
|
source: &Text,
|
2019-07-24 00:22:11 +02:00
|
|
|
) -> Result<EvaluatedArgs, ShellError> {
|
|
|
|
let positional: Result<Option<Vec<_>>, _> = call
|
2019-06-22 03:36:57 +02:00
|
|
|
.positional()
|
|
|
|
.as_ref()
|
|
|
|
.map(|p| {
|
|
|
|
p.iter()
|
2019-08-15 07:02:02 +02:00
|
|
|
.map(|e| evaluate_baseline_expr(e, registry, scope, source))
|
2019-06-22 03:36:57 +02:00
|
|
|
.collect()
|
|
|
|
})
|
|
|
|
.transpose();
|
|
|
|
|
|
|
|
let positional = positional?;
|
|
|
|
|
2019-08-09 06:51:21 +02:00
|
|
|
let named: Result<Option<IndexMap<String, Tagged<Value>>>, ShellError> = call
|
2019-06-22 03:36:57 +02:00
|
|
|
.named()
|
|
|
|
.as_ref()
|
|
|
|
.map(|n| {
|
|
|
|
let mut results = IndexMap::new();
|
|
|
|
|
|
|
|
for (name, value) in n.named.iter() {
|
|
|
|
match value {
|
2019-09-14 18:30:24 +02:00
|
|
|
hir::named::NamedValue::PresentSwitch(tag) => {
|
2019-09-14 19:16:52 +02:00
|
|
|
results.insert(name.clone(), Value::boolean(true).tagged(*tag));
|
2019-06-22 03:36:57 +02:00
|
|
|
}
|
|
|
|
hir::named::NamedValue::Value(expr) => {
|
|
|
|
results.insert(
|
|
|
|
name.clone(),
|
|
|
|
evaluate_baseline_expr(expr, registry, scope, source)?,
|
|
|
|
);
|
|
|
|
}
|
2019-06-01 07:50:16 +02:00
|
|
|
|
2019-06-22 03:36:57 +02:00
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
}
|
2019-06-01 07:50:16 +02:00
|
|
|
|
2019-06-22 03:36:57 +02:00
|
|
|
Ok(results)
|
|
|
|
})
|
|
|
|
.transpose();
|
2019-06-01 07:50:16 +02:00
|
|
|
|
2019-06-22 03:36:57 +02:00
|
|
|
let named = named?;
|
2019-06-01 07:50:16 +02:00
|
|
|
|
2019-07-24 00:22:11 +02:00
|
|
|
Ok(EvaluatedArgs::new(positional, named))
|
2019-05-26 08:54:41 +02:00
|
|
|
}
|