Skip to content

Commit fa41acf

Browse files
committed
Limit the order of positional and named parameters
1 parent afa334a commit fa41acf

File tree

15 files changed

+258
-438
lines changed

15 files changed

+258
-438
lines changed

projects/valkyrie-ast/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ serde = { version = "1.0.188", default-features = false, optional = true }
1818

1919
[dependencies.nyar-error]
2020
version = "0.1.*"
21-
path = 'C:\Users\Dell\CLionProjects\nyar-vm\projects\nyar-error'
2221
features = ["pratt"]
22+
#path = 'C:\Users\Dell\CLionProjects\nyar-vm\projects\nyar-error'
2323

2424
[dependencies.pretty-print]
2525
version = "0.1.9"

projects/valkyrie-ast/src/control_flow/control/mod.rs

-23
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@ use super::*;
22

33
mod display;
44

5-
/// `@tail_call(ret, recursion: true)`, **MIR**
6-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
7-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8-
pub struct TailCallNode {
9-
/// Weather it is a recursive tail call
10-
pub recursion: bool,
11-
}
12-
135
/// always equivalent to a statement that returns `( )`, and cannot be used as an `rvalue`.
146
#[derive(Clone, PartialEq, Eq, Hash)]
157
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
@@ -24,16 +16,6 @@ pub struct ControlNode {
2416
pub span: Range<u32>,
2517
}
2618

27-
/// `raise DivideZero()`
28-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
29-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30-
pub struct RaiseNode {
31-
/// The raised expression
32-
pub expression: Option<ExpressionKind>,
33-
/// The range of the node
34-
pub span: Range<u32>,
35-
}
36-
3719
/// The control flow keywords
3820
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
3921
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
@@ -63,8 +45,3 @@ pub enum ControlKind {
6345
/// `yield wait ^label`
6446
YieldSend,
6547
}
66-
impl ValkyrieNode for RaiseNode {
67-
fn get_range(&self) -> Range<usize> {
68-
Range { start: self.span.start as usize, end: self.span.end as usize }
69-
}
70-
}

projects/valkyrie-ast/src/expression_level/dispatch.rs

-2
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,12 @@ impl ValkyrieNode for ExpressionKind {
8080
Self::ClosureCall(node) => node.get_range(),
8181
Self::SubscriptCall(node) => node.get_range(),
8282
Self::GenericCall(node) => node.get_range(),
83-
Self::Resume(node) => node.get_range(),
8483
Self::If(node) => node.get_range(),
8584
Self::IfLet(node) => node.get_range(),
8685
Self::Switch(node) => node.get_range(),
8786
Self::Try(node) => node.get_range(),
8887
Self::Match(node) => node.get_range(),
8988
Self::DotMatchCall(node) => node.get_range(),
90-
9189
Self::Formatted(node) => node.get_range(),
9290
Self::OutputReference(node) => node.get_range(),
9391
Self::Array(node) => node.get_range(),

projects/valkyrie-ast/src/expression_level/display.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ impl Debug for ExpressionKind {
1919
Self::Infix(node) => Debug::fmt(node, f),
2020
Self::Tuple(node) => Debug::fmt(node, f),
2121
Self::Array(node) => Debug::fmt(node, f),
22-
Self::Resume(node) => Debug::fmt(node, f),
2322
Self::If(node) => Debug::fmt(node, f),
2423
Self::IfLet(node) => Debug::fmt(node, f),
2524
Self::Switch(node) => Debug::fmt(node, f),

projects/valkyrie-ast/src/expression_level/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ pub enum ExpressionKind {
112112
/// - Compound expression
113113
Array(Box<RangeNode>),
114114
/// - Standalone expression
115-
Resume(Box<RaiseNode>),
116-
/// - Standalone expression
117115
If(Box<IfStatement>),
118116
/// - Standalone expression
119117
IfLet(Box<GuardStatement>),

projects/valkyrie-ast/src/expression_level/operators/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod display;
55

66
mod logic;
77

8+
/// All builtin operator in valkyrie language
89
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
910
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1011
pub enum ValkyrieOperator {

projects/valkyrie-ast/src/expression_level/parameter/mod.rs

+46-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct ParametersList {
2323
}
2424

2525
/// `T: Type = type_expression`
26-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
26+
#[derive(Clone, PartialEq, Eq, Hash)]
2727
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2828
pub enum ParameterTerm {
2929
/// `<`
@@ -61,6 +61,51 @@ pub enum ParameterTerm {
6161
},
6262
}
6363

64+
impl Debug for ParameterTerm {
65+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
66+
match self {
67+
Self::LMark => f.write_str("<<<disable-index-parameters>>>"),
68+
Self::RMark => f.write_str("<<<require-named-parameters>>>"),
69+
Self::Single { annotations, key, bound, default } => {
70+
let w = &mut f.debug_struct("Parameter");
71+
w.field("key", &key.name);
72+
if !annotations.is_empty() {
73+
w.field("annotations", annotations);
74+
}
75+
if let Some(bound) = bound {
76+
w.field("bound", bound);
77+
}
78+
if let Some(default) = default {
79+
w.field("default", default);
80+
}
81+
w.finish()
82+
}
83+
Self::UnpackList { modifiers, key, bound } => {
84+
let w = &mut f.debug_struct("UnpackList");
85+
w.field("key", &key.name);
86+
if !modifiers.is_empty() {
87+
w.field("modifiers", modifiers);
88+
}
89+
if let Some(bound) = bound {
90+
w.field("bound", bound);
91+
}
92+
w.finish()
93+
}
94+
Self::UnpackDict { modifiers, key, bound } => {
95+
let w = &mut f.debug_struct("UnpackDict");
96+
w.field("key", &key.name);
97+
if !modifiers.is_empty() {
98+
w.field("modifiers", modifiers);
99+
}
100+
if let Some(bound) = bound {
101+
w.field("bound", bound);
102+
}
103+
w.finish()
104+
}
105+
}
106+
}
107+
}
108+
64109
impl Default for ParameterKind {
65110
fn default() -> Self {
66111
Self::Expression

projects/valkyrie-ast/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod string_like;
1717

1818
pub use crate::{
1919
control_flow::{
20-
control::{ControlKind, ControlNode, RaiseNode, TailCallNode},
20+
control::{ControlKind, ControlNode},
2121
do_catch::{MatchCallNode, MatchKind, MatchStatement},
2222
do_try::TryStatement,
2323
jmp_guard::{GuardPattern, GuardStatement},

projects/valkyrie-ast/src/package_level/classes/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ pub struct ClassDeclaration {
3636
pub span: Range<u32>,
3737
}
3838

39+
/// Valid terms in the class statements
3940
#[derive(Clone, PartialEq, Eq, Hash)]
4041
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4142
pub enum ClassTerm {
43+
/// `@expand {}`
4244
Macro(ProceduralNode),
45+
/// `field: Type = default`
4346
Field(FieldDeclaration),
47+
/// `method()`
4448
Method(MethodDeclaration),
49+
/// `domain { }`
4550
Domain(DomainDeclaration),
4651
}
4752

@@ -73,11 +78,11 @@ pub struct FieldDeclaration {
7378
pub span: Range<u32>,
7479
}
7580

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

101+
/// `domain { field; method(); domain {} }`
96102
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
97103
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
98104
pub struct DomainDeclaration {

projects/valkyrie-parser/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ version = "0.1.*"
1818
path = "../valkyrie-ast"
1919

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

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

2929
[dev-dependencies]

projects/valkyrie-parser/tests/declaration/class.ron

+21-51
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,8 @@ ClassDeclaration {
288288
},
289289
annotations: Empty,
290290
generics: [
291-
Single {
292-
annotations: Empty,
293-
key: Identifier("bool", 642..646),
294-
bound: None,
295-
default: None,
291+
Parameter {
292+
key: "bool",
296293
},
297294
],
298295
parameters: [],
@@ -542,11 +539,8 @@ ClassDeclaration {
542539
annotations: Empty,
543540
generics: [],
544541
parameters: [
545-
Single {
546-
annotations: Empty,
547-
key: Identifier("self", 1207..1211),
548-
bound: None,
549-
default: None,
542+
Parameter {
543+
key: "self",
550544
},
551545
],
552546
returns: ReturnType {
@@ -726,19 +720,12 @@ ClassDeclaration {
726720
},
727721
generics: [],
728722
parameters: [
729-
Single {
730-
annotations: Empty,
731-
key: Identifier("self", 1595..1599),
732-
bound: None,
733-
default: None,
723+
Parameter {
724+
key: "self",
734725
},
735-
Single {
736-
annotations: Empty,
737-
key: Identifier("rhs", 1601..1604),
738-
bound: Some(
739-
Self,
740-
),
741-
default: None,
726+
Parameter {
727+
key: "rhs",
728+
bound: Self,
742729
},
743730
],
744731
returns: ReturnType {
@@ -783,29 +770,18 @@ ClassDeclaration {
783770
],
784771
},
785772
generics: [
786-
Single {
787-
annotations: Empty,
788-
key: Identifier("T", 1688..1689),
789-
bound: None,
790-
default: None,
773+
Parameter {
774+
key: "T",
791775
},
792776
],
793777
parameters: [
794-
Single {
795-
annotations: Empty,
796-
key: Identifier("self", 1699..1703),
797-
bound: Some(
798-
T,
799-
),
800-
default: None,
778+
Parameter {
779+
key: "self",
780+
bound: T,
801781
},
802-
Single {
803-
annotations: Empty,
804-
key: Identifier("other", 1708..1713),
805-
bound: Some(
806-
T,
807-
),
808-
default: None,
782+
Parameter {
783+
key: "other",
784+
bound: T,
809785
},
810786
],
811787
returns: ReturnType {
@@ -992,17 +968,11 @@ ClassDeclaration {
992968
},
993969
generics: [],
994970
parameters: [
995-
Single {
996-
annotations: Empty,
997-
key: Identifier("self", 2073..2077),
998-
bound: None,
999-
default: None,
971+
Parameter {
972+
key: "self",
1000973
},
1001-
Single {
1002-
annotations: Empty,
1003-
key: Identifier("args", 2079..2083),
1004-
bound: None,
1005-
default: None,
974+
Parameter {
975+
key: "args",
1006976
},
1007977
],
1008978
returns: Auto,

0 commit comments

Comments
 (0)