Begin implementing as expression
This commit is contained in:
parent
7be9300f14
commit
8ea6b4be81
12
dust-lang/src/abstract_tree/as.rs
Normal file
12
dust-lang/src/abstract_tree/as.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use super::{Expression, Type};
|
||||
|
||||
pub struct As {
|
||||
expression: Expression,
|
||||
r#type: Type,
|
||||
}
|
||||
|
||||
impl As {
|
||||
pub fn new(expression: Expression, r#type: Type) -> Self {
|
||||
Self { expression, r#type }
|
||||
}
|
||||
}
|
@ -5,12 +5,13 @@ use crate::{
|
||||
};
|
||||
|
||||
use super::{
|
||||
AbstractNode, Action, BuiltInFunctionCall, FunctionCall, ListIndex, Logic, MapIndex, Math,
|
||||
AbstractNode, Action, As, BuiltInFunctionCall, FunctionCall, ListIndex, Logic, MapIndex, Math,
|
||||
SourcePosition, Type, ValueNode, WithPosition,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
|
||||
pub enum Expression {
|
||||
As(WithPosition<Box<As>>),
|
||||
BuiltInFunctionCall(WithPosition<Box<BuiltInFunctionCall>>),
|
||||
FunctionCall(WithPosition<FunctionCall>),
|
||||
Identifier(WithPosition<Identifier>),
|
||||
@ -24,6 +25,7 @@ pub enum Expression {
|
||||
impl Expression {
|
||||
pub fn position(&self) -> SourcePosition {
|
||||
match self {
|
||||
Expression::As(inner) => inner.position,
|
||||
Expression::FunctionCall(inner) => inner.position,
|
||||
Expression::Identifier(inner) => inner.position,
|
||||
Expression::MapIndex(inner) => inner.position,
|
||||
@ -58,6 +60,7 @@ impl AbstractNode for Expression {
|
||||
Expression::BuiltInFunctionCall(built_in_function_call) => {
|
||||
built_in_function_call.item.expected_type(_context)
|
||||
}
|
||||
Expression::As(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
pub mod r#as;
|
||||
pub mod assignment;
|
||||
pub mod async_block;
|
||||
pub mod block;
|
||||
@ -32,6 +33,7 @@ pub use self::{
|
||||
logic::Logic,
|
||||
map_index::MapIndex,
|
||||
math::Math,
|
||||
r#as::As,
|
||||
r#loop::Loop,
|
||||
r#type::Type,
|
||||
r#while::While,
|
||||
|
@ -39,6 +39,7 @@ impl<'src> Display for Token<'src> {
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum Keyword {
|
||||
Any,
|
||||
As,
|
||||
Async,
|
||||
Bool,
|
||||
Break,
|
||||
@ -65,6 +66,7 @@ impl Display for Keyword {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Keyword::Any => write!(f, "any"),
|
||||
Keyword::As => write!(f, "as"),
|
||||
Keyword::Async => write!(f, "async"),
|
||||
Keyword::Bool => write!(f, "bool"),
|
||||
Keyword::Break => write!(f, "break"),
|
||||
@ -256,6 +258,7 @@ pub fn lexer<'src>() -> impl Parser<
|
||||
|
||||
let identifier_and_keyword = text::ident().map(|text: &str| match text {
|
||||
"any" => Token::Keyword(Keyword::Any),
|
||||
"as" => Token::Keyword(Keyword::As),
|
||||
"async" => Token::Keyword(Keyword::Async),
|
||||
"bool" => Token::Keyword(Keyword::Bool),
|
||||
"break" => Token::Keyword(Keyword::Break),
|
||||
|
@ -335,6 +335,12 @@ pub fn parser<'src>(
|
||||
just(Token::Control(Control::DoubleColon)),
|
||||
);
|
||||
|
||||
let r#as = expression
|
||||
.clone()
|
||||
.then_ignore(just(Token::Keyword(Keyword::As)))
|
||||
.then(r#type.clone())
|
||||
.map_with(|(expression, r#type), state| todo!());
|
||||
|
||||
let atom = choice((
|
||||
range.clone(),
|
||||
parsed_function.clone(),
|
||||
@ -507,6 +513,7 @@ pub fn parser<'src>(
|
||||
|
||||
choice((
|
||||
logic_math_indexes_and_function_calls,
|
||||
r#as,
|
||||
built_in_function_call,
|
||||
range,
|
||||
structure_instance,
|
||||
|
@ -11,7 +11,7 @@ while count <= 15 {
|
||||
} else if divides_by_5 {
|
||||
'buzz'
|
||||
} else {
|
||||
string.new(count)
|
||||
count as str
|
||||
}
|
||||
|
||||
io.write_line(output)
|
||||
|
Loading…
Reference in New Issue
Block a user