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.
TranslationPart
One optional alchemy translation source and its explicit entry point.
TranslationParts
The package-local structural translation interface.

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_streaming
The parser a host streams a C document through: its rule passes, which C’s transducer part (alchemy/transduce.alc) reads, are make’s, alternate for alternate and token for token, it ends a document where make does, and it keeps nothing of a declaration it has closed.
make_streaming_with
The streaming parser built with the given plugin options.
make_with
A parser built with the given plugin options.
manifest_text
The plugin’s manifest, tabnas.plugin.json, as the repository carries it. Its translate object is what a host that translates reads: the shape the format is read as and written from (tree), the schema of that tree (c), the root the render needs (object), the file that holds the render, and the sentences that say what a written file does not keep. The crate embeds its own copy, translate/manifest.json, since a packaged crate holds nothing outside rs/; tests/translate_test.rs holds the copy to the file.
member
The member name of node, from its children: a node, an array of nodes for a list member, or None.
member_names
The member names a node of kind has.
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.
render_text
The render, alchemy/render.alc, the file the manifest’s translate.render names: a library of alchemy definitions, with no export, whose entry point c-render writes the reader’s tree’s events as C source that reads back as the same tree. A host links it with its own program. The crate embeds its own copy, translate/render.alc, held to the file as the manifest’s is.
translate
Return the translation parts of C source: the manifest, the render that writes the reader’s tree, a concrete syntax tree, back as C source that reads back as the same tree, and the transducer part, c-transduce, that makes the reader’s tree as JSON events from the grammar’s rule passes, for a host that reads parser events. There is no lift, and no embed: the tree is the reader’s own shape, the schema c, which a host renders only from a source of the same schema or from a program that builds the tree.