Skip to content

Commit

Permalink
Limit the order of positional and named parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Nov 21, 2023
1 parent 3cc6ff7 commit f3f2baa
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 438 deletions.
2 changes: 1 addition & 1 deletion projects/valkyrie-ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ serde = { version = "1.0.188", default-features = false, optional = true }

[dependencies.nyar-error]
version = "0.1.*"
path = 'C:\Users\Dell\CLionProjects\nyar-vm\projects\nyar-error'
features = ["pratt"]
#path = 'C:\Users\Dell\CLionProjects\nyar-vm\projects\nyar-error'

[dependencies.pretty-print]
version = "0.1.9"
Expand Down
23 changes: 0 additions & 23 deletions projects/valkyrie-ast/src/control_flow/control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ use super::*;

mod display;

/// `@tail_call(ret, recursion: true)`, **MIR**
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TailCallNode {
/// Weather it is a recursive tail call
pub recursion: bool,
}

/// always equivalent to a statement that returns `( )`, and cannot be used as an `rvalue`.
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand All @@ -24,16 +16,6 @@ pub struct ControlNode {
pub span: Range<u32>,
}

/// `raise DivideZero()`
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RaiseNode {
/// The raised expression
pub expression: Option<ExpressionKind>,
/// The range of the node
pub span: Range<u32>,
}

/// The control flow keywords
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -63,8 +45,3 @@ pub enum ControlKind {
/// `yield wait ^label`
YieldSend,
}
impl ValkyrieNode for RaiseNode {
fn get_range(&self) -> Range<usize> {
Range { start: self.span.start as usize, end: self.span.end as usize }
}
}
2 changes: 0 additions & 2 deletions projects/valkyrie-ast/src/expression_level/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,12 @@ impl ValkyrieNode for ExpressionKind {
Self::ClosureCall(node) => node.get_range(),
Self::SubscriptCall(node) => node.get_range(),
Self::GenericCall(node) => node.get_range(),
Self::Resume(node) => node.get_range(),
Self::If(node) => node.get_range(),
Self::IfLet(node) => node.get_range(),
Self::Switch(node) => node.get_range(),
Self::Try(node) => node.get_range(),
Self::Match(node) => node.get_range(),
Self::DotMatchCall(node) => node.get_range(),

Self::Formatted(node) => node.get_range(),
Self::OutputReference(node) => node.get_range(),
Self::Array(node) => node.get_range(),
Expand Down
1 change: 0 additions & 1 deletion projects/valkyrie-ast/src/expression_level/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ impl Debug for ExpressionKind {
Self::Infix(node) => Debug::fmt(node, f),
Self::Tuple(node) => Debug::fmt(node, f),
Self::Array(node) => Debug::fmt(node, f),
Self::Resume(node) => Debug::fmt(node, f),
Self::If(node) => Debug::fmt(node, f),
Self::IfLet(node) => Debug::fmt(node, f),
Self::Switch(node) => Debug::fmt(node, f),
Expand Down
2 changes: 0 additions & 2 deletions projects/valkyrie-ast/src/expression_level/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ pub enum ExpressionKind {
/// - Compound expression
Array(Box<RangeNode>),
/// - Standalone expression
Resume(Box<RaiseNode>),
/// - Standalone expression
If(Box<IfStatement>),
/// - Standalone expression
IfLet(Box<GuardStatement>),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod display;

mod logic;

/// All builtin operator in valkyrie language
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ValkyrieOperator {
Expand Down
47 changes: 46 additions & 1 deletion projects/valkyrie-ast/src/expression_level/parameter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct ParametersList {
}

/// `T: Type = type_expression`
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ParameterTerm {
/// `<`
Expand Down Expand Up @@ -61,6 +61,51 @@ pub enum ParameterTerm {
},
}

impl Debug for ParameterTerm {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
Self::LMark => f.write_str("<<<disable-index-parameters>>>"),
Self::RMark => f.write_str("<<<require-named-parameters>>>"),
Self::Single { annotations, key, bound, default } => {
let w = &mut f.debug_struct("Parameter");
w.field("key", &key.name);
if !annotations.is_empty() {
w.field("annotations", annotations);
}
if let Some(bound) = bound {
w.field("bound", bound);
}
if let Some(default) = default {
w.field("default", default);
}
w.finish()
}
Self::UnpackList { modifiers, key, bound } => {
let w = &mut f.debug_struct("UnpackList");
w.field("key", &key.name);
if !modifiers.is_empty() {
w.field("modifiers", modifiers);
}
if let Some(bound) = bound {
w.field("bound", bound);
}
w.finish()
}
Self::UnpackDict { modifiers, key, bound } => {
let w = &mut f.debug_struct("UnpackDict");
w.field("key", &key.name);
if !modifiers.is_empty() {
w.field("modifiers", modifiers);
}
if let Some(bound) = bound {
w.field("bound", bound);
}
w.finish()
}
}
}
}

impl Default for ParameterKind {
fn default() -> Self {
Self::Expression
Expand Down
2 changes: 1 addition & 1 deletion projects/valkyrie-ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod string_like;

pub use crate::{
control_flow::{
control::{ControlKind, ControlNode, RaiseNode, TailCallNode},
control::{ControlKind, ControlNode},
do_catch::{MatchCallNode, MatchKind, MatchStatement},
do_try::TryStatement,
jmp_guard::{GuardPattern, GuardStatement},
Expand Down
10 changes: 8 additions & 2 deletions projects/valkyrie-ast/src/package_level/classes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ pub struct ClassDeclaration {
pub span: Range<u32>,
}

/// Valid terms in the class statements
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ClassTerm {
/// `@expand {}`
Macro(ProceduralNode),
/// `field: Type = default`
Field(FieldDeclaration),
/// `method()`
Method(MethodDeclaration),
/// `domain { }`
Domain(DomainDeclaration),
}

Expand Down Expand Up @@ -73,11 +78,11 @@ pub struct FieldDeclaration {
pub span: Range<u32>,
}

/// `method()`
/// `#attribute modifier Trait::method(): Return / Effect { ... }`
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MethodDeclaration {
/// `method_name()`
/// The method name which may associated with a trait.
pub name: NamePathNode,
/// The modifiers of the node.
pub annotations: AnnotationNode,
Expand All @@ -93,6 +98,7 @@ pub struct MethodDeclaration {
pub span: Range<u32>,
}

/// `domain { field; method(); domain {} }`
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DomainDeclaration {
Expand Down
8 changes: 4 additions & 4 deletions projects/valkyrie-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ version = "0.1.*"
path = "../valkyrie-ast"

[dependencies.yggdrasil-rt]
version = "0.0.15"
path = 'C:\Users\Dell\CLionProjects\yggdrasil.rs\projects\ygg-rt'
version = "0.0.16"
#path = 'C:\Users\Dell\CLionProjects\yggdrasil.rs\projects\ygg-rt'

[dependencies.nyar-error]
version = "0.1.9"
path = 'C:\Users\Dell\CLionProjects\nyar-vm\projects\nyar-error'
version = "0.1.10"
#path = 'C:\Users\Dell\CLionProjects\nyar-vm\projects\nyar-error'
features = ["pratt", "yggdrasil-rt"]

[dev-dependencies]
Expand Down
72 changes: 21 additions & 51 deletions projects/valkyrie-parser/tests/declaration/class.ron
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,8 @@ ClassDeclaration {
},
annotations: Empty,
generics: [
Single {
annotations: Empty,
key: Identifier("bool", 642..646),
bound: None,
default: None,
Parameter {
key: "bool",
},
],
parameters: [],
Expand Down Expand Up @@ -542,11 +539,8 @@ ClassDeclaration {
annotations: Empty,
generics: [],
parameters: [
Single {
annotations: Empty,
key: Identifier("self", 1207..1211),
bound: None,
default: None,
Parameter {
key: "self",
},
],
returns: ReturnType {
Expand Down Expand Up @@ -726,19 +720,12 @@ ClassDeclaration {
},
generics: [],
parameters: [
Single {
annotations: Empty,
key: Identifier("self", 1595..1599),
bound: None,
default: None,
Parameter {
key: "self",
},
Single {
annotations: Empty,
key: Identifier("rhs", 1601..1604),
bound: Some(
Self,
),
default: None,
Parameter {
key: "rhs",
bound: Self,
},
],
returns: ReturnType {
Expand Down Expand Up @@ -783,29 +770,18 @@ ClassDeclaration {
],
},
generics: [
Single {
annotations: Empty,
key: Identifier("T", 1688..1689),
bound: None,
default: None,
Parameter {
key: "T",
},
],
parameters: [
Single {
annotations: Empty,
key: Identifier("self", 1699..1703),
bound: Some(
T,
),
default: None,
Parameter {
key: "self",
bound: T,
},
Single {
annotations: Empty,
key: Identifier("other", 1708..1713),
bound: Some(
T,
),
default: None,
Parameter {
key: "other",
bound: T,
},
],
returns: ReturnType {
Expand Down Expand Up @@ -992,17 +968,11 @@ ClassDeclaration {
},
generics: [],
parameters: [
Single {
annotations: Empty,
key: Identifier("self", 2073..2077),
bound: None,
default: None,
Parameter {
key: "self",
},
Single {
annotations: Empty,
key: Identifier("args", 2079..2083),
bound: None,
default: None,
Parameter {
key: "args",
},
],
returns: Auto,
Expand Down
Loading

0 comments on commit f3f2baa

Please sign in to comment.