[fine] While loops, nothing
This commit is contained in:
parent
1cc5ce6ca9
commit
ac3c158a81
7 changed files with 166 additions and 48 deletions
|
|
@ -143,10 +143,14 @@ pub enum TreeKind {
|
|||
ListConstructor,
|
||||
ListConstructorElement,
|
||||
LiteralExpression,
|
||||
MatchArm,
|
||||
MatchBody,
|
||||
MatchExpression,
|
||||
MemberAccess,
|
||||
NewObjectExpression,
|
||||
ParamList,
|
||||
Parameter,
|
||||
Pattern,
|
||||
ReturnStatement,
|
||||
ReturnType,
|
||||
SelfParameter,
|
||||
|
|
@ -156,13 +160,8 @@ pub enum TreeKind {
|
|||
TypeParameter,
|
||||
TypeParameterList,
|
||||
UnaryExpression,
|
||||
|
||||
Pattern,
|
||||
VariableBinding,
|
||||
|
||||
MatchExpression,
|
||||
MatchBody,
|
||||
MatchArm,
|
||||
WhileStatement,
|
||||
WildcardPattern,
|
||||
}
|
||||
|
||||
|
|
@ -781,6 +780,7 @@ const STATEMENT_RECOVERY: &[TokenKind] = &[
|
|||
TokenKind::Return,
|
||||
TokenKind::For,
|
||||
TokenKind::Class,
|
||||
TokenKind::While,
|
||||
];
|
||||
|
||||
fn block(p: &mut CParser) {
|
||||
|
|
@ -813,6 +813,8 @@ fn statement(p: &mut CParser) -> bool {
|
|||
// require a semicolon at the end if it's all by itself.
|
||||
TokenKind::If => statement_if(p),
|
||||
|
||||
TokenKind::While => statement_while(p),
|
||||
|
||||
_ => {
|
||||
if p.at(TokenKind::Semicolon) || p.at_any(EXPRESSION_FIRST) {
|
||||
statement_expression(p)
|
||||
|
|
@ -834,6 +836,24 @@ fn statement_if(p: &mut CParser) {
|
|||
p.end(m, TreeKind::IfStatement);
|
||||
}
|
||||
|
||||
fn statement_while(p: &mut CParser) {
|
||||
let m = p.start();
|
||||
|
||||
p.expect_start(TokenKind::While);
|
||||
if p.at_any(EXPRESSION_FIRST) {
|
||||
expression(p);
|
||||
} else {
|
||||
p.error("expected an expression for the loop condition");
|
||||
}
|
||||
if p.at(TokenKind::LeftBrace) {
|
||||
block(p);
|
||||
} else {
|
||||
p.error("expected a block for the loop body");
|
||||
}
|
||||
|
||||
p.end(m, TreeKind::WhileStatement);
|
||||
}
|
||||
|
||||
fn statement_let(p: &mut CParser) {
|
||||
let m = p.start();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue