Skip to content

Commit 61f90c9

Browse files
committed
feat: parse function declarations + explicit types
1 parent 21bf78f commit 61f90c9

File tree

10 files changed

+182
-117
lines changed

10 files changed

+182
-117
lines changed

.idea/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/custom-language-rust.iml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.idea/discord.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/engine/src/lexer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ impl<'a> Lexer<'a> {
173173
_ if double!('&', '&') => And,
174174
_ if double!('|', '|') => Or,
175175

176-
'(' => LParam,
177-
')' => RParam,
176+
'(' => LParen,
177+
')' => RParen,
178178
'{' => LBracket,
179179
'}' => RBracket,
180180
',' => Comma,

packages/engine/src/lexer/tokens.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ pub enum LexerTokenKind {
8787

8888
// punctuation
8989
/// `(`
90-
LParam,
90+
LParen,
9191
/// `)`
92-
RParam,
92+
RParen,
9393
/// `{`
9494
LBracket,
9595
/// `}`

packages/engine/src/parser/ast.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ pub enum Expression {
1616
ShellCommand(Box<ShellCommand>),
1717
Identifier(Box<Identifier>),
1818
FunctionCall(Box<(Identifier, Vec<Expression>)>),
19-
If(Box<(Expression, Block, Option<Statement>)>),
19+
If(Box<(Expression, WithCursor<Block>, Option<Statement>)>),
2020
Match(Box<(Expression, Vec<(Expression, Expression)>)>),
21-
Empty,
2221
}
2322

2423

25-
2624
#[derive(lang_macro::EnumVariants, Debug, Clone, PartialEq, Eq)]
2725
pub enum Statement {
28-
While(Box<(WithCursor<Expression>, Block)>),
29-
For(Box<(Variable, WithCursor<Expression>, Block)>),
26+
While(Box<(WithCursor<Expression>, WithCursor<Block>)>),
27+
For(Box<(Variable, WithCursor<Expression>, WithCursor<Block>)>),
3028
Return(Box<Option<WithCursor<Expression>>>),
3129
Expression(Box<WithCursor<Expression>>),
3230
Continue,
@@ -168,12 +166,14 @@ impl TryFrom<LexerTokenKind> for AssignmentOperator {
168166
#[derive(Debug, Clone, PartialEq, Eq)]
169167
pub struct Function {
170168
pub name: String,
171-
pub parameters: Vec<Variable>,
172-
pub body: Block,
169+
pub parameters: Option<Vec<Variable>>,
170+
pub strict_type: Option<String>,
171+
pub body: WithCursor<Block>,
173172
}
174173

175174
#[derive(Debug, Clone, PartialEq, Eq)]
176175
pub struct Variable {
177-
pub name: Box<String>,
178-
pub value: Option<Box<WithCursor<Expression>>>,
176+
pub name: String,
177+
pub strict_type: Option<String>,
178+
pub value: Option<WithCursor<Expression>>,
179179
}

0 commit comments

Comments
 (0)