forked from extern/nushell
This reverts commit e66bf70589
.
This commit is contained in:
@ -117,17 +117,6 @@ impl LiteGroup {
|
||||
pub fn push(&mut self, item: LitePipeline) {
|
||||
self.pipelines.push(item)
|
||||
}
|
||||
pub fn is_comment(&self) -> bool {
|
||||
if !self.is_empty()
|
||||
&& !self.pipelines[0].is_empty()
|
||||
&& !self.pipelines[0].commands.is_empty()
|
||||
&& !self.pipelines[0].commands[0].parts.is_empty()
|
||||
{
|
||||
self.pipelines[0].commands[0].parts[0].item.starts_with('#')
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
pub(crate) fn span(&self) -> Span {
|
||||
let start = if !self.pipelines.is_empty() {
|
||||
self.pipelines[0].span().start()
|
||||
@ -359,9 +348,7 @@ fn group(tokens: Vec<Token>) -> (LiteBlock, Option<ParseError>) {
|
||||
pipeline = LitePipeline::new();
|
||||
}
|
||||
if !group.is_empty() {
|
||||
if !group.is_comment() {
|
||||
groups.push(group);
|
||||
}
|
||||
groups.push(group);
|
||||
group = LiteGroup::new();
|
||||
}
|
||||
}
|
||||
@ -402,7 +389,7 @@ fn group(tokens: Vec<Token>) -> (LiteBlock, Option<ParseError>) {
|
||||
if !pipeline.is_empty() {
|
||||
group.push(pipeline);
|
||||
}
|
||||
if !group.is_empty() && !group.is_comment() {
|
||||
if !group.is_empty() {
|
||||
groups.push(group);
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,9 @@ use std::path::Path;
|
||||
use log::trace;
|
||||
use nu_errors::{ArgumentError, ParseError};
|
||||
use nu_protocol::hir::{
|
||||
self, Binary, Block, ClassifiedBlock, ClassifiedCommand, ClassifiedPipeline, Expression,
|
||||
ExternalRedirection, Flag, FlagKind, Group, InternalCommand, Member, NamedArguments, Operator,
|
||||
Pipeline, RangeOperator, SpannedExpression, Unit,
|
||||
self, Binary, Block, ClassifiedBlock, ClassifiedCommand, ClassifiedPipeline, Commands,
|
||||
Expression, ExternalRedirection, Flag, FlagKind, InternalCommand, Member, NamedArguments,
|
||||
Operator, RangeOperator, SpannedExpression, Unit,
|
||||
};
|
||||
use nu_protocol::{NamedType, PositionalType, Signature, SyntaxShape, UnspannedPathMember};
|
||||
use nu_source::{Span, Spanned, SpannedItem};
|
||||
@ -584,7 +584,7 @@ fn parse_interpolated_string(
|
||||
}
|
||||
}
|
||||
|
||||
let pipelines = vec![Pipeline {
|
||||
let block = vec![Commands {
|
||||
span: lite_arg.span,
|
||||
list: vec![ClassifiedCommand::Internal(InternalCommand {
|
||||
name: "build-string".to_owned(),
|
||||
@ -602,10 +602,8 @@ fn parse_interpolated_string(
|
||||
})],
|
||||
}];
|
||||
|
||||
let group = Group::new(pipelines, lite_arg.span);
|
||||
|
||||
let call = SpannedExpression {
|
||||
expr: Expression::Invocation(Block::new(vec![], vec![group], lite_arg.span)),
|
||||
expr: Expression::Invocation(Block::new(vec![], block, lite_arg.span)),
|
||||
span: lite_arg.span,
|
||||
};
|
||||
|
||||
@ -1343,14 +1341,10 @@ fn parse_positional_argument(
|
||||
parse_math_expression(idx, &lite_cmd.parts[idx..end_idx], registry, true);
|
||||
|
||||
let span = arg.span;
|
||||
let mut commands = hir::Pipeline::new(span);
|
||||
let mut commands = hir::Commands::new(span);
|
||||
commands.push(ClassifiedCommand::Expr(Box::new(arg)));
|
||||
|
||||
let block = hir::Block::new(
|
||||
vec![],
|
||||
vec![Group::new(vec![commands], lite_cmd.span())],
|
||||
span,
|
||||
);
|
||||
let block = hir::Block::new(vec![], vec![commands], span);
|
||||
|
||||
let arg = SpannedExpression::new(Expression::Block(block), span);
|
||||
|
||||
@ -1544,7 +1538,7 @@ fn classify_pipeline(
|
||||
lite_pipeline: &LitePipeline,
|
||||
registry: &dyn SignatureRegistry,
|
||||
) -> (ClassifiedPipeline, Option<ParseError>) {
|
||||
let mut commands = Pipeline::new(lite_pipeline.span());
|
||||
let mut commands = Commands::new(lite_pipeline.span());
|
||||
let mut error = None;
|
||||
|
||||
let mut iter = lite_pipeline.commands.iter().peekable();
|
||||
@ -1751,10 +1745,10 @@ fn expand_shorthand_forms(
|
||||
}
|
||||
|
||||
pub fn classify_block(lite_block: &LiteBlock, registry: &dyn SignatureRegistry) -> ClassifiedBlock {
|
||||
let mut block = vec![];
|
||||
let mut command_list = vec![];
|
||||
|
||||
let mut error = None;
|
||||
for lite_group in &lite_block.block {
|
||||
let mut command_list = vec![];
|
||||
for lite_pipeline in &lite_group.pipelines {
|
||||
let (lite_pipeline, vars, err) = expand_shorthand_forms(lite_pipeline);
|
||||
if error.is_none() {
|
||||
@ -1765,8 +1759,7 @@ pub fn classify_block(lite_block: &LiteBlock, registry: &dyn SignatureRegistry)
|
||||
|
||||
let pipeline = if let Some(vars) = vars {
|
||||
let span = pipeline.commands.span;
|
||||
let group = Group::new(vec![pipeline.commands.clone()], span);
|
||||
let block = hir::Block::new(vec![], vec![group], span);
|
||||
let block = hir::Block::new(vec![], vec![pipeline.commands.clone()], span);
|
||||
let mut call = hir::Call::new(
|
||||
Box::new(SpannedExpression {
|
||||
expr: Expression::string("with-env".to_string()),
|
||||
@ -1799,7 +1792,7 @@ pub fn classify_block(lite_block: &LiteBlock, registry: &dyn SignatureRegistry)
|
||||
args: call,
|
||||
});
|
||||
ClassifiedPipeline {
|
||||
commands: Pipeline {
|
||||
commands: Commands {
|
||||
list: vec![classified_with_env],
|
||||
span,
|
||||
},
|
||||
@ -1813,10 +1806,8 @@ pub fn classify_block(lite_block: &LiteBlock, registry: &dyn SignatureRegistry)
|
||||
error = err;
|
||||
}
|
||||
}
|
||||
let group = Group::new(command_list, lite_block.span());
|
||||
block.push(group);
|
||||
}
|
||||
let block = Block::new(vec![], block, lite_block.span());
|
||||
let block = Block::new(vec![], command_list, lite_block.span());
|
||||
|
||||
ClassifiedBlock::new(block, error)
|
||||
}
|
||||
|
@ -88,39 +88,35 @@ pub fn expression_to_flat_shape(e: &SpannedExpression) -> Vec<Spanned<FlatShape>
|
||||
pub fn shapes(commands: &Block) -> Vec<Spanned<FlatShape>> {
|
||||
let mut output = vec![];
|
||||
|
||||
for group in &commands.block {
|
||||
for pipeline in &group.pipelines {
|
||||
for command in &pipeline.list {
|
||||
match command {
|
||||
ClassifiedCommand::Internal(internal) => {
|
||||
output.append(&mut expression_to_flat_shape(&internal.args.head));
|
||||
for pipeline in &commands.block {
|
||||
for command in &pipeline.list {
|
||||
match command {
|
||||
ClassifiedCommand::Internal(internal) => {
|
||||
output.append(&mut expression_to_flat_shape(&internal.args.head));
|
||||
|
||||
if let Some(positionals) = &internal.args.positional {
|
||||
for positional_arg in positionals {
|
||||
output.append(&mut expression_to_flat_shape(positional_arg));
|
||||
}
|
||||
if let Some(positionals) = &internal.args.positional {
|
||||
for positional_arg in positionals {
|
||||
output.append(&mut expression_to_flat_shape(positional_arg));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(named) = &internal.args.named {
|
||||
for (_, named_arg) in named.iter() {
|
||||
match named_arg {
|
||||
NamedValue::PresentSwitch(span) => {
|
||||
output.push(FlatShape::Flag.spanned(*span));
|
||||
}
|
||||
NamedValue::Value(span, expr) => {
|
||||
output.push(FlatShape::Flag.spanned(*span));
|
||||
output.append(&mut expression_to_flat_shape(expr));
|
||||
}
|
||||
_ => {}
|
||||
if let Some(named) = &internal.args.named {
|
||||
for (_, named_arg) in named.iter() {
|
||||
match named_arg {
|
||||
NamedValue::PresentSwitch(span) => {
|
||||
output.push(FlatShape::Flag.spanned(*span));
|
||||
}
|
||||
NamedValue::Value(span, expr) => {
|
||||
output.push(FlatShape::Flag.spanned(*span));
|
||||
output.append(&mut expression_to_flat_shape(expr));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
ClassifiedCommand::Expr(expr) => {
|
||||
output.append(&mut expression_to_flat_shape(expr))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
ClassifiedCommand::Expr(expr) => output.append(&mut expression_to_flat_shape(expr)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user