yog-script-analyze 0.1.0

Yog Script (.ys, .yns) analyzed: its lexer, parser and syntax tree, names resolved, the class index model — what the build and the editors read a source with.
Documentation
//! `const` — a value known when the mod is built.

use crate::ast::DeclKind;
use crate::parser::{PResult, Parser};
use crate::source::token::Punct;
use crate::words::{Role, Word};

pub static WORD: Word = Word {
    text: "const",
    doc: "A value known when the mod is built: `const PREFIX = \"g\"`. Numbers and texts players see belong in the mod's `.yres`.",
    reserved: true,
    roles: &[Role::Decl { starts: None, parse }],
};

fn parse(p: &mut Parser) -> PResult<DeclKind> {
    p.bump();
    let name = p.name("a constant")?;
    let ty = if p.eat(Punct::Colon) { Some(p.ty()?) } else { None };
    p.need(Punct::Eq)?;
    Ok(DeclKind::Const { name, ty, value: p.expr()? })
}