Default values (#4770)

This commit is contained in:
JT
2022-03-07 15:08:56 -05:00
committed by GitHub
parent a3df2e5631
commit 1837bf775c
17 changed files with 289 additions and 19 deletions

View File

@ -1,7 +1,9 @@
use serde::{Deserialize, Serialize};
use super::Expression;
use crate::{DeclId, Span, Spanned};
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Call {
/// identifier of the declaration to call
pub decl_id: DeclId,

View File

@ -41,7 +41,7 @@ impl CellPath {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FullCellPath {
pub head: Expression,
pub tail: Vec<PathMember>,

View File

@ -1,9 +1,10 @@
use chrono::FixedOffset;
use serde::{Deserialize, Serialize};
use super::{Call, CellPath, Expression, FullCellPath, Operator, RangeOperator};
use crate::{ast::ImportPattern, BlockId, Signature, Span, Spanned, Unit, VarId};
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Expr {
Bool(bool),
Int(i64),

View File

@ -1,8 +1,10 @@
use serde::{Deserialize, Serialize};
use super::{Expr, Operator};
use crate::ast::ImportPattern;
use crate::{engine::StateWorkingSet, BlockId, Signature, Span, Type, VarId, IN_VARIABLE_ID};
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Expression {
pub expr: Expr,
pub span: Span,

View File

@ -1,21 +1,23 @@
use serde::{Deserialize, Serialize};
use crate::{span, OverlayId, Span};
use std::collections::HashSet;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ImportPatternMember {
Glob { span: Span },
Name { name: Vec<u8>, span: Span },
List { names: Vec<(Vec<u8>, Span)> },
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ImportPatternHead {
pub name: Vec<u8>,
pub id: Option<OverlayId>,
pub span: Span,
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ImportPattern {
pub head: ImportPatternHead,
pub members: Vec<ImportPatternMember>,

View File

@ -56,7 +56,7 @@ pub enum RangeInclusion {
RightExclusive,
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
pub struct RangeOperator {
pub inclusion: RangeInclusion,
pub span: Span,

View File

@ -2,6 +2,7 @@ use serde::Deserialize;
use serde::Serialize;
use crate::ast::Call;
use crate::ast::Expression;
use crate::engine::Command;
use crate::engine::EngineState;
use crate::engine::Stack;
@ -10,24 +11,28 @@ use crate::PipelineData;
use crate::SyntaxShape;
use crate::VarId;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Flag {
pub long: String,
pub short: Option<char>,
pub arg: Option<SyntaxShape>,
pub required: bool,
pub desc: String,
// For custom commands
pub var_id: Option<VarId>,
pub default_value: Option<Expression>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PositionalArg {
pub name: String,
pub desc: String,
pub shape: SyntaxShape,
// For custom commands
pub var_id: Option<VarId>,
pub default_value: Option<Expression>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@ -123,6 +128,7 @@ impl Signature {
desc: "Display this help message".into(),
required: false,
var_id: None,
default_value: None,
};
Signature {
@ -160,6 +166,7 @@ impl Signature {
desc: desc.into(),
shape: shape.into(),
var_id: None,
default_value: None,
});
self
@ -177,6 +184,7 @@ impl Signature {
desc: desc.into(),
shape: shape.into(),
var_id: None,
default_value: None,
});
self
@ -193,6 +201,7 @@ impl Signature {
desc: desc.into(),
shape: shape.into(),
var_id: None,
default_value: None,
});
self
@ -215,6 +224,7 @@ impl Signature {
required: false,
desc: desc.into(),
var_id: None,
default_value: None,
});
self
@ -237,6 +247,7 @@ impl Signature {
required: true,
desc: desc.into(),
var_id: None,
default_value: None,
});
self
@ -258,6 +269,7 @@ impl Signature {
required: false,
desc: desc.into(),
var_id: None,
default_value: None,
});
self

View File

@ -2,7 +2,7 @@ use miette::SourceSpan;
use serde::{Deserialize, Serialize};
/// A spanned area of interest, generic over what kind of thing is of interest
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct Spanned<T>
where
T: Clone + std::fmt::Debug,

View File

@ -2,6 +2,8 @@ use serde::{Deserialize, Serialize};
use std::fmt::Display;
use crate::SyntaxShape;
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Type {
Int,
@ -27,6 +29,34 @@ pub enum Type {
Signature,
}
impl Type {
pub fn to_shape(&self) -> SyntaxShape {
match self {
Type::Int => SyntaxShape::Int,
Type::Float => SyntaxShape::Number,
Type::Range => SyntaxShape::Range,
Type::Bool => SyntaxShape::Boolean,
Type::String => SyntaxShape::String,
Type::Block => SyntaxShape::Block(None), // FIXME needs more accuracy
Type::CellPath => SyntaxShape::CellPath,
Type::Duration => SyntaxShape::Duration,
Type::Date => SyntaxShape::DateTime,
Type::Filesize => SyntaxShape::Filesize,
Type::List(x) => SyntaxShape::List(Box::new(x.to_shape())),
Type::Number => SyntaxShape::Number,
Type::Nothing => SyntaxShape::Any,
Type::Record(_) => SyntaxShape::Record,
Type::Table => SyntaxShape::Table,
Type::ListStream => SyntaxShape::List(Box::new(SyntaxShape::Any)),
Type::Unknown => SyntaxShape::Any,
Type::Error => SyntaxShape::Any,
Type::Binary => SyntaxShape::Binary,
Type::Custom => SyntaxShape::Custom(Box::new(SyntaxShape::Any), String::new()),
Type::Signature => SyntaxShape::Signature,
}
}
}
impl Display for Type {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {

View File

@ -1,4 +1,6 @@
#[derive(Debug, Clone, Copy)]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum Unit {
// Filesize units: metric
Byte,