Crates.io | pgf2json |
lib.rs | pgf2json |
version | 0.2.5 |
created_at | 2025-09-08 13:46:25.739216+00 |
updated_at | 2025-09-14 21:04:02.572121+00 |
description | This crate is an Application Programming Interface to load and interpret grammars compiled in Portable Grammar Format (PGF). The PGF format is produced as a final output from the GF compiler. The library provides methods for generating JSON output of a correctly formed PGF file. The API is meant to be used for embedding GF grammars in Rust programs. |
homepage | https://github.com/CryptoPatrick/pgf2json |
repository | https://github.com/CryptoPatrick/pgf2json |
max_upload_size | |
id | 1829315 |
size | 619,962 |
A Rust library for parsing Portable Grammar Format (PGF) files and converting them to JSON. This crate provides an API to load and interpret grammars compiled in Portable Grammar Format (PGF), which is the final output format from the Grammatical Framework (GF) compiler.
The library enables embedding GF grammars in Rust programs. The current implementation is sensitive to PGF versioning; stable for 1.0 and experimental support for the yanked (upcoming?) version 2.1 .
There seems to be a minor format difference between PGF 1.0 and 2.1 that needs addressing (see more below), but the core parser architecture is solid.
pgf2json contains a complete PGF binary parser, covering all of the PGF v1.0 format specifications. The libraries strength include:
Pretty simple, just load a .pgf
files and convert it to .json
.
use pgf2json::{read_pgf, pgf_to_json, parse, language, types};
// Load a PGF file
let pgf = read_pgf("./grammars/Food.pgf")?;
// Convert to JSON
let json = pgf_to_json(&pgf)?;
// Parse a sentence
let lang = language::read_language("FoodEng").unwrap();
let typ = types::start_cat(&pgf);
let trees = parse(&pgf, &lang, &typ, "this pizza is delicious")?;
The test suite includes parsing real PGF files and validating JSON output structure.
cargo test
The parser supports both PGF 1.0 and PGF 2.1 formats with their different string encoding approaches:
The current implementation includes robust string parsing that:
is_pgf_2_1
flagAll tests including test_real_pgf_parsing
now pass, confirming correct parsing of strings across all supported formats.