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.
extendedturns 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. - Macro
Def - 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 asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. A macro definition captured from a#definedirective. Macros are not expanded: the table only says which names are macros, so a call site can be tagged. - Macro
Table - 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 asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. - 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 asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. - Symbol
Table - 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 asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. The classic identifier / typedef-name disambiguation table. - Translation
Part - One optional alchemy translation source and its explicit entry point.
- Translation
Parts - 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 asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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. - Scope
Kind - 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 asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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 asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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 fromts/src/symbols.ts, and the Go port exports them asSymbolTableandMacroTable. 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.jscopiests/c-grammar.jsonichere, as it copies it togo/c-grammar.jsonicfor//go:embed. - META_
KEY - The key
metacarries the pre-bound names under, as the canonical plugin readsctx.meta.cmetaand the Go port readsctx.Meta["cmeta"]. - PLUGIN_
NAME - The plugin’s name, as
use_pluginrecords it. - REALIZE_
DEPTH_ CAP - How deep
realizewill descend before it gives up. - VERSION
- This crate’s version. It MUST equal
ts/package.json“version”: the release orchestrator rewrites both, andtests/version_test.rsfails the build if they drift. MirrorsVERSIONints/src/c.tsandconst VERSIONingo/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, aremake’s, alternate for alternate and token for token, it ends a document wheremakedoes, 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. Itstranslateobject 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 outsiders/;tests/translate_test.rsholds the copy to the file. - member
- The member
nameofnode, from its children: a node, an array of nodes for a list member, orNone. - member_
names - The member names a node of
kindhas. - 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’stranslate.rendernames: a library of alchemy definitions, with noexport, whose entry pointc-renderwrites 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 schemac, which a host renders only from a source of the same schema or from a program that builds the tree.