Skip to content

Commit 07dff7d

Browse files
committed
Prevent printing No documentation found when result is not empty
1 parent 61e2a25 commit 07dff7d

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

lib/src/metta/runner/stdlib/mod.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -689,13 +689,7 @@ mod tests {
689689
!(get-doc &self NoSuchAtom)
690690
"#);
691691

692-
assert_eq_metta_results!(metta.run(parser), Ok(vec![
693-
vec![expr!("@doc-formal"
694-
("@item" "NoSuchAtom")
695-
("@kind" "atom")
696-
("@type" "%Undefined%")
697-
("@desc" {Str::from_str("No documentation")}) )],
698-
]));
692+
assert_eq_metta_results!(metta.run(parser), Ok(vec![vec![]]));
699693
}
700694

701695
#[test]
@@ -718,13 +712,7 @@ mod tests {
718712
!(get-doc &self (some-func arg1 arg2))
719713
"#);
720714

721-
assert_eq_metta_results!(metta.run(parser), Ok(vec![
722-
vec![expr!("@doc-formal"
723-
("@item" ("some-func" "arg1" "arg2"))
724-
("@kind" "atom")
725-
("@type" "RetType")
726-
("@desc" {Str::from_str("No documentation")}) )],
727-
]));
715+
assert_eq_metta_results!(metta.run(parser), Ok(vec![vec![]]));
728716
}
729717

730718
#[test]

lib/src/metta/runner/stdlib/stdlib.metta

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@
825825
(let $type' (if (== $type %Undefined%) (undefined-doc-function-type $params) (cdr-atom $type))
826826
(let ($params' $ret') (get-doc-params $params $ret $type')
827827
(@doc-formal (@item $name) (@kind function) (@type $type) $desc (@params $params') $ret')))
828-
(@doc-formal (@item $name) (@kind function) (@type $type) (@desc "No documentation")) ))
828+
Empty ))
829829

830830
(@doc undefined-doc-function-type
831831
(@desc "Function used by get-doc-single-atom in case of absence of function's type notation")
@@ -872,7 +872,7 @@
872872
(@doc-formal (@item $atom) (@kind atom) (@type $type) $desc)
873873
(unify $space (@doc $atom $desc' (@params $params) $ret)
874874
(get-doc-function $space $atom %Undefined%)
875-
(@doc-formal (@item $atom) (@kind atom) (@type $type) (@desc "No documentation")) ))))
875+
Empty ))))
876876

877877
(@doc help!
878878
(@desc "Function prints documentation for the input atom or module. Without parameters prints the list of the corelib functions.")
@@ -881,6 +881,15 @@
881881
(@return "Unit atom"))
882882
(: help! (-> Atom (->)))
883883
(= (help! $atom)
884+
(case (help-internal! $atom) (
885+
(Empty (println! (format-args "No documentation found for {}" ($atom))))
886+
($other $other) )))
887+
888+
(: help! (-> (->)))
889+
(= (help!) (help! corelib))
890+
891+
(: help-internal! (-> Atom (->)))
892+
(= (help-internal! $atom)
884893
(let $top-space (mod-space! top)
885894
(case (get-doc $top-space $atom) (
886895
((@doc-formal (@item $item) (@kind function) (@type $type) (@desc $descr)
@@ -897,15 +906,14 @@
897906
((@doc-formal (@item $item) (@kind atom) (@type $type) (@desc $descr))
898907
(let () (println! (format-args "Atom {}: {} {}" ($item $type $descr)))
899908
() ))
909+
(Empty Empty)
900910
($other (Error $other "Cannot match @doc-formal structure") )))))
901911

902-
(: help! (-> Symbol (->)))
903-
(= (help! $mod)
904-
(let $space (module-space-no-deps (mod-space! $mod))
905-
(help-space! $space) ))
906-
907-
(: help! (-> (->)))
908-
(= (help!) (help! corelib))
912+
(: help-internal! (-> Symbol (->)))
913+
(= (help-internal! $mod)
914+
(case (module-space-no-deps (mod-space! $mod)) (
915+
((Error $atom $msg) Empty) ; return Empty because other instance returns ()
916+
($space (help-space! $space)) )))
909917

910918
(@doc help-space!
911919
(@desc "Function prints documentation for all of the atoms from the given space.")
@@ -914,13 +922,15 @@
914922
(@return "Unit atom"))
915923
(: help-space! (-> SpaceType (->)))
916924
(= (help-space! $space)
917-
(unify $space (@doc $name (@desc $desc) $params $ret)
918-
(let () (println! (format-args "{}\n\t{}" ($name $desc))) Empty)
919-
Empty))
925+
(let $_ (collapse
926+
(unify $space (@doc $name (@desc $desc) $params $ret)
927+
(let () (println! (format-args "{}\n\t{}" ($name $desc))) Empty)
928+
Empty )) ()))
920929
(= (help-space! $space)
921-
(unify $space (@doc $name (@desc $desc))
922-
(let () (println! (format-args "{}\n\t{}" ($name $desc))) Empty)
923-
Empty))
930+
(let $_ (collapse
931+
(unify $space (@doc $name (@desc $desc))
932+
(let () (println! (format-args "{}\n\t{}" ($name $desc))) Empty)
933+
Empty )) Empty)) ; return Empty because other instance returns ()
924934

925935
(@doc help-param!
926936
(@desc "Function used by function help! to output parameters using println!")

python/tests/scripts/g1_docs.metta

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@
6767
; description.
6868
!(assertEqual
6969
(get-doc NoSuchAtom)
70-
(@doc-formal (@item NoSuchAtom) (@kind atom) (@type %Undefined%) (@desc "No documentation")))
70+
Empty)
7171

7272
; Same result is returned if for instance documentation for the function
7373
; application is queried.
7474
!(assertEqual
7575
(get-doc (some-func arg1 arg2))
76-
(@doc-formal (@item (some-func arg1 arg2)) (@kind atom) (@type ReturnType) (@desc "No documentation")))
76+
Empty)
7777

7878
; `help!` function gets the documentation and prints it in a human readable
7979
; format.

0 commit comments

Comments
 (0)