neural/rs/sigil/src/lib.rs

//! neural sigil — the surface syntax.
//!
//! Two jobs at slice-1: turn a line of text into a typed [`Sentence`], and
//! resolve a `word` to its [`Particle`] (a typed particle is a word; here we
//! mint the particle — its content identity — from the name). Everything a
//! neuron speaks enters the graph through this crate.

/// A particle id — a 32-byte content address (the same shape as `bbg::Particle`).
pub type Particle = [u8; 32];

/// A parsed neural sentence: `subject —relation→ object`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Sentence {
    pub subject: String,
    pub relation: String,
    pub object: String,
}

/// Why a line is not a well-formed sentence.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParseError {
    /// A slice-1 sentence is exactly three tokens; this had `found`.
    Arity { found: usize },
}

impl std::fmt::Display for ParseError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ParseError::Arity { found } => {
                write!(f, "expected 3 tokens (subject relation object), got {found}")
            }
        }
    }
}
impl std::error::Error for ParseError {}

/// Parse `"cat is-a animal"` into a [`Sentence`]. Slice-1 grammar: exactly three
/// whitespace-separated tokens — subject, relation, object. Richer grammar
/// (sigil-explicit `#cat ~is-a #animal`, multi-link chains) layers on later.
pub fn parse(input: &str) -> Result<Sentence, ParseError> {
    let toks: Vec<&str> = input.split_whitespace().collect();
    if toks.len() != 3 {
        return Err(ParseError::Arity { found: toks.len() });
    }
    Ok(Sentence {
        subject: toks[0].to_string(),
        relation: toks[1].to_string(),
        object: toks[2].to_string(),
    })
}

/// Resolve a word to its particle — the hemera hash of its name. Deterministic:
/// the same name is the same particle everywhere in the graph, so speaking a
/// word *merges* into the graph rather than minting a fresh node.
pub fn word_particle(name: &str) -> Particle {
    let h = cyber_hemera::hash(name.as_bytes());
    let b = h.as_bytes();
    let mut out = [0u8; 32];
    let n = b.len().min(32);
    out[..n].copy_from_slice(&b[..n]);
    out
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn parses_a_triple() {
        let s = parse("cat is-a animal").unwrap();
        assert_eq!(
            s,
            Sentence { subject: "cat".into(), relation: "is-a".into(), object: "animal".into() }
        );
    }

    #[test]
    fn word_is_deterministic_and_distinct() {
        assert_eq!(word_particle("cat"), word_particle("cat"));
        assert_ne!(word_particle("cat"), word_particle("animal"));
    }

    #[test]
    fn rejects_non_triples() {
        assert!(parse("cat animal").is_err());
        assert!(parse("a b c d").is_err());
    }
}

Homonyms

soft3/nox/rs/lib.rs
warriors/trisha/honeycrisp/lib.rs
soft3/strata/src/lib.rs
warriors/trisha/rs/lib.rs
cyb/optica/src/lib.rs
cyb/src-tauri/src/lib.rs
soft3/foculus/src/lib.rs
soft3/mudra/src/lib.rs
cyb/honeycrisp/src/lib.rs
soft3/glia/run/lib.rs
cyb/prysm/rs/lib.rs
soft3/lens/src/lib.rs
neural/trident/src/lib.rs
soft3/tru/rs/lib.rs
soft3/mir/src/lib.rs
warriors/trisha/wgpu/lib.rs
soft3/cybergraph/src/lib.rs
soft3/glia/import/lib.rs
soft3/hemera/rs/src/lib.rs
neural/rune/rs/lower/lib.rs
soft3/zheng/rs/src/lib.rs
soft3/radio/iroh-relay/src/lib.rs
soft3/radio/iroh-dns-server/src/lib.rs
soft3/strata/kuro/rs/lib.rs
neural/rune/rs/mold/lib.rs
soft3/radio/iroh-willow/src/lib.rs
soft3/lens/ikat/src/lib.rs
neural/rs/link/src/lib.rs
neural/rs/dialect/src/lib.rs
soft3/strata/core/src/lib.rs
soft3/radio/iroh-docs/src/lib.rs
soft3/strata/ext/src/lib.rs
soft3/radio/iroh-blobs/src/lib.rs
neural/rune/rs/parse/lib.rs
neural/rs/darwin-sys/src/lib.rs
neural/rs/macros/src/lib.rs
soft3/lens/brakedown/src/lib.rs
neural/rs/mir-format/src/lib.rs
soft3/strata/compute/src/lib.rs
cyb/honeycrisp/unimem/src/lib.rs
cyb/honeycrisp/rane/src/lib.rs
soft3/hemera/wgsl/src/lib.rs
neural/rs/codegen/src/lib.rs
soft3/radio/iroh-car/src/lib.rs
soft3/lens/porphyry/src/lib.rs
soft3/lens/binius/src/lib.rs
cyb/honeycrisp/acpu/src/lib.rs
neural/rune/rs/lex/lib.rs
soft3/radio/iroh-base/src/lib.rs
neural/eidos/rs/src/lib.rs
neural/rune/rs/prysm/lib.rs
soft3/radio/iroh-gossip/src/lib.rs
cyb/cyb/cyb-services/src/lib.rs
neural/rune/rs/interp/lib.rs
soft3/lens/assayer/src/lib.rs
soft3/bbg/rs/src/lib.rs
soft3/strata/nebu/rs/lib.rs
neural/rune/rs/ast/lib.rs
neural/rune/rs/parse-pure/lib.rs
soft3/lens/core/src/lib.rs
soft3/radio/iroh/src/lib.rs
cyb/honeycrisp/aruminium/src/lib.rs
neural/rune/rs/subject/lib.rs
neural/rs/core/src/lib.rs
soft3/radio/cyber-bao/src/lib.rs
soft3/strata/proof/src/lib.rs
soft3/radio/iroh-ffi/src/lib.rs
neural/rune/rs/compile/lib.rs
cyb/evy/crates/evy_dialect/src/lib.rs
neural/inf/rs/ast/src/lib.rs
cyb/wysm/crates/wasi/src/lib.rs
cyb/evy/crates/evy_platform_caps/src/lib.rs
cyb/wysm/crates/core/src/lib.rs
cyb/evy/forks/bevy_core_pipeline/src/lib.rs
neural/inf/rs/parse/src/lib.rs
cyb/evy/crates/evy_engine_tasks/src/lib.rs
neural/inf/rs/lower/src/lib.rs
soft3/radio/tests/integration/src/lib.rs
neural/inf/rs/plan/src/lib.rs
cyb/wysm/crates/collections/src/lib.rs
cyb/evy/forks/bevy_animation/src/lib.rs
neural/rs/tests/macro-integration/src/lib.rs
cyb/wysm/crates/c_api/src/lib.rs
cyb/evy/crates/evy_radio/src/lib.rs
cyb/evy/forks/bevy_tasks/src/lib.rs
cyb/evy/crates/evy_prysm_core/src/lib.rs
soft3/radio/iroh-ffi/iroh-js/src/lib.rs
soft3/strata/trop/rs/src/lib.rs
neural/inf/rs/value/src/lib.rs
cyb/evy/crates/evy_diagnostic/src/lib.rs
cyb/evy/forks/bevy_render/src/lib.rs
soft3/strata/jali/wgsl/src/lib.rs
soft3/strata/kuro/wgsl/src/lib.rs
neural/inf/rs/eval/src/lib.rs
cyb/wysm/crates/c_api/macro/lib.rs
cyb/evy/forks/bevy_post_process/src/lib.rs
cyb/evy/forks/bevy_image/src/lib.rs
soft3/strata/genies/rs/src/lib.rs
cyb/wysm/crates/wast/src/lib.rs
cyb/evy/forks/bevy_gizmos_render/src/lib.rs
cyb/evy/crates/evy_engine_dispatch/src/lib.rs
soft3/radio/iroh/bench/src/lib.rs
cyb/evy/forks/bevy_anti_alias/src/lib.rs
neural/inf/rs/source/src/lib.rs
neural/trident/editor/zed/src/lib.rs
cyb/evy/forks/bevy_sprite/src/lib.rs
cyb/wysm/crates/wasmi/src/lib.rs
cyb/evy/forks/bevy_mesh/src/lib.rs
cyb/evy/forks/bevy_pbr/src/lib.rs
neural/inf/rs/oracle/src/lib.rs
soft3/strata/nebu/wgsl/src/lib.rs
neural/inf/rs/lex/src/lib.rs
cyb/evy/forks/bevy_diagnostic/src/lib.rs
soft3/tape/impl/rust/src/lib.rs
cyb/evy/forks/bevy_transform/src/lib.rs
cyb/evy/forks/bevy_sprite_render/src/lib.rs
cyb/evy/forks/bevy_gizmos/src/lib.rs
cyb/evy/forks/bevy_ecs/src/lib.rs
cyb/evy/crates/evy_ecs_storage/src/lib.rs
soft3/strata/genies/wgsl/src/lib.rs
cyb/wysm/crates/c_api/artifact/lib.rs
cyb/evy/crates/evy_engine_core/src/lib.rs
cyb/evy/forks/naga/src/lib.rs
cyb/wysm/crates/fuzz/src/lib.rs
soft3/strata/jali/rs/src/lib.rs
soft3/strata/trop/wgsl/src/lib.rs
cyb/wysm/crates/ir/src/lib.rs
bootloader/go-cyber/cw/contracts/graph-filter/src/lib.rs
bootloader/go-cyber/cw/packages/cyber-std-test/src/lib.rs
bootloader/go-cyber/cw/packages/cyber-std/src/lib.rs
bootloader/go-cyber/cw/contracts/std-test/src/lib.rs

Graph