yog_script_analyze/words/
command.rs1use crate::ast::DeclKind;
4use crate::parser::{PResult, Parser};
5use crate::source::token::Tok;
6use crate::words::{Role, Word};
7
8pub static WORD: Word = Word {
9 text: "command",
10 doc: "A chat command: `command \"charge\" { server void Fill(Sender source, Player target = source.Player) \
11 requires source.IsOp { … } }`. Each method is a subcommand; its parameters are the arguments.",
12 reserved: false,
13 roles: &[Role::Decl { starts: Some(starts), parse }],
14};
15
16fn starts(p: &Parser) -> bool {
17 p.at_word(&WORD) && matches!(p.nth(1), Tok::Str(_))
18}
19
20fn parse(p: &mut Parser) -> PResult<DeclKind> {
21 p.bump();
22 let name = p.plain_string("a command's name")?;
23 Ok(DeclKind::Command { name, body: p.body()? })
24}