pub mod annotations;
pub mod argument;
pub mod call_apply;
pub mod call_dot;
pub mod call_subscript;
pub mod ctor;
mod dispatch;
pub mod lambda;
pub mod number;
pub mod operators;
pub mod parameter;
pub mod range;
pub mod string_template;
pub mod symbol;
pub mod tuple;
pub mod call_generic;
mod display;
use crate::{helper::ValkyrieNode, *};
use alloc::{
boxed::Box,
format,
string::{String, ToString},
vec,
vec::Vec,
};
use core::{
fmt::{Debug, Display, Formatter, Write},
num::{NonZeroU64, NonZeroUsize},
ops::Range,
};
use deriver::From;
#[cfg(feature = "lispify")]
use lispify::{Lisp, Lispify};
use nyar_error::{
third_party::{Associativity, Precedence},
FileID, FileSpan, NyarError, ReportKind, SyntaxError,
};
#[cfg(feature = "pretty-print")]
use pretty_print::{
helpers::{KAndRBracket, PrettySequence},
PrettyPrint, PrettyProvider, PrettyTree,
};
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExpressionNode {
pub omit: bool,
pub body: ExpressionKind,
pub span: Range<u32>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct TypingExpression {
pub body: ExpressionKind,
pub span: Range<u32>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExpressionContext {
pub type_level: bool,
pub allow_newline: bool,
pub allow_curly: bool,
}
#[derive(Clone, PartialEq, Eq, Hash, From)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ExpressionKind {
Placeholder,
Null(Box<NullNode>),
Boolean(Box<BooleanNode>),
Lambda(Box<LambdaNode>),
Slot(Box<LambdaSlotNode>),
Symbol(Box<NamePathNode>),
Number(Box<NumberLiteralNode>),
Text(Box<StringTextNode>),
String(Box<StringLiteralNode>),
Formatted(Box<FormatterNode>),
New(Box<ConstructNewNode>),
Object(Box<ConstructObjectNode>),
Unary(Box<UnaryNode>),
Infix(Box<BinaryNode>),
Tuple(Box<TupleNode>),
Array(Box<RangeNode>),
If(Box<IfStatement>),
IfLet(Box<GuardStatement>),
Switch(Box<SwitchStatement>),
Match(Box<MatchStatement>),
Try(Box<TryStatement>),
Procedural(Box<ProceduralNode>),
ApplyCall(Box<ApplyCallNode>),
ClosureCall(Box<ClosureCallNode>),
SubscriptCall(Box<SubscriptCallNode>),
GenericCall(Box<GenericCallNode>),
DotCall(Box<DotCallNode>),
DotMatchCall(Box<MatchCallNode>),
OutputReference(Box<OutputNode>),
}
impl Default for ExpressionContext {
fn default() -> Self {
ExpressionContext { type_level: false, allow_newline: true, allow_curly: false }
}
}
impl ExpressionContext {
pub fn in_type() -> Self {
ExpressionContext { type_level: true, allow_newline: true, allow_curly: false }
}
pub fn in_free() -> Self {
ExpressionContext { type_level: false, allow_newline: true, allow_curly: true }
}
pub fn in_repl() -> Self {
ExpressionContext { type_level: false, allow_newline: false, allow_curly: true }
}
}
impl TypingExpression {
#[allow(clippy::wrong_self_convention)]
pub fn as_normal(self) -> ExpressionNode {
ExpressionNode { omit: true, body: self.body, span: self.span }
}
}
impl ExpressionKind {
pub fn binary(o: OperatorNode, lhs: Self, rhs: Self) -> Self {
Self::Infix(Box::new(BinaryNode { infix: o, lhs, rhs }))
}
pub fn prefix(o: OperatorNode, rhs: Self) -> Self {
Self::Unary(Box::new(UnaryNode { operator: o, base: rhs }))
}
pub fn suffix(o: OperatorNode, lhs: Self) -> Self {
Self::Unary(Box::new(UnaryNode { operator: o, base: lhs }))
}
}