Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/workshop-rs-cli/src/census.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ fn settings_probe(definition: &SettingDefinition, catalog: &Catalog) -> String {
lines.push(format!("{indent}{name} {{"));
lines.push(format!("{indent}}}"));
}
other => unreachable!("census has no probe for settings value domain {other:?}"),
}
while depth > 1 {
depth -= 1;
Expand Down
10 changes: 4 additions & 6 deletions crates/workshop-rs-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ fn emit_command(args: Vec<String>) -> i32 {
return 1;
}
};
let options = EmitOptions {
fallback_locale: fallback,
};
let mut options = EmitOptions::default();
options.fallback_locale = fallback;
match emitter::emit_with_options(&program, &catalog, &locale, &options) {
Ok(output) => {
report_fallbacks(&output.fallback_ids);
Expand Down Expand Up @@ -283,9 +282,8 @@ fn convert_command(args: Vec<String>) -> i32 {
return 1;
}
};
let options = ConvertOptions {
fallback_locale: fallback,
};
let mut options = ConvertOptions::default();
options.fallback_locale = fallback;
match convert::convert(&input, &catalog, &from, &to, &options) {
Ok(output) => {
report_fallbacks(&output.fallback_ids);
Expand Down
1 change: 1 addition & 0 deletions crates/workshop-rs/src/actions/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct ActionLayout {

/// Errors returned while querying public canonical native action layout.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ActionLayoutError {
/// The public program cannot be materialized as a valid Workshop program.
InvalidProgram { message: String },
Expand Down
3 changes: 3 additions & 0 deletions crates/workshop-rs/src/analysis/element_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum ElementNodeKind {

/// One node's contribution and its nested element-count analysis.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ElementCountNode {
pub kind: ElementNodeKind,
/// An opaque identity unique within this report. It is not a WIR or
Expand All @@ -47,6 +48,7 @@ pub struct ElementCountNode {

/// A structured element-count report for one canonical Workshop program.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ElementCountReport {
/// The sum of all rule counts.
pub total: usize,
Expand All @@ -65,6 +67,7 @@ impl ElementCountReport {

/// A construct for which an exact canonical element count cannot be produced.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ElementCountError {
/// The input cannot be materialized or structurally validated as a
/// canonical Workshop program.
Expand Down
1 change: 1 addition & 0 deletions crates/workshop-rs/src/analysis/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl ResidualClassification {
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct SemanticIssue {
pub kind: IncompletenessKind,
pub name: String,
Expand Down
1 change: 1 addition & 0 deletions crates/workshop-rs/src/catalog/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::core::error::{Result, WorkshopError};

/// A language-detection result with ranked evidence.
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct Detection {
/// The best-matching locale.
pub locale: Locale,
Expand Down
5 changes: 5 additions & 0 deletions crates/workshop-rs/src/catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl Kind {
/// vectors, or null.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct ParamCoercions {
/// Accept `False` as numeric zero.
#[serde(default)]
Expand Down Expand Up @@ -351,6 +352,7 @@ impl EnumDomain {

/// Target-format metadata recorded in the catalog.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[non_exhaustive]
pub struct TargetMeta {
pub game: String,
pub format: String,
Expand All @@ -360,6 +362,7 @@ pub struct TargetMeta {
/// Provenance of the catalog data.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Provenance {
pub generator: String,
pub generator_version: String,
Expand All @@ -376,6 +379,7 @@ pub struct Provenance {
/// localized preset identities, and enum members) carry a mapping for the
/// locale out of the declared total.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[non_exhaustive]
pub struct LocaleCoverage {
pub locale: Locale,
/// Canonical entries with a declared mapping in this locale.
Expand All @@ -391,6 +395,7 @@ pub struct LocaleCoverage {
/// identity names.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub struct CatalogIdentity {
/// The `workshop-rs` package version (semver); bumped by code changes.
pub implementation_version: String,
Expand Down
2 changes: 2 additions & 0 deletions crates/workshop-rs/src/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::core::source::Span;

/// A structured Workshop-language error.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum WorkshopError {
/// Catalog data is malformed or fails validation.
Catalog(CatalogError),
Expand Down Expand Up @@ -33,6 +34,7 @@ pub enum WorkshopError {

/// Catalog-specific error.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct CatalogError {
pub code: &'static str,
pub message: String,
Expand Down
1 change: 1 addition & 0 deletions crates/workshop-rs/src/core/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ impl SourceEdit {

/// Failure while creating or applying source edits.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum SourceEditError {
InvalidRange,
SourceMismatch,
Expand Down
40 changes: 40 additions & 0 deletions crates/workshop-rs/src/gameplay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,33 @@ impl LocalizedText {
/// A machine-identifiable source reference for a gameplay fact.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct SourceReference {
pub source: String,
pub locator: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub note: Option<String>,
}

impl SourceReference {
pub fn new(source: impl Into<String>, locator: impl Into<String>) -> Self {
Self {
source: source.into(),
locator: locator.into(),
note: None,
}
}
pub fn with_note(mut self, note: impl Into<String>) -> Self {
self.note = Some(note.into());
self
}
}

/// Identity and source metadata of a gameplay dataset. This is distinct from
/// the Workshop parser/catalog dataset identity.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct GameplayDatasetIdentity {
pub dataset_id: String,
pub version: String,
Expand All @@ -298,6 +314,28 @@ pub struct GameplayDatasetIdentity {
pub reviewed: bool,
}

impl GameplayDatasetIdentity {
pub fn new(
dataset_id: impl Into<String>,
version: impl Into<String>,
digest: impl Into<String>,
source: impl Into<String>,
license: impl Into<String>,
target: impl Into<String>,
reviewed: bool,
) -> Self {
Self {
dataset_id: dataset_id.into(),
version: version.into(),
digest: digest.into(),
source: source.into(),
license: license.into(),
target: target.into(),
reviewed,
}
}
}

/// A gameplay fact tied to source references in the dataset version being consumed.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Fact<T> {
Expand Down Expand Up @@ -537,6 +575,7 @@ impl Hero {

/// Explicit failure for a logical-slot lookup.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum AbilityLookupError {
Missing {
hero: HeroId,
Expand Down Expand Up @@ -583,6 +622,7 @@ impl std::error::Error for AbilityLookupError {}

/// Validation and construction errors for gameplay data.
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum GameplayDataError {
EmptyIdentity(&'static str),
DuplicateHero(HeroId),
Expand Down
4 changes: 4 additions & 0 deletions crates/workshop-rs/src/gameplay/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum StatOwner {
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum GameplayQueryError {
MissingHero {
hero: HeroId,
Expand Down Expand Up @@ -93,6 +94,7 @@ impl std::error::Error for GameplayQueryError {}

/// Explicit failures from locale-aware display-name resolution.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum AbilityNameResolutionError {
MissingHero {
hero: HeroId,
Expand Down Expand Up @@ -203,6 +205,7 @@ impl TryFrom<f64> for CooldownPercentage {
}

#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum CooldownPercentageError {
NotFinite { value: f64 },
OutOfRange { value: f64 },
Expand All @@ -228,6 +231,7 @@ pub enum CooldownNonApplicability {
}

#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum CooldownError {
Missing {
ability: AbilityRef,
Expand Down
2 changes: 2 additions & 0 deletions crates/workshop-rs/src/output/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::output::emitter::{self, EmitOptions};

/// Conversion options: opt-in fallback for missing target-locale mappings.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct ConvertOptions {
/// When a canonical identity has no spelling for the target locale, its
/// spelling in this declared locale is used instead. `None` (the
Expand All @@ -26,6 +27,7 @@ pub struct ConvertOptions {

/// The result of a raw Workshop locale conversion.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct Conversion {
/// The converted localized Workshop text.
pub text: String,
Expand Down
2 changes: 2 additions & 0 deletions crates/workshop-rs/src/output/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub(crate) use crate::wir;

/// Emission options: opt-in fallback for missing target-locale mappings.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct EmitOptions {
/// When a canonical identity has no spelling for the target locale, its
/// spelling in this declared locale is used instead. `None` (the default)
Expand All @@ -29,6 +30,7 @@ pub struct EmitOptions {

/// The result of a localized emission.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct EmitOutput {
/// The emitted localized Workshop text.
pub text: String,
Expand Down
1 change: 1 addition & 0 deletions crates/workshop-rs/src/output/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::output::emitter;

/// A recorded round-trip result for regression and contract checks.
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct RoundTripRecord {
/// SHA-256 of the input Workshop text.
pub input_identity: String,
Expand Down
1 change: 1 addition & 0 deletions crates/workshop-rs/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct ActionProvenance {

/// A failure while attaching source mappings to a public [`Program`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum SourceMappingError {
UnknownFile(FileId),
InvalidSpan(Span),
Expand Down
8 changes: 8 additions & 0 deletions crates/workshop-rs/src/program/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct SourceMap {
/// Workshop text together with the [`SourceMap`] of its authored origin: the
/// `workshop-rs/mapped-text-v1` artifact.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct MappedText {
/// The Workshop text, itself a `workshop-rs/text-v1` artifact.
pub text: String,
Expand Down Expand Up @@ -411,6 +412,13 @@ impl SourceMap {
}

impl MappedText {
pub fn new(text: impl Into<String>, map: SourceMap) -> Self {
Self {
text: text.into(),
map,
}
}

/// Serialize as a `workshop-rs/mapped-text-v1` JSON document.
pub fn to_json(&self) -> String {
let artifact = Artifact {
Expand Down
5 changes: 5 additions & 0 deletions crates/workshop-rs/src/settings/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub enum SettingIdentity {

/// The Workshop-native section that owns a setting.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum SettingScope {
Main,
Lobby,
Expand Down Expand Up @@ -123,6 +124,7 @@ pub enum Applicability {
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum NumericBoundsError {
NonFinite,
Reversed,
Expand Down Expand Up @@ -196,6 +198,7 @@ pub struct EffectiveNumber {

/// The machine-readable value domain of a setting.
#[derive(Debug, Clone, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum SettingValueDomain {
Boolean,
Number(NumericBounds),
Expand Down Expand Up @@ -288,6 +291,7 @@ impl SettingSourceEdit {

/// Failure from a typed settings query or source-preserving edit.
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum SettingOperationError {
NotApplicable {
setting: SettingId,
Expand Down Expand Up @@ -389,6 +393,7 @@ impl SettingPresentation {

/// Source metadata shared by the reviewed table projection.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct SettingSource {
pub kind: SettingSourceKind,
pub source: &'static str,
Expand Down
Loading
Loading