forked from extern/nushell
Add wrap and get and cell_path parsing
This commit is contained in:
@ -45,4 +45,8 @@ impl Call {
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn nth(&self, pos: usize) -> Option<Expression> {
|
||||
self.positional.get(pos).cloned()
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
use super::Expression;
|
||||
use crate::Span;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum PathMember {
|
||||
String { val: String, span: Span },
|
||||
Int { val: usize, span: Span },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct CellPath {
|
||||
pub members: Vec<PathMember>,
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::{Call, Expression, FullCellPath, Operator, RangeOperator};
|
||||
use super::{Call, CellPath, Expression, FullCellPath, Operator, RangeOperator};
|
||||
use crate::{BlockId, Signature, Span, VarId};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -24,6 +24,7 @@ pub enum Expr {
|
||||
Table(Vec<Expression>, Vec<Vec<Expression>>),
|
||||
Keyword(Vec<u8>, Span, Box<Expression>),
|
||||
String(String), // FIXME: improve this in the future?
|
||||
CellPath(CellPath),
|
||||
FullCellPath(Box<FullCellPath>),
|
||||
Signature(Box<Signature>),
|
||||
Garbage,
|
||||
|
@ -9,7 +9,7 @@ pub use stream::*;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::ast::PathMember;
|
||||
use crate::ast::{CellPath, PathMember};
|
||||
use crate::{span, BlockId, Span, Type};
|
||||
|
||||
use crate::ShellError;
|
||||
@ -72,6 +72,10 @@ pub enum Value {
|
||||
val: Vec<u8>,
|
||||
span: Span,
|
||||
},
|
||||
CellPath {
|
||||
val: CellPath,
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
impl Value {
|
||||
@ -99,6 +103,7 @@ impl Value {
|
||||
Value::Stream { span, .. } => *span,
|
||||
Value::Nothing { span, .. } => *span,
|
||||
Value::Binary { span, .. } => *span,
|
||||
Value::CellPath { span, .. } => *span,
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,6 +124,7 @@ impl Value {
|
||||
Value::Nothing { span, .. } => *span = new_span,
|
||||
Value::Error { .. } => {}
|
||||
Value::Binary { span, .. } => *span = new_span,
|
||||
Value::CellPath { span, .. } => *span = new_span,
|
||||
}
|
||||
|
||||
self
|
||||
@ -143,6 +149,7 @@ impl Value {
|
||||
Value::Stream { .. } => Type::ValueStream,
|
||||
Value::Error { .. } => Type::Error,
|
||||
Value::Binary { .. } => Type::Binary,
|
||||
Value::CellPath { .. } => Type::CellPath,
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,6 +191,7 @@ impl Value {
|
||||
Value::Nothing { .. } => String::new(),
|
||||
Value::Error { error } => format!("{:?}", error),
|
||||
Value::Binary { val, .. } => format!("{:?}", val),
|
||||
Value::CellPath { val, .. } => format!("{:?}", val),
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,6 +223,7 @@ impl Value {
|
||||
Value::Nothing { .. } => String::new(),
|
||||
Value::Error { error } => format!("{:?}", error),
|
||||
Value::Binary { val, .. } => format!("{:?}", val),
|
||||
Value::CellPath { val, .. } => format!("{:?}", val),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user