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
17 changes: 17 additions & 0 deletions lib/src/metta/runner/builtin_mods/catalog.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(@doc catalog-list!
(@desc "Lists contents of all module catalogs that support the \"list\" method")
(@params (
(@param "Name of the catalog to list or \"all\" to list all available")))
(@return "Unit atom"))

(@doc catalog-update!
(@desc "Update all contents of all managed catalogs to the latest version of all modules")
(@params (
(@param "Name of the catalog to update or \"all\" to update all")))
(@return "Unit atom"))

(@doc catalog-clear!
(@desc "Clears the contents of all managed catalogs")
(@params (
(@param "Name of the catalog to clear or \"all\" to clear all")))
(@return "Unit atom"))
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use hyperon_atom::{Atom, Grounded, ExecError, CustomExecute};
use crate::metta::text::SExprParser;
use crate::space::grounding::GroundingSpace;
use crate::metta::{ARROW_SYMBOL, ATOM_TYPE_SYMBOL, UNIT_TYPE};
use crate::metta::runner::{Metta, ModuleLoader, RunContext};
Expand Down Expand Up @@ -49,6 +50,8 @@ use crate::metta::runner::modules::MettaMod;
// At the very least, it makes `!(catalog-list! all)` much more noisy
//

pub static CATALOG_METTA: &'static str = include_str!("catalog.metta");

/// Loader to Initialize the "catalog" module
#[derive(Debug)]
pub(crate) struct CatalogModLoader;
Expand All @@ -57,7 +60,10 @@ impl ModuleLoader for CatalogModLoader {
fn load(&self, context: &mut RunContext) -> Result<(), String> {
let space = GroundingSpace::new();
context.init_self_module(space.into(), None);
self.load_tokens(context.module(), context.metta.clone())
let _ = self.load_tokens(context.module(), context.metta.clone());
let parser = SExprParser::new(CATALOG_METTA);
context.push_parser(Box::new(parser));
Ok(())
}

fn load_tokens(&self, target: &MettaMod, metta: Metta) -> Result<(), String> {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/metta/runner/builtin_mods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod random;
/// Op atoms for working with catalogs
mod json;
#[cfg(feature = "pkg_mgmt")]
pub mod catalog_mods;
pub mod catalog;

#[cfg(feature = "das")]
pub mod das;
Expand All @@ -20,7 +20,7 @@ pub fn load_builtin_mods(metta: &Metta) -> Result<(), String> {
let _mod_id = metta.load_module_direct(Box::new(fileio::FileioModLoader), "fileio").map_err(|e| format!("error loading builtin \"catalog\" module: {e}"))?;
let _mod_id = metta.load_module_direct(Box::new(json::JsonModLoader), "json").map_err(|e| format!("error loading builtin \"catalog\" module: {e}"))?;
#[cfg(feature = "pkg_mgmt")]
let _mod_id = metta.load_module_direct(Box::new(catalog_mods::CatalogModLoader), "catalog").map_err(|e| format!("error loading builtin \"catalog\" module: {e}"))?;
let _mod_id = metta.load_module_direct(Box::new(catalog::CatalogModLoader), "catalog").map_err(|e| format!("error loading builtin \"catalog\" module: {e}"))?;
#[cfg(feature = "das")]
let _mod_id = metta.load_module_direct(Box::new(das::DasModLoader), "das").map_err(|e| format!("error loading builtin \"das\" module: {e}"))?;

Expand Down
2 changes: 1 addition & 1 deletion mkdocs.metta
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@
!(document-module "File Input/Output" fileio)
!(document-module "JSON" json)
!(document-module "Random" random)
!(document-module "Module catalog" catalog)
;!(document-module "DAS" das)
;!(document-module "Modules catalog" catlog_mods)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ nav:
- Random: random.md
- File I/O: fileio.md
- JSON: json.md
- Module catalogs: catalog.md
- Minimal Metta specification: minimal-metta.md
- MeTTa modules: modules_dev.md
- DAS setup: das_setup.md
Expand Down
Loading