camxes-rs
A comprehensive Lojban parser combining fast PEG parsing with semantic analysis capabilities.
camxes-rs provides both low-level parsing (via the integrated camxes PEG parser) and high-level semantic analysis (via the tersmu semantic engine). Use it as a standalone parser library or as a complete semantic analyzer.
Features
- Fast PEG Parser: Zero-copy parsing with span-based tokens
- Semantic Analysis: Converts Lojban to logical forms and canonical representations
- Rich Error Diagnostics: Position tracking and detailed error messages
- WebAssembly Support: Runs in browsers via WASM
- Thread-Safe: Create parser instances per thread for concurrent usage
- Comprehensive Testing: Validated against extensive golden examples
Installation
Add to your Cargo.toml:
[]
= "1.0"
Quick Start
As a PEG Parser
Use the integrated camxes module for fast, low-level parsing:
use Peg;
use LOJBAN_GRAMMAR;
With Semantic Analysis
Use the high-level API for logical forms and canonical output:
use parse_text;
Command-Line Tool
The crate includes a camxes binary for command-line usage:
# Install
# Parse a file (one sentence per line)
# Parse from stdin
|
# Output JSON
|
# Logical form only
|
# Canonical Lojban only
|
Logging
Enable debug output with the RUST_LOG environment variable:
# All debug logs
RUST_LOG=debug
# Only camxes-rs logs
RUST_LOG=camxes_rs=debug
# Specific module logs
RUST_LOG=camxes_rs::morphology=debug,camxes_rs::parse_lojban=trace
API Examples
Token Extraction
Extract tokens with text spans:
use Peg;
use ;
use LOJBAN_GRAMMAR;
Custom Grammar Rules
Parse specific syntactic constructs:
use Peg;
use LOJBAN_GRAMMAR;
// Parse only a word (morphology level)
let = LOJBAN_GRAMMAR;
let word_parser = new?;
let result = word_parser.parse;
// Parse a specific construct
let sumti_parser = new?;
let result = sumti_parser.parse;
Multi-threaded Usage
For web servers or concurrent applications:
use HashMap;
use Arc;
use Peg;
use LOJBAN_GRAMMAR;
// In server initialization
let grammar_texts: = new;
// In each worker thread
let mut parsers = new;
for in grammar_texts.iter
// Use the parser
if let Some = parsers.get
API Compatibility Note
Important: The embedded camxes module differs from the standalone camxes-rs 0.1.x:
- 0.1.x:
ParseResult(cost, position, result)- result at index 2 - 1.0.0+:
ParseResult(cost, position, error_position, result)- result at index 3
The 1.0.0+ version adds an explicit error position field for better error diagnostics. When migrating from 0.1.x, change result.2 to result.3 to access the parse result.
WebAssembly
Build for WASM:
See the web-app directory for a complete browser example.
Development
Build
Test
# Run all tests
# Run focused camxes tests
# Build examples
# Run benchmarks
Project Structure
rust/
Cargo.toml
src/
lib.rs # Crate root with documentation
main.rs # CLI entry point
camxes/ # Integrated PEG parser
grammar/lojban.peg # Embedded Lojban grammar
peg/ # PEG parser engine
parse_lojban.rs # High-level semantic API
morphology.rs # Morphology validation
jbo_*.rs # Semantic analysis modules
examples/ # Usage examples
tests/ # Integration tests
benches/ # Performance benchmarks
web-app/ # WASM browser application
Modules
camxes: PEG parser with embedded Lojban grammarparse_lojban: High-level semantic parsing APImorphology: Lojban morphology validationjbo_tree,jbo_syntax,jbo_prop: Semantic tree structuresjbo_show: Output formatting (logical forms, canonical Lojban)jbo_parse: Parse tree to semantic tree conversionrun: CLI orchestration and JSON output
Documentation
- API Documentation - Full API reference
- Repository - Source code and examples
- Lojban.org - Official Lojban website
License
GPL-3.0 - See LICENSE for details.
Acknowledgments
This crate combines:
- camxes: PEG parser originally developed as a standalone crate
- tersmu: Semantic analysis engine (Rust port of the Haskell implementation)
Both are now integrated into a single, comprehensive Lojban parsing library.