ctb_formats_dcdata/
dcdata.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3This file is part of Collective Toolbox, a database and document workspace and utilities.
4Copyright (C) 2026 Collective Toolbox Developers
5Contact: info@collectivetoolbox.com
6
7This program is free software: you can redistribute it and/or modify it under
8the terms of the GNU Affero General Public License as published by the Free
9Software Foundation, either version 3 of the License, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License along
17with this program.  If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Comprehensive table validators and facet splitters for Document Characters (Dcs),
21//! Formats, and Global Graph Layout datasets.
22
23#[cfg(test)]
24pub(crate) use ctb_build_support::{dc_codegen, find_repository_root_from};
25pub(crate) use ctb_build_support::{fs2, sha2};
26#[allow(
27    unused_imports,
28    clippy::wildcard_imports,
29    reason = "Standard workspace crate prelude"
30)]
31pub(crate) use ctb_utilities::*;
32
33pub use crate as ctb_formats_dc_data;
34
35#[path = "../../build_support/ctbnbdl.rs"]
36pub mod ctbnbdl;
37#[rustfmt::skip]
38#[path = "dc.generated.rs"]
39pub mod dc;
40pub mod dc_char;
41pub mod dc_def;
42pub mod dc_number_minimal;
43pub mod dcts;
44pub mod format_spec;
45pub mod lookup;
46pub mod seed_graph;
47pub mod stagel3;
48pub mod support;
49pub mod syntax;
50
51pub use support::{
52    column_spec, format, graph_ledger, layout, report, shared,
53    stagel_dc_alloc, updater, validation, wat,
54};
55
56pub use column_spec::{
57    ParsedAliasesOrBaseColumn, parse_aliases_or_base_column,
58};
59
60pub use ctb_formats_dctf as dctf;
61pub use ctb_storage_minimal::global_graph_layout;
62pub use ctb_storage_minimal::shorthand;
63pub use ctb_storage_minimal::shorthand::{
64    DcShorthand, is_valid_shorthand, parse_format_shorthand,
65    parse_unicode_shorthand,
66};
67pub use dcts::{
68    DctsOptions, dclist_to_dcts, dclist_to_dcts_string_with_options,
69    dclist_to_dcts_with_options, parse_dcts_strict_to_dc_chars,
70};
71
72pub use ctb_formats_unicode::describe_general_category;
73pub use ctb_utilities::DC_INTEGER;
74pub use dc::{
75    DC_ASSIGN, DC_BASE64_END, DC_BASE64_PADDING, DC_BASE64_START,
76    DC_BEGIN_BLOCK_COMMENT, DC_BEGIN_BLOCK_COMMENT_NEW_LINE,
77    DC_BEGIN_CHECKSUMMED_SECTION, DC_BEGIN_DATE_DURATION,
78    DC_BEGIN_DATE_MAGNITUDE, DC_BEGIN_ENVIRONMENT_DESCRIPTION,
79    DC_BEGIN_ERROR_RECORD, DC_BEGIN_FILE_FLAGS_DESCRIPTION,
80    DC_BEGIN_FORMAT_REPRESENTATION, DC_BEGIN_IDENTIFIER, DC_BEGIN_KV_MAP,
81    DC_BEGIN_KV_PAIR, DC_BEGIN_LEGACY_KV_MAP, DC_BEGIN_LIST, DC_BEGIN_LITERAL,
82    DC_BEGIN_NUMBER, DC_BEGIN_OPERATION_SESSION, DC_BEGIN_PARAMETER,
83    DC_BEGIN_SINGLE_LINE_COMMENT, DC_BEGIN_SINGLE_LINE_COMMENT_NEW_LINE,
84    DC_BEGIN_TIME_MOMENT, DC_BEGIN_TYPE_DEF, DC_BEGIN_WARNING_RECORD,
85    DC_BOOLEAN_FALSE, DC_BOOLEAN_TRUE, DC_COLLECTIVE_TOOLBOX_WORKSPACE,
86    DC_DC_DOCUMENT_EXECUTION_KERNEL, DC_DESTINATION_PATH,
87    DC_END_BLOCK_COMMENT, DC_END_CHECKSUMMED_SECTION, DC_END_DATE_DURATION,
88    DC_END_DATE_MAGNITUDE, DC_END_ENCAPSULATION_BINARY,
89    DC_END_ENCAPSULATION_UTF8, DC_END_ENVIRONMENT_DESCRIPTION,
90    DC_END_ERROR_RECORD, DC_END_FILE_FLAGS_DESCRIPTION,
91    DC_END_FORMAT_REPRESENTATION, DC_END_IDENTIFIER, DC_END_KV_MAP,
92    DC_END_KV_PAIR, DC_END_LEGACY_KV_MAP, DC_END_LIST, DC_END_LITERAL,
93    DC_END_NUMBER, DC_END_OPERATION_SESSION, DC_END_PARAMETER,
94    DC_END_SINGLE_LINE_COMMENT, DC_END_TIME_MOMENT, DC_END_TYPE_DEF,
95    DC_END_WARNING_RECORD, DC_ENTER_IDENTIFIER_SCOPE,
96    DC_EQUIVALENT_REPRESENTATIONS, DC_ESCAPE, DC_EXIT_IDENTIFIER_SCOPE,
97    DC_FILE_PATH_DELIMITER, DC_FORMAT_PARAM_APPLICATION, DC_LANG_ASSIGN,
98    DC_LANG_SAY, DC_LIST_ELEMENT_SEPARATOR, DC_LOG_MESSAGE, DC_LONG_DC,
99    DC_NEGATIVE, DC_OPERATION_COMPLETED, DC_OPERATION_STATUS_CODE,
100    DC_OPTIONAL_ABSENT, DC_OPTIONAL_PRESENT,
101    DC_PARTIALLY_EQUIVALENT_REPRESENTATIONS, DC_POSITIVE, DC_RAW_FILE_FLAGS,
102    DC_REFERENCE_BOUND_VALUE, DC_REFERENCE_NAMED_OBJECT,
103    DC_REPLACEMENT_UNAVAIL_DC, DC_REPLACEMENT_UNAVAIL_UNICODE,
104    DC_ROUTINE_INVOCATION, DC_SECTION_DIGEST, DC_SEQUENCE_IDENTIFIER,
105    DC_SOURCE_PATH, DC_START_ENCAPSULATION_BINARY, DC_START_ENCAPSULATION_UTF8,
106    DC_TRACE_IDENTIFIER, DC_TYPE_ANY, DC_TYPE_CONVERSION, DC_TYPE_INTERSECTION,
107    DC_TYPE_NUMBER, DC_TYPE_ROUTINE, DC_TYPE_ROUTINE_NAME, DC_TYPE_STRING,
108    DC_TYPE_TRANSFORMATION, DC_TYPE_TRANSMUTATION, DC_TYPE_UNION,
109    SHORT_DC_REGION_END, SHORT_DC_REGION_START, long_to_short_dc,
110    short_to_long_dc,
111};
112pub use dc_char::{DcChar, DcCharExt, is_type_token};
113pub use dc_def::{DcDefn, FormatDetails};
114pub use dc_number_minimal::{
115    dc_base64_char_to_digit, dc_base64_char_to_digit_with_resolver,
116    dc_base64_digit_to_char, integer_to_dc_number_chars,
117    is_dc_base64_encapsulation_char,
118    is_dc_base64_encapsulation_char_with_resolver, read_dc_number_u128,
119    read_dc_number_u128_with_resolver, read_typed_dc_integer,
120    read_typed_dc_integer_with_resolver, u128_to_dc_number_chars,
121    u128_to_dc_number_short,
122};
123pub use format::{
124    FORMAT_REGION_END, FORMAT_REGION_START, validate_all_format_files,
125    validate_all_format_files_from_disk, validate_format_files_data,
126    validate_formats_category_file,
127};
128pub use format_spec::{
129    DcToken, FormatExpr, FormatOp, MAX_FORMAT_EXPR_DEPTH,
130    MAX_FORMAT_EXPR_NODES, decode_dc_stream, decode_dc_stream_string,
131    encode_dc_stream, encode_dc_stream_string, format_chain_directive,
132    format_expr, parse_format_expr, validate_format_expr,
133};
134pub use layout::{
135    ParsedLayoutRow, UNICODE_REGION_END, UNICODE_REGION_START,
136    validate_layout_table,
137};
138pub use lookup::{
139    get_all_dc_defns, get_all_format_defns, get_dc_count, get_dc_defn,
140    get_dc_name, get_eite_dc_data_rows, get_short_dc_defn, get_short_dc_name,
141    maximum_known_short_dc,
142};
143pub use report::{ValidationDiagnostic, ValidationReport, ValidationSeverity};
144pub use seed_graph::{
145    ActiveConverterBody, ActiveConverterStep, ActivePropertyValue,
146    PRIMARY_SEED_GRAPH_ASSET_KEY, ReconstructedNamedType,
147    SEED_GRAPH_ASSET_GLOB, SYSTEM_GRAPH_HISTORY_ASSET_GLOB, SeedGraphIndex,
148    TrustedSystemSupervisorResolution,
149};
150pub use shared::{
151    BidiClass, GeneralCategory, SupportLevel, validate_bidi_class,
152    validate_combining_class, validate_cross_table_uniqueness,
153    validate_extension_entry, validate_extensions_field,
154    validate_general_category, validate_mime_field, validate_rust_identifier,
155    validate_support_level,
156};
157pub use stagel_dc_alloc::{
158    StagelAllocStats, assign_and_update_stagel_dc_ids,
159    check_stagel_files_need_no_dc_updates,
160};
161pub use syntax::{
162    ActionArg, CharTarget, DcSyntaxExpr, DcSyntaxRule, Quantifier,
163    SyntaxAction, SyntaxElement, SyntaxPattern, SyntaxTerm, parse_dc_syntax,
164    parse_target_token, validate_dc_syntax,
165};
166pub use tinywasm;
167pub use updater::{
168    MergedGenerationStats, TableUpdateStats, assign_and_update_dc_categories,
169    assign_and_update_format_categories,
170    check_category_csvs_need_no_id_updates, find_repository_root,
171    generate_merged_csvs, is_empty_row, is_unassigned_id, read_csv_file,
172    validate_category_allocations, write_csv_file,
173};
174pub use validation::{
175    parse_dc_aliases_column, split_dc_aliases_column, validate_all_data_tables,
176    validate_all_data_tables_embedded, validate_all_data_tables_from_repo,
177    validate_all_data_tables_from_repo_with_options, validate_all_dc_files,
178    validate_all_dc_files_from_disk, validate_dc_aliases_spacing,
179    validate_dc_category_file, validate_dc_files_data,
180};
181
182/// Returns the raw bytes of a data source file from `src/formats/dcdata/data-src/`.
183pub fn get_dc_data_file(key: &str) -> Option<Vec<u8>> {
184    // Reason for fallback: strip optional data-src/ or fixtures/ prefix, defaulting to full relative key
185    let clean = key
186        .strip_prefix("data-src/")
187        .or_else(|| key.strip_prefix("fixtures/"))
188        .unwrap_or(key);
189    let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
190        .join("data-src")
191        .join(clean);
192    std::fs::read(path).ok()
193}
194
195pub(crate) fn get_dc_categories_dir_path() -> std::path::PathBuf {
196    std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
197        .join("data-src")
198        .join("categories")
199}
200
201pub(crate) fn get_formats_categories_dir_path() -> std::path::PathBuf {
202    std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
203        .join("data-src")
204        .join("categories/formats")
205}