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.
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_
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.