Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.
src/parse.x
X2c recursive-descent parser core.
Functions
| Function | Summary |
|---|---|
Compiler.bind_syntax | Binds parser-shaped syntax at context into current compiler state. |
Compiler.bind_template_local | Installs a definition-local template binding or typedef provisionally. |
Compiler.defines_main | Reports whether the unit’s tokens define a function named main at file scope. |
Compiler.finish_foreign_alias | Constructs a foreign alias from one direct function declaration and target. |
Compiler.finish_managed_declaration | Lowers managed block declarations to declaration/defer pairs in source order, preserving their installed bindings and the enclosing lifetime. |
Compiler.meta_form_is_definition | Reports whether the current tokens begin a meta function declaration. |
Compiler.package_alias_spelling | Returns the folded package-member spelling at the current token, or NULL. |
Compiler.parse_basic_identifier | Consumes one ident token and returns its spelling as a one-item List. |
Compiler.parse_complex_identifier | Parses the current identifier or dotted owner/member as a one-item name. |
Compiler.parse_declaration_argument | Parses one non-function, non-typedef Decl macro argument. |
Compiler.parse_declaration_row | Parses one x2c declaration row and leaves its terminator current. |
Compiler.parse_enumerator | Parses one enumerator for enum type context and returns its AST. |
Compiler.parse_enumerators | Parses comma-separated enumerators up to the current closing brace. |
Compiler.parse_field | Parses one field for aggregate type context and returns its AST. |
Compiler.parse_fields | Parses aggregate fields in source order up to the current closing brace. |
Compiler.parse_function_definition | Parses one function declaration and its required compound body. |
Compiler.parse_function_target | Parses one function decorator target and returns its resulting AST. |
Compiler.parse_import_declaration | Parses and registers one import declaration, including its semicolon. |
Compiler.parse_named_type | Captures a name followed by an ordinary complete type and semicolon. |
Compiler.parse_optional_identifier | Consumes and returns the current identifier, or NULL without consuming. |
Compiler.parse_parameter | Parses one parameter and returns (param TYPE DECLARATOR) or (...). |
Compiler.parse_parameter_list | Parses a nonempty comma-separated parameter List in source order. |
Compiler.parse_simple_declaration | Parses one declaration group and leaves its terminating token current. |
Compiler.parse_static_assert | Parses a C assertion declaration; native C owns constant-expression checks. |
Compiler.parse_top_level | Parses one top-level form and applies its source-ordered compiler effects. |
Compiler.parse_type_name | Parses a type specifier with qualifiers and pointer/reference modifiers. |
Compiler.script_statement_executes | Reports whether the top-level item at the cursor is a script statement that runs, rather than a declaration: an expression, control flow, a with block, or a statement macro. |
Compiler.script_statement_starts | Reports whether the top-level item at the cursor is one of a script unit’s statements, which become main’s body. |
Compiler.skip_linkage_brace | Consumes one brace of a C linkage specification at file scope and reports whether it did. |
Compiler.test_declaration | Tests whether the current token can begin a declaration without consuming. |
Compiler.test_static_assert | Reports whether the current identifier starts a C static assertion. |
Compiler
Compiler.bind_syntax
List Compiler.bind_syntax( Compiler c, Var syntax, AstPos context, Type return_type)
Binds parser-shaped syntax at context into current compiler state.
The input must evaluate to a nonempty AST List valid for the requested
AstPos. Bindings, types, scopes, and expressions are resolved in source
order; return_type applies only while descendants are bound. This method
mutates Sym and does not open a semantic transaction.
Source: src/parse.x:2085
Compiler.bind_template_local
void Compiler.bind_template_local( Compiler c, List key, List type, List context)
Installs a definition-local template binding or typedef provisionally.
Source: src/parse.x:972
Compiler.defines_main
int Compiler.defines_main(Compiler c)
Reports whether the unit’s tokens define a function named main at file
scope. A script unit that does is an ordinary program: its declarations
stay at file scope and it may not have top-level statements. Both parse
passes read the same tokens, so they agree before either parses.
Source: src/parse.x:1620
Compiler.finish_foreign_alias
List Compiler.finish_foreign_alias( Compiler c, List declaration, List native_syntax)
Constructs a foreign alias from one direct function declaration and target.
native_syntax must resolve to a different direct identifier and, when
typed, a function. Storage is limited to static or inline, when
present, and variadic parameters are rejected.
Source: src/parse.x:2019
Compiler.finish_managed_declaration
List Compiler.finish_managed_declaration( Compiler c, List declaration, Token origin)
Lowers managed block declarations to declaration/defer pairs in source order, preserving their installed bindings and the enclosing lifetime.
Source: src/parse.x:1341
Compiler.meta_form_is_definition
int Compiler.meta_form_is_definition(Compiler c)
Reports whether the current tokens begin a meta function declaration.
meta is contextual: it marks a function the compiler runs at compile
time as well as emits, and stays an ordinary identifier wherever the
tokens after it do not declare or define a function. This query does not
consume tokens.
Source: src/parse.x:1674
Compiler.package_alias_spelling
String Compiler.package_alias_spelling(Compiler c)
Returns the folded package-member spelling at the current token, or NULL.
The token must be an unshadowed imported alias followed by . and an
identifier. This lookahead does not consume tokens.
Source: src/parse.x:30
Compiler.parse_basic_identifier
List Compiler.parse_basic_identifier(Compiler compiler)
Consumes one ident token and returns its spelling as a one-item List.
Source: src/parse.x:108
Compiler.parse_complex_identifier
List Compiler.parse_complex_identifier(Compiler compiler)
Parses the current identifier or dotted owner/member as a one-item name.
Package aliases and imported method spellings are folded through the
current Sym, and all accepted tokens are consumed.
Source: src/parse.x:103
Compiler.parse_declaration_argument
List Compiler.parse_declaration_argument(Compiler c)
Parses one non-function, non-typedef Decl macro argument.
Returns a single declaration without consuming the invocation delimiter;
flat destructuring may omit an initializer in this position.
Source: src/parse.x:1504
Compiler.parse_declaration_row
List Compiler.parse_declaration_row(Compiler compiler)
Parses one x2c declaration row and leaves its terminator current.
A mixed-type comma row returns a seq of declarations in source order;
a single declaration returns directly.
Source: src/parse.x:1253
Compiler.parse_enumerator
List Compiler.parse_enumerator(Compiler c, Type context)
Parses one enumerator for enum type context and returns its AST.
Outside macro-template parsing, its binding is published immediately so
later initializers and enumerators can resolve it.
Source: src/parse.x:573
Compiler.parse_enumerators
List Compiler.parse_enumerators(Compiler c, List context)
Parses comma-separated enumerators up to the current closing brace.
Returns their flat source-order List and leaves the brace unconsumed.
Source: src/parse.x:621
Compiler.parse_field
List Compiler.parse_field(Compiler compiler, List context)
Parses one field for aggregate type context and returns its AST.
Ordinary fields publish their binding in the aggregate’s field scope and
consume their terminating semicolon; macro forms follow their own syntax.
Source: src/parse.x:478
Compiler.parse_fields
List Compiler.parse_fields(Compiler c, List context)
Parses aggregate fields in source order up to the current closing brace.
Returns a flat field List, publishes delegate-field metadata, and leaves
the closing brace unconsumed.
Source: src/parse.x:496
Compiler.parse_function_definition
List Compiler.parse_function_definition(Compiler compiler)
Parses one function declaration and its required compound body. The parameter bindings are active while the body is parsed, and the first token after the closing brace remains current.
Source: src/parse.x:1527
Compiler.parse_function_target
List Compiler.parse_function_target(Compiler compiler)
Parses one function decorator target and returns its resulting AST. A compatible unit macro at the current token is expanded first; otherwise an ordinary function definition is required.
Source: src/parse.x:1540
Compiler.parse_import_declaration
List Compiler.parse_import_declaration(Compiler c)
Parses and registers one import declaration, including its semicolon.
The alias defaults to the package name; with members add source-ordered
local spellings. These spellings affect source resolution only; the package
name in the returned AST drives the generated header include.
Source: src/parse.x:1585
Compiler.parse_named_type
List Compiler.parse_named_type(Compiler c)
Captures a name followed by an ordinary complete type and semicolon. The reserved typedef identity permits fields to refer to their enclosing named type before its pointer or value representation is complete.
Source: src/parse.x:926
Compiler.parse_optional_identifier
List Compiler.parse_optional_identifier(Compiler compiler)
Consumes and returns the current identifier, or NULL without consuming.
Source: src/parse.x:115
Compiler.parse_parameter
List Compiler.parse_parameter(Compiler compiler)
Parses one parameter and returns (param TYPE DECLARATOR) or (...).
Outside macro-template parsing, a named parameter is installed in the
current Sym scope. The following delimiter remains current.
Source: src/parse.x:759
Compiler.parse_parameter_list
List Compiler.parse_parameter_list(Compiler c)
Parses a nonempty comma-separated parameter List in source order.
The caller owns the parameter scope; the first non-comma delimiter remains
current.
Source: src/parse.x:774
Compiler.parse_simple_declaration
List Compiler.parse_simple_declaration(Compiler c)
Parses one declaration group and leaves its terminating token current.
Declared names are installed in Sym as their declarators are completed;
the result is one declare, typedef, or initialized dstrdecl AST.
Source: src/parse.x:1237
Compiler.parse_static_assert
List Compiler.parse_static_assert(Compiler compiler)
Parses a C assertion declaration; native C owns constant-expression checks.
Source: src/parse.x:458
Compiler.parse_top_level
List Compiler.parse_top_level(Compiler c)
Parses one top-level form and applies its source-ordered compiler effects.
Returns its AST, or NULL when a keyword definition, top-level Lisp form,
linkage brace, or compile-time-only meta function only updates compiler
state, with the first following token current. A macro import whose
.xmacro declares meta functions retains their runtime definitions,
which the unit emits where it reaches them.
Source: src/parse.x:1751
Compiler.parse_type_name
Type Compiler.parse_type_name(Compiler compiler)
Parses a type specifier with qualifiers and pointer/reference modifiers.
Returns its flat Type AST and leaves the first following token current.
Source: src/parse.x:682
Compiler.script_statement_executes
int Compiler.script_statement_executes(Compiler c)
Reports whether the top-level item at the cursor is a script statement
that runs, rather than a declaration: an expression, control flow, a
with block, or a statement macro. This query does not consume tokens.
Source: src/parse.x:1708
Compiler.script_statement_starts
int Compiler.script_statement_starts(Compiler c)
Reports whether the top-level item at the cursor is one of a script
unit’s statements, which become main’s body.
Preprocessor lines, imports, protocols, compile-time definitions and
Lisp, file-scope macro invocations, typedef, static, and extern
declarations, linkage braces, type definitions, and function prototypes
and definitions stay at file scope. This query does not consume tokens.
Source: src/parse.x:1690
Compiler.skip_linkage_brace
int Compiler.skip_linkage_brace(Compiler c)
Consumes one brace of a C linkage specification at file scope and reports
whether it did. extern "C" { opens a group; a } at file scope closes
the innermost open group, because every other file-scope form consumes
its own braces. The declarations between them stay at file scope. The
#ifdef __cplusplus arm of the usual header guard is skipped, so only an
unguarded group reaches this operation.
Source: src/parse.x:1719
Compiler.test_declaration
int Compiler.test_declaration(Compiler c)
Tests whether the current token can begin a declaration without consuming. Typedefs, package aliases, and macro-hole kinds are resolved through the current compiler state.
Source: src/parse.x:1231
Compiler.test_static_assert
int Compiler.test_static_assert(Compiler compiler)
Reports whether the current identifier starts a C static assertion.
Source: src/parse.x:452
Design notes
Converts token streams into AST nodes for declarations and top-level constructs. Expression, statement, and literal parsing are in their own modules and are invoked via the Compiler.* entry points.
Declaration parsing recognizes initializers and finds the function body. Type resolution and lexical scopes use the Compiler’s current symbol environment; failures retain positioned diagnostic context.