grammatica

Crates.iogrammatica
lib.rsgrammatica
version0.1.2
created_at2025-12-09 13:02:09.75599+00
updated_at2025-12-09 13:02:09.75599+00
descriptionRust library for representing and transforming formal grammars (Chomsky hierarchy today; extensible toward attribute, probabilistic, and specialized grammars).
homepagehttps://github.com/platinvm/grammatica
repositoryhttps://github.com/platinvm/grammatica
max_upload_size
id1975448
size63,973
(platinvm)

documentation

https://docs.rs/grammatica

README

Grammatica

Grammatica is a Rust library for representing and transforming formal grammars. It currently implements the full Chomsky hierarchy (regular, context-free, context-sensitive, unrestricted) and is designed to be extensible toward additional paradigms such as attribute grammars, probabilistic/stochastic grammars, L-systems, and domain‑specific rewriting systems.

Currently Implemented

  • Regular grammars (Type‑3)
  • Context-free grammars (Type‑2)
  • Context-sensitive grammars (Type‑1)
  • Unrestricted grammars (Type‑0)

Planned Extensions

  • Attribute grammars (semantic annotations)
  • Probabilistic / weighted production systems
  • Rewriting systems (Thue, string rewriting)
  • L‑systems and growth models

Goals

Core goals:

  • Provide immutable, validated grammar representations
  • Enable safe transformations between grammar classes
  • Offer introspection utilities (counts, symbol sets, structural checks)
  • Serve as a foundation for parsers, analyzers, and educational tooling

Example (sketch)

use std::collections::HashSet;
use grammatica::grammar::chomsky::{RegularGrammar, RegularProduction, RegularRhs};

let g = RegularGrammar::new(
	HashSet::from(["S".to_string()]),
	HashSet::from(['a', 'b']),
	"S".to_string(),
	vec![
		RegularProduction { lhs: "S".to_string(), rhs: RegularRhs::Terminal('b') },
		RegularProduction { lhs: "S".to_string(), rhs: RegularRhs::TerminalNonTerminal('a', "S".to_string()) },
	]
).unwrap();
println!("start: {} productions: {}", g.start_symbol(), g.productions().len());

Documentation

API docs will appear on docs.rs after the first successful publish.

License

Licensed under the MIT License. See LICENSE for details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work shall be licensed under MIT without additional terms or conditions.

Commit count: 0

cargo fmt