[core] API: scaena-core public API (canon, claims, hooks), bodies pending
This commit is contained in:
Generated
+413
@@ -0,0 +1,413 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3"
|
||||
dependencies = [
|
||||
"bit-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi 5.3.0",
|
||||
"wasip2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi 6.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.191"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proptest"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"bit-vec",
|
||||
"bitflags",
|
||||
"num-traits",
|
||||
"rand",
|
||||
"rand_chacha",
|
||||
"rand_xorshift",
|
||||
"regex-syntax",
|
||||
"rusty-fork",
|
||||
"tempfile",
|
||||
"unarray",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "5.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41"
|
||||
dependencies = [
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
|
||||
dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_xorshift"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rusty-fork"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"quick-error",
|
||||
"tempfile",
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scaena-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proptest",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.4.3",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unarray"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.13.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasip2"
|
||||
version = "1.0.1+wasi-0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
|
||||
dependencies = [
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed43f3060383c64b000f3c630550aebdfa9d3b76d48de32390483dd2cc7e0865"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5cbd820fe3e35fb38c83b6dc7e6b1618bc46e0cd10073ae94e8d52dc468d8b9"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = ["crates/scaena-core"]
|
||||
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "scaena-core"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
license = "CPAL-1.0"
|
||||
description = "Pure core of Scaena: canon parser, claim checker, hook templates. No I/O."
|
||||
repository = "https://gitea.marek-novak.cz/mnovak/ScaenaPublic"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
thiserror = "2"
|
||||
unicode-segmentation = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
proptest = "1"
|
||||
@@ -0,0 +1,200 @@
|
||||
// SPDX-License-Identifier: CPAL-1.0
|
||||
// Copyright (c) 2026 Marek Novák. Exhibit A notice: LICENSE at the repository root.
|
||||
|
||||
//! Canon files: `apps/<id>.md`, the only facts Praeco Domi may state.
|
||||
//!
|
||||
//! Format (strict):
|
||||
//!
|
||||
//! ```text
|
||||
//! ---
|
||||
//! id: tabula
|
||||
//! name: Tabula
|
||||
//! one_liner: Notes that stay on your own computer.
|
||||
//! audience: People who want notes without an account.
|
||||
//! price: (assumption) one-time purchase
|
||||
//! clicks: New note in 1 click.
|
||||
//! status: released
|
||||
//! aula: https://aula.marek-novak.cz/tabula/
|
||||
//! ---
|
||||
//!
|
||||
//! # Tabula
|
||||
//! - [F1] Tabula keeps notes on your own computer.
|
||||
//! - [F2] It syncs between your devices without a cloud account. (assumption)
|
||||
//! ```
|
||||
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Largest canon file accepted, in bytes.
|
||||
pub const MAX_FILE_BYTES: usize = 64 * 1024;
|
||||
|
||||
/// Highest fact number (`[F9999]`).
|
||||
pub const MAX_FACT_ID: u32 = 9999;
|
||||
|
||||
/// A parsed canon file.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct CanonFile {
|
||||
pub id: String,
|
||||
pub front: FrontMatter,
|
||||
pub facts: Vec<Fact>,
|
||||
}
|
||||
|
||||
/// The front matter of a canon file. Values are kept as written, including a leading `(assumption) `.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct FrontMatter {
|
||||
pub name: String,
|
||||
pub one_liner: String,
|
||||
pub audience: String,
|
||||
pub price: String,
|
||||
pub clicks: String,
|
||||
pub status: Status,
|
||||
pub aula: Option<String>,
|
||||
pub site: Option<String>,
|
||||
}
|
||||
|
||||
/// Release status of an app.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Status {
|
||||
Released,
|
||||
Beta,
|
||||
Planned,
|
||||
}
|
||||
|
||||
/// One fact line `- [F<id>] <text>`. `text` has the trailing ` (assumption)` marker removed;
|
||||
/// `assumption` says whether the fact is unconfirmed. `line` is 1-based (0 for ad-hoc facts).
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Fact {
|
||||
pub id: u32,
|
||||
pub text: String,
|
||||
pub assumption: bool,
|
||||
pub line: usize,
|
||||
}
|
||||
|
||||
/// A canon error: the 1-based line it was found on (0 = the whole file) and what is wrong.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||
#[error("line {line}: {code}")]
|
||||
pub struct CanonError {
|
||||
pub line: usize,
|
||||
pub code: CanonCode,
|
||||
}
|
||||
|
||||
/// What is wrong with a canon file.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum CanonCode {
|
||||
#[error("the file is {bytes} bytes; the limit is 65536")]
|
||||
TooLarge { bytes: usize },
|
||||
#[error("forbidden character U+{codepoint:04X} (control, hidden or direction-changing)")]
|
||||
ForbiddenCharacter { codepoint: u32 },
|
||||
#[error("a carriage return that is not part of a CRLF line ending")]
|
||||
LoneCarriageReturn,
|
||||
#[error("the file must start with a '---' line")]
|
||||
NoFrontMatter,
|
||||
#[error("the front matter is not closed with a '---' line")]
|
||||
UnclosedFrontMatter,
|
||||
#[error("front matter lines must be 'key: value'")]
|
||||
FrontMatterLine,
|
||||
#[error("unknown front matter key '{0}'")]
|
||||
UnknownKey(String),
|
||||
#[error("front matter key '{0}' appears twice")]
|
||||
DuplicateKey(String),
|
||||
#[error("front matter key '{0}' is missing")]
|
||||
MissingKey(String),
|
||||
#[error("front matter key '{0}' has no value")]
|
||||
EmptyValue(String),
|
||||
#[error("'{0}' is not a valid app id (1-32 of a-z 0-9 -, no leading or trailing -)")]
|
||||
BadId(String),
|
||||
#[error("id '{id}' does not match the file name '{stem}'")]
|
||||
IdMismatch { id: String, stem: String },
|
||||
#[error("status '{0}' is not one of released, beta, planned")]
|
||||
BadStatus(String),
|
||||
#[error("'{0}' is not a single https:// URL")]
|
||||
BadUrl(String),
|
||||
#[error("a line starting '- [F' must be '- [F<n>] <text>'")]
|
||||
MalformedFact,
|
||||
#[error("fact number must be 1-9999 without leading zeros")]
|
||||
FactIdOutOfRange,
|
||||
#[error("fact F{0} appears twice")]
|
||||
DuplicateFact(u32),
|
||||
#[error("fact has no text")]
|
||||
EmptyFact,
|
||||
#[error("app '{0}' is already in the canon")]
|
||||
DuplicateApp(String),
|
||||
}
|
||||
|
||||
/// Parse `apps/<file_stem>.md`. Strict: any deviation from the format is an error.
|
||||
pub fn parse(file_stem: &str, text: &str) -> Result<CanonFile, CanonError> {
|
||||
let _ = (file_stem, text);
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// True if `id` is a valid app id: 1-32 of `[a-z0-9-]`, no leading or trailing `-`.
|
||||
pub fn is_valid_app_id(id: &str) -> bool {
|
||||
let _ = id;
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// True if a front matter value is marked `(assumption) `.
|
||||
pub fn is_assumption_value(value: &str) -> bool {
|
||||
let _ = value;
|
||||
todo!()
|
||||
}
|
||||
|
||||
impl CanonFile {
|
||||
/// The fact with this number.
|
||||
pub fn fact(&self, id: u32) -> Option<&Fact> {
|
||||
let _ = id;
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Allowed URLs of this file: `aula`, `site`, and every `https://` URL inside a fact's text. Sorted, unique.
|
||||
pub fn urls(&self) -> Vec<String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// An in-memory canon file (for the `release` source). Facts count as confirmed. Not validated.
|
||||
pub fn adhoc(id: &str, name: &str, facts: Vec<(u32, String)>) -> CanonFile {
|
||||
let _ = (id, name, facts);
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// The set of canon files, keyed by app id.
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Canon {
|
||||
files: BTreeMap<String, CanonFile>,
|
||||
}
|
||||
|
||||
impl Canon {
|
||||
pub fn new() -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Add a file. A second file with the same id is an error.
|
||||
pub fn insert(&mut self, f: CanonFile) -> Result<(), CanonError> {
|
||||
let _ = f;
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn get(&self, app: &str) -> Option<&CanonFile> {
|
||||
let _ = app;
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// All files, sorted by id.
|
||||
pub fn apps(&self) -> impl Iterator<Item = &CanonFile> {
|
||||
self.files.values()
|
||||
}
|
||||
|
||||
pub fn fact(&self, app: &str, id: u32) -> Option<&Fact> {
|
||||
let _ = (app, id);
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// The union of every file's [`CanonFile::urls`].
|
||||
pub fn allowed_urls(&self) -> BTreeSet<String> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// SPDX-License-Identifier: CPAL-1.0
|
||||
// Copyright (c) 2026 Marek Novák. Exhibit A notice: LICENSE at the repository root.
|
||||
|
||||
//! The claim checker.
|
||||
//!
|
||||
//! Every sentence that states a fact carries at least one `[app#Fn]` reference (several may be adjacent:
|
||||
//! `[tabula#F3][tabula#F7]`) at its end, and every reference must point to a confirmed canon fact.
|
||||
//! Fail closed: a sentence states a fact unless it is one of a short list of plain phrases
|
||||
//! ("Here's what's new.", "Try it today.").
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::canon::Canon;
|
||||
|
||||
/// A claim reference `[app#F<fact>]`.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
pub struct Ref {
|
||||
pub app: String,
|
||||
pub fact: u32,
|
||||
}
|
||||
|
||||
/// Why a text fails the claim check.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub enum Problem {
|
||||
/// A sentence that states a fact without any reference.
|
||||
Unsourced { sentence: String },
|
||||
/// The app exists, the fact does not.
|
||||
MissingFact { r: Ref },
|
||||
/// No canon file for the app.
|
||||
UnknownApp { r: Ref },
|
||||
/// The fact is marked `(assumption)`.
|
||||
Unconfirmed { r: Ref },
|
||||
/// Something that looks like a reference but is not `[app#Fn]`.
|
||||
MalformedRef { text: String },
|
||||
/// A URL that is not in [`Canon::allowed_urls`].
|
||||
UrlNotInCanon { url: String },
|
||||
/// A control, hidden or direction-changing character (addition to the Day 1 contract).
|
||||
HiddenCharacter { codepoint: u32 },
|
||||
}
|
||||
|
||||
impl Problem {
|
||||
/// Plain English, for "Needs facts".
|
||||
pub fn reason(&self) -> String {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// The result of [`check`].
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Report {
|
||||
/// Every well-formed reference found, sorted and unique.
|
||||
pub refs: Vec<Ref>,
|
||||
pub problems: Vec<Problem>,
|
||||
}
|
||||
|
||||
impl Report {
|
||||
pub fn ok(&self) -> bool {
|
||||
self.problems.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
/// Check generated text against the canon.
|
||||
pub fn check(text: &str, canon: &Canon) -> Report {
|
||||
let _ = (text, canon);
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Remove every well-formed `[app#Fn]` reference (and the spaces before it), for display and posting.
|
||||
pub fn strip_refs(text: &str) -> String {
|
||||
let _ = text;
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Split text into sentences the way [`check`] does.
|
||||
pub fn sentences(text: &str) -> Vec<String> {
|
||||
let _ = text;
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Whether [`check`] treats this sentence (without its references) as stating a fact. Fail closed.
|
||||
pub fn states_fact(sentence: &str, canon: &Canon) -> bool {
|
||||
let _ = (sentence, canon);
|
||||
todo!()
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// SPDX-License-Identifier: CPAL-1.0
|
||||
// Copyright (c) 2026 Marek Novák. Exhibit A notice: LICENSE at the repository root.
|
||||
|
||||
//! Hook templates: `brand/hooks.md` lines `- [H<n>] <template>` with slots from a fixed set.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The only slot names a template may use.
|
||||
pub const SLOTS: [&str; 7] = ["app", "feature", "pain", "number", "platform", "clicks", "audience"];
|
||||
|
||||
/// Largest hooks file accepted, in bytes.
|
||||
pub const MAX_FILE_BYTES: usize = 64 * 1024;
|
||||
|
||||
/// One hook template. `id` is `H<n>`; `slots` are unique, in order of first use.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct HookTemplate {
|
||||
pub id: String,
|
||||
pub text: String,
|
||||
pub slots: Vec<String>,
|
||||
pub genome: Genome,
|
||||
}
|
||||
|
||||
/// How a hook opens.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Opening {
|
||||
Question,
|
||||
Statement,
|
||||
Number,
|
||||
Command,
|
||||
}
|
||||
|
||||
/// A simple genome derived from a hook's text (Day 4 evolves it).
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct Genome {
|
||||
pub opening: Opening,
|
||||
/// Words, a slot counts as one.
|
||||
pub words: usize,
|
||||
/// A digit or the `{number}` slot.
|
||||
pub has_number: bool,
|
||||
/// The first word, lowercased, when the hook opens with a command.
|
||||
pub lead_verb: Option<String>,
|
||||
}
|
||||
|
||||
impl Genome {
|
||||
/// Derive the genome from a template or a filled hook.
|
||||
pub fn of(text: &str) -> Genome {
|
||||
let _ = text;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// A hooks file error.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum HookError {
|
||||
#[error("the file is {bytes} bytes; the limit is 65536")]
|
||||
TooLarge { bytes: usize },
|
||||
#[error("line {line}: forbidden character U+{codepoint:04X} (control, hidden or direction-changing)")]
|
||||
ForbiddenCharacter { line: usize, codepoint: u32 },
|
||||
#[error("line {line}: a line starting '- [H' must be '- [H<n>] <template>'")]
|
||||
Malformed { line: usize },
|
||||
#[error("line {line}: hook number must be 1-9999 without leading zeros")]
|
||||
IdOutOfRange { line: usize },
|
||||
#[error("line {line}: hook {id} appears twice")]
|
||||
Duplicate { line: usize, id: String },
|
||||
#[error("line {line}: unknown slot '{{{slot}}}'")]
|
||||
UnknownSlot { line: usize, slot: String },
|
||||
#[error("line {line}: unbalanced '{{' or '}}'")]
|
||||
UnbalancedBrace { line: usize },
|
||||
#[error("line {line}: hook has no text")]
|
||||
Empty { line: usize },
|
||||
#[error("no value for slot '{{{slot}}}'")]
|
||||
MissingValue { slot: String },
|
||||
}
|
||||
|
||||
/// Parse `brand/hooks.md`. Lines that do not start `- [H` are ignored (headings, prose).
|
||||
pub fn parse(md: &str) -> Result<Vec<HookTemplate>, HookError> {
|
||||
let _ = md;
|
||||
todo!()
|
||||
}
|
||||
|
||||
impl HookTemplate {
|
||||
/// Fill every slot. A missing value is an error; braces inside values are not expanded again.
|
||||
pub fn fill(&self, values: &BTreeMap<String, String>) -> Result<String, HookError> {
|
||||
let _ = values;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// SPDX-License-Identifier: CPAL-1.0
|
||||
// Copyright (c) 2026 Marek Novák. Exhibit A notice: LICENSE at the repository root.
|
||||
|
||||
//! `scaena-core`: the pure core of Scaena and Praeco Domi.
|
||||
//!
|
||||
//! - [`canon`]: the strict parser for canon files (`apps/<id>.md`), the only facts Praeco Domi may state.
|
||||
//! - [`claims`]: the claim checker. Every sentence that states a fact must carry an `[app#Fn]` reference to a
|
||||
//! confirmed canon fact. Fail closed: when unsure whether a sentence states a fact, it does.
|
||||
//! - [`hooks`]: hook templates (`brand/hooks.md`) with a fixed slot set, filling, and a simple genome.
|
||||
//!
|
||||
//! No I/O, no unsafe code.
|
||||
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
pub mod canon;
|
||||
pub mod claims;
|
||||
pub mod hooks;
|
||||
|
||||
mod text;
|
||||
@@ -0,0 +1,4 @@
|
||||
// SPDX-License-Identifier: CPAL-1.0
|
||||
// Copyright (c) 2026 Marek Novák. Exhibit A notice: LICENSE at the repository root.
|
||||
|
||||
//! Shared text scanning: forbidden characters, URLs, line splitting.
|
||||
Reference in New Issue
Block a user