Skip to content

Commit

Permalink
Generate archive of all test content
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Nov 7, 2023
1 parent 4ba237b commit 88eed2b
Show file tree
Hide file tree
Showing 30 changed files with 1,921 additions and 6,088 deletions.
2 changes: 1 addition & 1 deletion projects/valkyrie-ast/src/expression_level/apply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct ArgumentKeyNode {
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ApplyCallNode {
///
/// The call basement
pub base: ExpressionType,
/// Weather it is a monadic call
pub monadic: bool,
Expand Down
32 changes: 19 additions & 13 deletions projects/valkyrie-ast/src/expression_level/operators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ pub enum ValkyrieOperator {
/// binary operator:
VeryMuchLess,
/// binary operator: `≡`, `≢`
Equal(bool),
/// binary operator:
StrictlyEqual(bool),
Equal {
/// negative operator `!=`
negative: bool,
},
/// binary operator: `≡`, `≢`
StrictlyEqual {
/// negative operator `=!=`
negative: bool,
},
/// binary operator: `⊑, ⋢, is, is not`
Is {
/// negative operator: `⋢, is not`
Expand Down Expand Up @@ -169,8 +175,8 @@ impl ValkyrieOperator {

// infix - 3
Self::LogicMatrix { .. } => 14700,
Self::Equal(_) => 14700,
Self::StrictlyEqual(_) => 14700,
Self::Equal { .. } => 14700,
Self::StrictlyEqual { .. } => 14700,
// infix - 2
Self::Greater { .. } => 14800,
Self::Less { .. } => 14800,
Expand Down Expand Up @@ -268,13 +274,13 @@ impl ValkyrieOperator {
true => "∌",
false => "∋",
},
Self::Equal(v) => match v {
true => "",
false => "",
Self::Equal { negative } => match negative {
true => "",
false => "==",
},
Self::StrictlyEqual(v) => match v {
true => "",
false => "",
Self::StrictlyEqual { negative } => match negative {
true => "",
false => "",
},
Self::Reciprocal => "⅟",
Self::Roots(v) => match v {
Expand Down Expand Up @@ -309,8 +315,8 @@ impl ValkyrieOperator {
/// if this operatr can be override
pub fn overrideable(&self) -> bool {
match self {
Self::Equal(false) => false,
Self::StrictlyEqual(false) => false,
Self::Equal { negative: true } => false,
Self::StrictlyEqual { negative: true } => false,
_ => true,
}
}
Expand Down
5 changes: 5 additions & 0 deletions projects/valkyrie-parser/src/atomic/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ impl crate::NamepathNode {
}
}

impl crate::NamepathFreeNode {
pub fn build(&self, ctx: &ProgramContext) -> NamePathNode {
NamePathNode { names: self.identifier.iter().map(|v| v.build(ctx)).collect() }
}
}
impl crate::IdentifierNode {
pub fn build(&self, ctx: &ProgramContext) -> IdentifierNode {
match self {
Expand Down
19 changes: 18 additions & 1 deletion projects/valkyrie-parser/src/atomic/tuple.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::{TupleKeyNode, TuplePairNode};
use valkyrie_ast::{TupleKeyType, TupleTermNode};
use valkyrie_ast::{ApplyArgument, ApplyCallNode, SubscriptCallNode, TupleKeyType, TupleTermNode};

impl TupleLiteralNode {
pub fn build(&self, ctx: &ProgramContext) -> Validation<TupleNode> {
Expand Down Expand Up @@ -39,3 +39,20 @@ impl TupleKeyNode {
}
}
}

impl crate::TupleCallNode {
pub fn build(&self, ctx: &ProgramContext) -> Validation<ApplyCallNode> {
let monadic = self.op_and_then.is_some();
// let terms = self.tuple_literal.build(ctx)?.terms;
Success {
value: ApplyCallNode {
base: Default::default(),
monadic,
caller: Default::default(),
arguments: None,
span: self.span.clone(),
},
diagnostics: vec![],
}
}
}
48 changes: 32 additions & 16 deletions projects/valkyrie-parser/src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use crate::{
};
use nyar_error::{NyarError, Success, Validate, Validation};
use pratt::{Affix, PrattParser, Precedence};
use valkyrie_ast::{BinaryNode, ExpressionNode, ExpressionType, OperatorNode, SubscriptCallNode, UnaryNode, ValkyrieOperator};
use valkyrie_ast::{
ApplyCallNode, BinaryNode, ExpressionNode, ExpressionType, OperatorNode, SubscriptCallNode, UnaryNode, ValkyrieOperator,
};

impl ExpressionStatementNode {
pub fn build(&self, ctx: &ProgramContext) -> Validation<ExpressionNode> {
Expand Down Expand Up @@ -52,6 +54,7 @@ enum TokenStream {
Term(ExpressionType),
Postfix(OperatorNode),
Subscript(SubscriptCallNode),
Apply(ApplyCallNode),
}

impl<I> PrattParser<I> for ExpressionResolver
Expand All @@ -68,7 +71,7 @@ where
TokenStream::Infix(v) => Affix::Infix(v.kind.precedence(), v.kind.associativity()),
TokenStream::Term(_) => Affix::Nilfix,
TokenStream::Postfix(v) => Affix::Postfix(v.kind.precedence()),
TokenStream::Subscript(_) => Affix::Postfix(Precedence(u32::MAX)),
TokenStream::Apply(_) | TokenStream::Subscript(_) => Affix::Postfix(Precedence(10000)),
};
Ok(affix)
}
Expand Down Expand Up @@ -98,6 +101,7 @@ where
match op {
TokenStream::Postfix(v) => Ok(UnaryNode { operator: v, base: lhs }.into()),
TokenStream::Subscript(call) => Ok(call.with_base(lhs).into()),
TokenStream::Apply(call) => Ok(call.with_base(lhs).into()),
_ => unreachable!(),
}
}
Expand All @@ -117,6 +121,12 @@ impl MainPrefixNode {
"!" => ValkyrieOperator::Not,
"+" => ValkyrieOperator::Positive,
"-" => ValkyrieOperator::Negative,
"*" => ValkyrieOperator::Unbox,
"⅟" => ValkyrieOperator::Reciprocal,
"√" => ValkyrieOperator::Roots(2),
"∛" => ValkyrieOperator::Roots(3),
"∜" => ValkyrieOperator::Roots(4),

_ => unimplemented!("{} is not a valid prefix operator", self.text),
};
OperatorNode { kind: o, span: self.span.clone() }
Expand All @@ -129,11 +139,29 @@ impl MainInfixNode {
s if s.starts_with("is") => ValkyrieOperator::Is { negative: s.ends_with("not") },
s if s.ends_with("in") => ValkyrieOperator::In { negative: s.ends_with("not") },
"+" => ValkyrieOperator::Plus,
"-" => ValkyrieOperator::Minus,
"*" => ValkyrieOperator::Multiply,
"/" => ValkyrieOperator::Divide,
"%" => ValkyrieOperator::Remider,
"^" => ValkyrieOperator::Power,
_ => unimplemented!("{} is not a valid prefix operator", self.text),
"!=" => ValkyrieOperator::Equal { negative: true },
"==" => ValkyrieOperator::Equal { negative: false },
_ => unimplemented!("{} is not a valid infix operator", self.text),
};
OperatorNode { kind: o, span: self.span.clone() }
}
}

impl SuffixOperatorNode {
pub fn as_operator(&self) -> OperatorNode {
let o = match self.text.as_str() {
"!" => ValkyrieOperator::QuickRaise,
"℃" => ValkyrieOperator::Celsius,
"℉" => ValkyrieOperator::Fahrenheit,
"%" => ValkyrieOperator::DivideByDecimalPower(2),
"‰" => ValkyrieOperator::DivideByDecimalPower(3),
"‱" => ValkyrieOperator::DivideByDecimalPower(4),
_ => unimplemented!("{} is not a valid suffix operator", self.text),
};
OperatorNode { kind: o, span: self.span.clone() }
}
Expand All @@ -145,9 +173,7 @@ impl MainSuffixNode {
MainSuffixNode::InlineSuffix(v) => match v {
InlineSuffixNode::InlineSuffix0(v) => TokenStream::Postfix(v.as_operator()),
InlineSuffixNode::RangeCall(v) => TokenStream::Subscript(v.build(ctx)?),
InlineSuffixNode::TupleCall(v) => {
todo!()
}
InlineSuffixNode::TupleCall(v) => TokenStream::Apply(v.build(ctx)?),
},
};
Success { value: token, diagnostics: vec![] }
Expand All @@ -170,13 +196,3 @@ impl InlineSuffixNode {
// OperatorNode { kind: o, span: self.span.clone() }
}
}

impl SuffixOperatorNode {
pub fn as_operator(&self) -> OperatorNode {
let o = match self.text.as_str() {
"!" => ValkyrieOperator::QuickRaise,
_ => unimplemented!("{} is not a valid prefix operator", self.text),
};
OperatorNode { kind: o, span: self.span.clone() }
}
}
15 changes: 8 additions & 7 deletions projects/valkyrie-parser/src/statements/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::helpers::ProgramContext;
use nyar_error::{Failure, Success, Validation};
use valkyrie_ast::{ProgramRoot, StatementNode};
use valkyrie_ast::{NamespaceDeclaration, ProgramRoot, StatementNode};

mod namespace;
impl crate::ProgramNode {
pub fn build(&self, ctx: &ProgramContext) -> Validation<ProgramRoot> {
let mut errors = vec![];
Expand All @@ -24,7 +25,7 @@ impl crate::ProgramNode {

impl crate::StatementNode {
pub fn build(&self, ctx: &ProgramContext) -> Validation<StatementNode> {
match self {
let value = match self {
Self::DefineClass(_) => {
todo!()
}
Expand All @@ -37,19 +38,19 @@ impl crate::StatementNode {
Self::DefineImport(_) => {
todo!()
}
Self::DefineNamespace(_) => {
todo!()
}
Self::DefineNamespace(v) => v.build(ctx).into(),
Self::DefineTrait(_) => {
todo!()
}
Self::DefineUnion(_) => {
todo!()
}
Self::MainStatement(v) => v.build(ctx),
}
Self::MainStatement(v) => v.build(ctx)?,
};
Success { value, diagnostics: vec![] }
}
}

impl crate::MainStatementNode {
pub fn build(&self, ctx: &ProgramContext) -> Validation<StatementNode> {
match self {
Expand Down
17 changes: 17 additions & 0 deletions projects/valkyrie-parser/src/statements/namespace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use super::*;
use crate::OpNamespaceNode;
use valkyrie_ast::{NamePathNode, NamespaceKind};

impl crate::DefineNamespaceNode {
pub fn build(&self, ctx: &ProgramContext) -> NamespaceDeclaration {
let kind = match &self.op_namespace {
None => NamespaceKind::Unique,
Some(s) => match s {
OpNamespaceNode::Hide => NamespaceKind::Unique,
OpNamespaceNode::Main => NamespaceKind::Shared,
OpNamespaceNode::Test => NamespaceKind::Test,
},
};
NamespaceDeclaration { kind, path: self.namepath_free.build(ctx).names, span: self.span.clone() }
}
}
93 changes: 82 additions & 11 deletions projects/valkyrie-parser/tests/expression/apply.ron
Original file line number Diff line number Diff line change
@@ -1,11 +1,82 @@
(call/apply f (apply))
(call/apply f (apply 1))
(call/apply f (apply (k 1)))
(call/apply f (apply null (a 1) (⁑ args) (⁂ kwargs)))
(call/apply (call/apply (call/apply (call/apply f (apply)) (apply 1)) (apply 1 2)) (apply 1 2 3))
(call/apply-dot a (b))
(call/apply-dot a (b))
(call/apply-dot (call/apply-dot a (b)) (c))
(call/apply
(call/apply (call/apply-dot (call/apply (call/apply-dot (call/apply a (apply 1)) (b 1)) (apply 2)) (b 1)) (apply 2))
(apply 3))
ProgramRoot {
statements: [
ExpressionNode {
omit: true,
body: ApplyCallNode {
base: f,
monadic: false,
caller: None,
arguments: None,
span: 21..23,
},
span: 20..24,
},
ExpressionNode {
omit: true,
body: ApplyCallNode {
base: f,
monadic: false,
caller: None,
arguments: None,
span: 26..29,
},
span: 25..30,
},
ExpressionNode {
omit: true,
body: ApplyCallNode {
base: f,
monadic: false,
caller: None,
arguments: None,
span: 32..38,
},
span: 31..39,
},
ExpressionNode {
omit: false,
body: ApplyCallNode {
base: f,
monadic: false,
caller: None,
arguments: None,
span: 41..72,
},
span: 40..92,
},
ExpressionNode {
omit: true,
body: ApplyCallNode {
base: ApplyCallNode {
base: ApplyCallNode {
base: ApplyCallNode {
base: f,
monadic: false,
caller: None,
arguments: None,
span: 93..95,
},
monadic: false,
caller: None,
arguments: None,
span: 95..98,
},
monadic: false,
caller: None,
arguments: None,
span: 98..104,
},
monadic: false,
caller: None,
arguments: None,
span: 104..113,
},
span: 92..114,
},
ExpressionNode {
omit: false,
body: a,
span: 128..129,
},
],
}
25 changes: 25 additions & 0 deletions projects/valkyrie-parser/tests/expression/brackets.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ProgramRoot {
statements: [
ExpressionNode {
omit: false,
body: SubscriptCallNode {
kind: Ordinal,
base: ApplyCallNode {
base: a,
monadic: false,
caller: None,
arguments: None,
span: 1..4,
},
monadic: false,
terms: [
Index {
index: 2,
},
],
span: 4..7,
},
span: 0..7,
},
],
}
Loading

0 comments on commit 88eed2b

Please sign in to comment.