forked from extern/nushell
Remove statements, replaced by pipelines (#4482)
This commit is contained in:
@ -2,12 +2,12 @@ use std::ops::{Index, IndexMut};
|
||||
|
||||
use crate::{Signature, Span, VarId};
|
||||
|
||||
use super::Statement;
|
||||
use super::Pipeline;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Block {
|
||||
pub signature: Box<Signature>,
|
||||
pub stmts: Vec<Statement>,
|
||||
pub pipelines: Vec<Pipeline>,
|
||||
pub captures: Vec<VarId>,
|
||||
pub redirect_env: bool,
|
||||
pub span: Option<Span>, // None option encodes no span to avoid using test_span()
|
||||
@ -15,25 +15,25 @@ pub struct Block {
|
||||
|
||||
impl Block {
|
||||
pub fn len(&self) -> usize {
|
||||
self.stmts.len()
|
||||
self.pipelines.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.stmts.is_empty()
|
||||
self.pipelines.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<usize> for Block {
|
||||
type Output = Statement;
|
||||
type Output = Pipeline;
|
||||
|
||||
fn index(&self, index: usize) -> &Self::Output {
|
||||
&self.stmts[index]
|
||||
&self.pipelines[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexMut<usize> for Block {
|
||||
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
||||
&mut self.stmts[index]
|
||||
&mut self.pipelines[index]
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ impl Block {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
signature: Box::new(Signature::new("")),
|
||||
stmts: vec![],
|
||||
pipelines: vec![],
|
||||
captures: vec![],
|
||||
redirect_env: false,
|
||||
span: None,
|
||||
@ -57,12 +57,12 @@ impl Block {
|
||||
|
||||
impl<T> From<T> for Block
|
||||
where
|
||||
T: Iterator<Item = Statement>,
|
||||
T: Iterator<Item = Pipeline>,
|
||||
{
|
||||
fn from(stmts: T) -> Self {
|
||||
fn from(pipelines: T) -> Self {
|
||||
Self {
|
||||
signature: Box::new(Signature::new("")),
|
||||
stmts: stmts.collect(),
|
||||
pipelines: pipelines.collect(),
|
||||
captures: vec![],
|
||||
redirect_env: false,
|
||||
span: None,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::{Expr, Operator, Statement};
|
||||
use super::{Expr, Operator};
|
||||
use crate::ast::ImportPattern;
|
||||
use crate::{engine::StateWorkingSet, BlockId, Signature, Span, Type, VarId, IN_VARIABLE_ID};
|
||||
|
||||
@ -116,7 +116,7 @@ impl Expression {
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Some(Statement::Pipeline(pipeline)) = block.stmts.get(0) {
|
||||
if let Some(pipeline) = block.pipelines.get(0) {
|
||||
match pipeline.expressions.get(0) {
|
||||
Some(expr) => expr.has_in_variable(working_set),
|
||||
None => false,
|
||||
@ -218,7 +218,7 @@ impl Expression {
|
||||
Expr::RowCondition(block_id) | Expr::Subexpression(block_id) => {
|
||||
let block = working_set.get_block(*block_id);
|
||||
|
||||
if let Some(Statement::Pipeline(pipeline)) = block.stmts.get(0) {
|
||||
if let Some(pipeline) = block.pipelines.get(0) {
|
||||
if let Some(expr) = pipeline.expressions.get(0) {
|
||||
expr.has_in_variable(working_set)
|
||||
} else {
|
||||
@ -261,7 +261,7 @@ impl Expression {
|
||||
Expr::Block(block_id) => {
|
||||
let block = working_set.get_block(*block_id);
|
||||
|
||||
let new_expr = if let Some(Statement::Pipeline(pipeline)) = block.stmts.get(0) {
|
||||
let new_expr = if let Some(pipeline) = block.pipelines.get(0) {
|
||||
if let Some(expr) = pipeline.expressions.get(0) {
|
||||
let mut new_expr = expr.clone();
|
||||
new_expr.replace_in_variable(working_set, new_var_id);
|
||||
@ -276,7 +276,7 @@ impl Expression {
|
||||
let block = working_set.get_block_mut(*block_id);
|
||||
|
||||
if let Some(new_expr) = new_expr {
|
||||
if let Some(Statement::Pipeline(pipeline)) = block.stmts.get_mut(0) {
|
||||
if let Some(pipeline) = block.pipelines.get_mut(0) {
|
||||
if let Some(expr) = pipeline.expressions.get_mut(0) {
|
||||
*expr = new_expr
|
||||
}
|
||||
@ -353,7 +353,7 @@ impl Expression {
|
||||
Expr::RowCondition(block_id) | Expr::Subexpression(block_id) => {
|
||||
let block = working_set.get_block(*block_id);
|
||||
|
||||
let new_expr = if let Some(Statement::Pipeline(pipeline)) = block.stmts.get(0) {
|
||||
let new_expr = if let Some(pipeline) = block.pipelines.get(0) {
|
||||
if let Some(expr) = pipeline.expressions.get(0) {
|
||||
let mut new_expr = expr.clone();
|
||||
new_expr.replace_in_variable(working_set, new_var_id);
|
||||
@ -368,7 +368,7 @@ impl Expression {
|
||||
let block = working_set.get_block_mut(*block_id);
|
||||
|
||||
if let Some(new_expr) = new_expr {
|
||||
if let Some(Statement::Pipeline(pipeline)) = block.stmts.get_mut(0) {
|
||||
if let Some(pipeline) = block.pipelines.get_mut(0) {
|
||||
if let Some(expr) = pipeline.expressions.get_mut(0) {
|
||||
*expr = new_expr
|
||||
}
|
||||
@ -420,11 +420,9 @@ impl Expression {
|
||||
Expr::Block(block_id) => {
|
||||
let mut block = working_set.get_block(*block_id).clone();
|
||||
|
||||
for stmt in block.stmts.iter_mut() {
|
||||
if let Statement::Pipeline(pipeline) = stmt {
|
||||
for expr in pipeline.expressions.iter_mut() {
|
||||
expr.replace_span(working_set, replaced, new_span)
|
||||
}
|
||||
for pipeline in block.pipelines.iter_mut() {
|
||||
for expr in pipeline.expressions.iter_mut() {
|
||||
expr.replace_span(working_set, replaced, new_span)
|
||||
}
|
||||
}
|
||||
|
||||
@ -497,11 +495,9 @@ impl Expression {
|
||||
Expr::RowCondition(block_id) | Expr::Subexpression(block_id) => {
|
||||
let mut block = working_set.get_block(*block_id).clone();
|
||||
|
||||
for stmt in block.stmts.iter_mut() {
|
||||
if let Statement::Pipeline(pipeline) = stmt {
|
||||
for expr in pipeline.expressions.iter_mut() {
|
||||
expr.replace_span(working_set, replaced, new_span)
|
||||
}
|
||||
for pipeline in block.pipelines.iter_mut() {
|
||||
for expr in pipeline.expressions.iter_mut() {
|
||||
expr.replace_span(working_set, replaced, new_span)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ mod expression;
|
||||
mod import_pattern;
|
||||
mod operator;
|
||||
mod pipeline;
|
||||
mod statement;
|
||||
|
||||
pub use block::*;
|
||||
pub use call::*;
|
||||
@ -16,4 +15,3 @@ pub use expression::*;
|
||||
pub use import_pattern::*;
|
||||
pub use operator::*;
|
||||
pub use pipeline::*;
|
||||
pub use statement::*;
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
use crate::ast::Expression;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -21,4 +23,26 @@ impl Pipeline {
|
||||
pub fn from_vec(expressions: Vec<Expression>) -> Pipeline {
|
||||
Self { expressions }
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.expressions.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.expressions.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<usize> for Pipeline {
|
||||
type Output = Expression;
|
||||
|
||||
fn index(&self, index: usize) -> &Self::Output {
|
||||
&self.expressions[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexMut<usize> for Pipeline {
|
||||
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
||||
&mut self.expressions[index]
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
use super::Pipeline;
|
||||
use crate::DeclId;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Statement {
|
||||
Declaration(DeclId),
|
||||
Pipeline(Pipeline),
|
||||
}
|
Reference in New Issue
Block a user