Skip to content

Commit 719ade9

Browse files
authored
Merge pull request #1062 from vsbogd/docs
Format docs, add documentation publishing howto
2 parents 920fbb9 + 2f2b234 commit 719ade9

File tree

4 files changed

+91
-49
lines changed

4 files changed

+91
-49
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@ Running benchmarks requires nightly toolchain so they can be run using:
151151
cargo +nightly bench --features benchmark
152152
```
153153

154-
Generate docs:
155-
```
156-
cargo doc --no-deps
157-
```
158-
Docs can be found at `./target/doc/hyperon/index.html`.
159-
160154
## C and Python API
161155

162156
Create build directory and initialize CMake project:

docs/building_c_docs.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/building_docs.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Howto Build and Publish Documentation
2+
3+
## Building Rust Documentation
4+
5+
Run the following command under the root directory of the repository:
6+
```
7+
cargo doc --no-deps
8+
```
9+
Docs can be found at `./target/doc/hyperon/index.html`.
10+
11+
## Building C Documentation
12+
13+
1. `doxygen` must be installed. Depending on your platform it may be easiest to use a package manager.
14+
- using apt: `sudo apt-get install doxygen`
15+
- using homebrew (Mac): `brew install doxygen`
16+
- installing from source: [https://www.doxygen.nl/manual/install.html]
17+
18+
2. Build the Hyperon C library, following the instructions here: [https://github.com/trueagi-io/hyperon-experimental?tab=readme-ov-file#c-and-python-api]
19+
20+
3. Set CMake environment variables. Relative to the `build` directory, run the following:
21+
- `export CMAKE_CURRENT_SOURCE_DIR=../c/`
22+
- `export HYPERONC_INCLUDE_DIR=./hyperonc-install/include/hyperonc/hyperon/`
23+
24+
4. Invoke `doxygen` using the following command: `doxygen ../c/hyperonc.doxyfile`
25+
26+
The top page for the rendered HTML results will be written to `./html/index.html`, and latex results will be similarly written to `./latex/index.tex`
27+
28+
## Building Python Documentation
29+
30+
Install `mkdocs` and dependencies.
31+
```
32+
pip install mkdocs-material==9.7.0 \
33+
mkdocs-minify-plugin==0.8.0 \
34+
mkdocstrings[python]==0.26.1
35+
```
36+
37+
Run the following command under the root directory of the repository:
38+
```
39+
mkdocs build
40+
```
41+
42+
## Publishing the Documentation
43+
44+
Make all of three steps above. Then copy Rust and C API documentation under the
45+
common site tree:
46+
```
47+
cp -R ./target/doc ./site/rust
48+
cp -R ./build/html ./site/c
49+
```
50+
51+
Publish `./site` directory as `gh-pages` branch of the repository:
52+
```
53+
ghp-import -m 'Deploy documentation' \
54+
--push \
55+
--force \
56+
--no-history \
57+
--remote=<git remote repo> \
58+
--branch=gh-pages \
59+
./site
60+
```

docs/metta.md

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# Syntax
1+
# MeTTa language specification
22

3-
## S-expression grammar
3+
This document covers MeTTa language specification implemented by
4+
hyperon-experimental interpreter.
5+
6+
## Syntax
7+
8+
### S-expression grammar
49

510
This is the S-expression grammar of the MeTTa language. The program is
611
consisted of the atoms prefixed or not prefixed by the `!` sign.
@@ -49,7 +54,7 @@ the `<token regexp>` from the tokenizer then a grounded atom is constructed by
4954
argument. For instance it is possible instantiating the integer grounded atoms
5055
by adding the pair `([0-9]+, <int parser>)` into the tokenizer.
5156

52-
## Special expressions
57+
### Special expressions
5358

5459
This section lists atoms with some special meaning in the interpreter. The
5560
expressions listed below are not the only expressions possible when the special
@@ -63,7 +68,7 @@ other languages. In MeTTa the programmer still can use these symbols in an
6368
unusual context but it should be noted that the interpreter has a special
6469
meaning for them.
6570

66-
### Function expression
71+
#### Function expression
6772

6873
The `=` atom is used to define a function expression in the following form:
6974
```
@@ -76,7 +81,7 @@ For example the `if` function can be defined as following:
7681
(= (if False $then $else) $else)
7782
```
7883

79-
### Type assignment
84+
#### Type assignment
8085

8186
The `:` atom is used to define the type of the atom:
8287
```
@@ -88,7 +93,7 @@ For example the `if` function could have the following type definition:
8893
(: if (-> Bool Atom Atom $t))
8994
```
9095

91-
### Function type
96+
#### Function type
9297

9398
The `->` atom is used to introduce a type of a function:
9499
```
@@ -100,7 +105,7 @@ For example the type of the `if` function:
100105
(-> Bool Atom Atom $t)
101106
```
102107

103-
### Elementary types
108+
#### Elementary types
104109

105110
There are the number of symbols which are used as the basic types:
106111
- `Type` - the type of any type
@@ -117,7 +122,7 @@ These types plus `Atom` are referred below as meta-types. `Atom` is a special
117122
meta-type which matches any atom and used for changing the order of evaluation.
118123

119124

120-
### Special function results
125+
#### Special function results
121126

122127
- `Empty` - the function doesn't return any result, it is different from the
123128
void or unit result in other languages
@@ -147,7 +152,7 @@ it could be used to introduce custom type constructors. This could be
147152
implemented by making an interpreter treating any expression which has
148153
`ErrorType` type as an error.
149154

150-
### Minimal MeTTa instructions
155+
#### Minimal MeTTa instructions
151156

152157
The minimal MeTTa is an attempt to create an assembly language for MeTTa.
153158
Minimal MeTTa related atoms are listed here because while they are not a part
@@ -192,7 +197,7 @@ Minimal MeTTa instructions:
192197
(*) `call-native` instruction cannot be called from a MeTTa program, but it can
193198
be returned by a grounded function for the further evaluation.
194199

195-
# Interpretation
200+
## Interpretation
196201

197202
MeTTa program is interpreted atom by atom. If an atom is not prefixed by `!` it
198203
is added into the atomspace of the top module. Hierarchy of modules is
@@ -230,9 +235,9 @@ Two special functions are not specified: `match_atoms` and `merge_bindings`.
230235
They will be specified in the following sections. For now one can rely on
231236
intuitive understanding how two-side unification and bindings merging works.
232237

233-
## Evaluation
238+
### Evaluation
234239

235-
### Evaluate atom (metta)
240+
#### Evaluate atom (metta)
236241

237242
```
238243
Input:
@@ -267,7 +272,7 @@ else:
267272
return $error
268273
```
269274

270-
### Cast types (type_cast)
275+
#### Cast types (type_cast)
271276

272277
```
273278
Input:
@@ -290,7 +295,7 @@ for $t in $types:
290295
return [((Error $atom (BadType $type $t)), $bindings) for $t in $no_match]
291296
```
292297

293-
### Match types (match_types)
298+
#### Match types (match_types)
294299

295300
```
296301
Input:
@@ -308,7 +313,7 @@ if $type1 == %Undefined% or $type1 == Atom
308313
return match_atoms($type1, $type2)
309314
```
310315

311-
### Interpret expression (interpret_expression)
316+
#### Interpret expression (interpret_expression)
312317

313318
```
314319
Input:
@@ -350,7 +355,7 @@ if <$actual_types contains non function types or %Undefined% type>:
350355
return $tuples + $errors
351356
```
352357

353-
### Interpret tuple (interpret_tuple)
358+
#### Interpret tuple (interpret_tuple)
354359

355360
```
356361
Input:
@@ -376,7 +381,7 @@ for ($h, $hb) in metta($head, %Undefined%, $space, $bindings):
376381
return $result
377382
```
378383

379-
### Check if function type is applicable (check_if_function_type_is_applicable)
384+
#### Check if function type is applicable (check_if_function_type_is_applicable)
380385

381386
```
382387
Input:
@@ -421,7 +426,7 @@ else:
421426
return Ok($results)
422427
```
423428

424-
### Check argument type (check_argument_type)
429+
#### Check argument type (check_argument_type)
425430

426431
```
427432
Input:
@@ -444,7 +449,7 @@ for $t in $actual_types:
444449
return $result
445450
```
446451

447-
### Interpret function (interpret_function)
452+
#### Interpret function (interpret_function)
448453
```
449454
Input:
450455
- $atom - atom to be evaluated
@@ -472,7 +477,7 @@ for ($h, $hb) in metta($op, $op_type, $space, $bindings):
472477
return $result
473478
```
474479

475-
### Interpret arguments (interpret_args)
480+
#### Interpret arguments (interpret_args)
476481

477482
```
478483
Input:
@@ -501,7 +506,7 @@ for ($h, $hb) in metta($atom, $type, $space, $bindings):
501506
return $result
502507
```
503508

504-
### Call MeTTa expression (metta_call)
509+
#### Call MeTTa expression (metta_call)
505510

506511
```
507512
Input:
@@ -542,7 +547,7 @@ else:
542547
return $results
543548
```
544549

545-
## Matching
550+
### Matching
546551

547552
This section explains the atom matching algorithm. The result of matching is
548553
list of variable binding sets. If two atoms matched don't contain grounded
@@ -565,7 +570,7 @@ explain how binding set is modified. For example `$bindings - { $b <- $b_value
565570
} + { $a = $b }` means one need remove relation `$b <- $b_value` from $bindings
566571
and add relation `$a = $b`.
567572

568-
### Match atoms (match_atoms)
573+
#### Match atoms (match_atoms)
569574

570575
```
571576
Input:
@@ -607,7 +612,7 @@ else:
607612
return filter(lambda $b: <$b doesn't have variable loops>, $results)
608613
```
609614

610-
### Merge bindings (merge_bindings)
615+
#### Merge bindings (merge_bindings)
611616

612617
```
613618
Input:
@@ -626,7 +631,7 @@ for $rel in <set of "assign value to var" or "vars are equal" relations of $righ
626631
return $result
627632
```
628633

629-
### Add variable binding to binding set (add_var_binding)
634+
#### Add variable binding to binding set (add_var_binding)
630635

631636
```
632637
Input:
@@ -649,7 +654,7 @@ else:
649654
return $result
650655
```
651656

652-
### Add variable equality to binding set (add_var_equality)
657+
#### Add variable equality to binding set (add_var_equality)
653658

654659
```
655660
Input:

0 commit comments

Comments
 (0)