yog_script_analyze/words/while.rs
1//! `while` — again while a condition holds.
2
3use crate::ast::Stmt;
4use crate::parser::{PResult, Parser};
5use crate::words::{Role, Word};
6
7pub static WORD: Word = Word {
8 text: "while",
9 doc: "Runs a statement again while a condition holds: `while (queue.Count > 0) { … }`.",
10 reserved: true,
11 roles: &[Role::Stmt { parse }],
12};
13
14fn parse(p: &mut Parser) -> PResult<Stmt> {
15 p.bump();
16 let cond = p.paren_cond()?;
17 let body = Box::new(p.stmt()?);
18 Ok(Stmt::While { cond, body })
19}