[fine] Assignments!

And new error capabilities!
This commit is contained in:
John Doty 2024-01-19 19:08:17 -08:00
parent 92cf840766
commit f20f5a5e03
12 changed files with 400 additions and 64 deletions

View file

@ -119,30 +119,32 @@ impl<'a> std::ops::IndexMut<TreeRef> for SyntaxTree<'a> {
#[derive(Debug, Eq, PartialEq)]
pub enum TreeKind {
Error,
File,
FunctionDecl,
ParamList,
Parameter,
TypeExpression,
Block,
LetStatement,
ReturnStatement,
ExpressionStatement,
LiteralExpression,
GroupingExpression,
UnaryExpression,
ConditionalExpression,
CallExpression,
ArgumentList,
Argument,
ArgumentList,
BinaryExpression,
IfStatement,
Block,
CallExpression,
ConditionalExpression,
ExpressionStatement,
File,
ForStatement,
FunctionDecl,
GroupingExpression,
Identifier,
ReturnType,
TypeParameterList,
TypeParameter,
IfStatement,
LetStatement,
ListConstructor,
ListConstructorElement,
LiteralExpression,
ParamList,
Parameter,
ReturnStatement,
ReturnType,
TypeExpression,
TypeParameter,
TypeParameterList,
UnaryExpression,
}
pub struct Tree<'a> {
@ -628,6 +630,7 @@ fn statement(p: &mut CParser) {
TokenKind::LeftBrace => block(p),
TokenKind::Let => statement_let(p),
TokenKind::Return => statement_return(p),
TokenKind::For => statement_for(p),
// NOTE: Technically 'if' is an expression, but `if` doesn't
// require a semicolon at the end if it's all by itself.
@ -677,6 +680,22 @@ fn statement_return(p: &mut CParser) {
p.end(m, TreeKind::ReturnStatement);
}
fn statement_for(p: &mut CParser) {
assert!(p.at(TokenKind::For));
let m = p.start();
p.expect(TokenKind::For, "expect a for to start a for loop");
p.expect(
TokenKind::Identifier,
"expected an identifier for the loop variable",
);
p.expect(TokenKind::In, "expect an 'in' after the loop variable");
expression(p);
block(p);
p.end(m, TreeKind::ForStatement);
}
fn statement_expression(p: &mut CParser) {
let m = p.start();