Languages

CCParser

Parse Cosmic source and expressions into Catalyst syntax trees.

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

parse() and parseFile() handle translation units; parseExpr() handles a single expression. The result is an AST represented by cvar and cfunc.

Cosmic’s whitespace rules and language additions apply. A parser API is not a promise that arbitrary standard C++ formatting is accepted.

Jump to a declaration · 12

CCParser

class CCParser

Types, constants & data

using Tokens = CVector<CToken>;

Methods

CCParser

CCParser();
CCParser(const CCParser&) = delete;

Creates a reusable Cosmic 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.

setLineComments

void setLineComments(bool flag);

Enables reading numeric source-line annotations from comments such as // 42 instead of assigning ordinary parsed line metadata. Disabled by default; this controls source-location reconstruction rather than general comment preservation.

parse

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

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

parseFile

cvar parseFile(const cstr& path);

Reads and parses a Cosmic 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.