Languages

CMParser

Parse Microcosm source and expressions into Catalyst syntax trees.

C++23 mc/CMParser.h
#include <mc/CMParser.h>

Parsing builds a cvar AST and does not execute it. Token information belongs to the parser and may change on the next parse.

Jump to a declaration · 12

CMParser

class CMParser

Types, constants & data

using Tokens = CVector<CToken>;

Methods

CMParser

CMParser();
CMParser(const CMParser&) = delete;

Creates a reusable Microcosm parser with its own token storage. Each parse replaces the previous tokenization.

setFileId

void setFileId(uint16_t fileId);

Assigns the file identifier attached to parsed source locations.

discardComments

void discardComments(bool flag);

Controls whether comments are omitted from the syntax tree; the default is true. Set false to retain comment nodes for source tools; the interpreter treats those nodes as no-ops.

parse

cvar parse(const char* code);
cvar parse(const cstr& code);

Parses a complete Microcosm source string into a cvar syntax tree without executing it. Malformed source throws CParseError.

parseFile

cvar parseFile(const cstr& path);

Reads and parses a Microcosm source file, returning its syntax tree. File-loading errors and source-location parse errors are reported to the caller.

parseExpr

cvar parseExpr(const cstr& code);

Parses one expression without executing it. Returns the expression’s cvar syntax tree and rejects additional statements.

tokens

Tokens& tokens();

Borrows the token list from the most recent parse for tasks such as syntax highlighting. A later parse replaces its contents; the parser must outlive the reference.

format

static cstr format(const cstr& code);

Formats source text using the language’s formatter.