Skip to main content

Crate camxes_rs

Crate camxes_rs 

Source
Expand description

§camxes-rs: Lojban PEG Parser with Semantic Analysis

camxes-rs is a comprehensive Lojban parser that combines:

  • PEG Parser: Fast, zero-copy parsing with the integrated camxes module
  • Semantic Analysis: Full tersmu semantic engine for logical form generation
  • Morphology: Complete Lojban morphology validation
  • Multiple Outputs: Parse trees, logical forms, canonical Lojban, and semantic graphs

§Quick Start

§As a PEG Parser (camxes)

use camxes_rs::camxes::peg::grammar::Peg;
use camxes_rs::camxes::LOJBAN_GRAMMAR;

let (start_rule, grammar_text) = LOJBAN_GRAMMAR;
let parser = Peg::new(start_rule, grammar_text).expect("Failed to build parser");
let input = "mi klama le zarci";
let result = parser.parse(input);

// result.3 contains Result<Vec<ParseNode>, ParseError>
match result.3.as_ref() {
    Ok(nodes) => println!("Parse succeeded with {} nodes", nodes.len()),
    Err(err) => eprintln!("Parse failed at position {}", err.position),
}

§With Semantic Analysis

use camxes_rs::parse_lojban::parse_text;

let result = parse_text("mi klama le zarci");
match result {
    Ok(text) => {
        println!("Parsed successfully: {:?}", text);
        // text is a Text struct containing the semantic parse tree
    }
    Err(pos) => eprintln!("Parse error at position: {}", pos),
}

§Modules

§Features

  • Zero-copy parsing with span-based tokens
  • Rich error diagnostics with position tracking
  • WebAssembly support for browser usage
  • Thread-safe parser instances
  • Comprehensive test suite with golden examples

§API Compatibility Note

The embedded camxes module differs from the standalone camxes-rs 0.1.x in one way:

  • 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 diagnostics.

Modules§

bindful
Monad for binding values to numbered variables
camxes
A Parsing Expression Grammar (PEG) parser generator.
cli
CLI options matching Main.hs (System.Console.GetOpt).
eval_show
CLI eval/show bridge for semantic analysis from jbo_parse.
grammar_parity
Rule-name parity helpers between legacy Lojban.pappy and camxes-rs lojban.peg.
jbo_parse
Semantic analysis from JboSyntax to JboProp - COMPLETE PORT
jbo_prolog
Prolog output format for camxes-rs semantic propositions.
jbo_prop
Evaluation-layer types from JboProp.hs. Filled in as crate::eval grows.
jbo_show
Output formatting from JboShow.hs.
jbo_syntax
Abstract syntax from JboSyntax.hs (parse tree). Selbri/tag cycles use Box.
jbo_tree
Graph-based output from JboTree.hs.
logic
Proposition type from Logic.hs. Quantified formulas use higher-order abstract syntax in Haskell; Quantified is added when JboParse.hs is ported.
morphology
Word segmentation for the pipeline, matching Morph.hs interface (morph).
parse_lojban
Lojban surface parse — ports ParseText.parseText.
parse_m
Parse state monad for semantic analysis
parse_m_helpers
Helper functions for ParseM
run
Main loop: Main.hs doParse, mangleInput, parseLineToResult, jsonOneLine.
util
Utility functions from Util.hs