Skip to main content

Crate tabnas_c

Crate tabnas_c 

Source
Expand description

The C grammar plugin for the tabnas parsing engine.

Parses C23 source, plus the common GCC, Clang and MSVC extensions, into a CONCRETE syntax tree: every token, comment, macro definition, macro use and compiler extension is kept verbatim, so the tree can be walked back to the source it came from.

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let value = tabnas_c::parse("int x = 1;")?;
    assert_eq!(value.to_json()["kind"], "translation_unit");
    Ok(())
}

The plugin layers on the relaxed-JSON grammar of tabnas_jsonic (the DSL the grammar document is authored in) and on tabnas_expr for Pratt-style expression parsing, exactly as the canonical TypeScript plugin layers on @tabnas/jsonic and @tabnas/expr.

TypeScript is canonical: ts/src/c.ts defines behaviour, option names and defaults, and ts/c-grammar.jsonic defines the rule chain, embedded here as the same text. The shared fixtures in test/spec/*.tsv are the parity contract across TypeScript, Go and Rust.

Modules§

matchers
Focused lex matchers for the C parser. Each one does a single job and returns either a token or None, meaning “not my prefix”.

Structs§

CError
The error a failed parse produces, re-exported so callers need not depend on the engine crate directly.
CMeta
Names a parse should already know.
COptions
Plugin options. extended turns on the GCC, Clang and MSVC extension constructs and the legacy fallback that covers the long-tail declarator shapes; plain C23, the whole preprocessor included, is the default.
MacroDef
The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. A macro definition captured from a #define directive. Macros are not expanded: the table only says which names are macros, so a call site can be tagged.
MacroTable
The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable.
Scope
The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable.
SymbolTable
The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The classic identifier / typedef-name disambiguation table.

Enums§

Binding
The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. What a name is bound to in a scope. Ordinary bindings matter because an inner non-typedef declaration of a name hides an outer typedef.
ScopeKind
The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The kind of scope a binding was made in. Inner scopes shadow outer ones, and lookups walk the stack outward.
TagKind
The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. The symbol and macro tables, re-exported so a caller can seed a parse with names a header would have introduced. The canonical plugin exports the same pair from ts/src/symbols.ts, and the Go port exports them as SymbolTable and MacroTable. A struct, union or enum tag. Tags live in their own namespace in C.

Constants§

GRAMMAR_TEXT
The declarative grammar, the single source of truth for the rule shapes. ts/embed-grammar.js copies ts/c-grammar.jsonic here, as it copies it to go/c-grammar.jsonic for //go:embed.
META_KEY
The key meta carries the pre-bound names under, as the canonical plugin reads ctx.meta.cmeta and the Go port reads ctx.Meta["cmeta"].
PLUGIN_NAME
The plugin’s name, as use_plugin records it.
REALIZE_DEPTH_CAP
How deep realize will descend before it gives up.
VERSION
This crate’s version. It MUST equal ts/package.json “version”: the release orchestrator rewrites both, and tests/version_test.rs fails the build if they drift. Mirrors VERSION in ts/src/c.ts and const VERSION in go/c.go.

Functions§

c
Install the C grammar on a parser that already carries the jsonic base grammar.
make
A parser carrying the jsonic base grammar and the C grammar.
make_with
A parser built with the given plugin options.
parse
Parse C source with a shared default parser.
parse_with
Parse with a parser the caller built, realizing the tree into plain engine values.
parse_with_meta
Parse with names the source never declares itself: the typedef and macro names a header would have introduced.
plugin
The plugin, for use_plugin.
realize
Realize an arena handle into the plain engine value the caller sees. Values that are not handles pass through unchanged, so a tree that mixes CST nodes with engine values realizes correctly.