sanitize-html := λ(: s String). (: (
(set s (replace( s '<_s '<\\:_s )))
(set s (replace( s '>_s '>\\:_s )))
s
) String);
doc-render := λ. (: (
(let doc SNil)
(set doc (+( doc (SAtom '\nimport\sdocs/ubuntu-docs.lm\:\n\n_s) )))
(set doc (+( doc (SAtom '\[docs-html\[\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\`Documentation:\\s_s) )))
(set doc (+( doc (SAtom config-doby-input) )))
(set doc (+( doc (SAtom '_s\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\[docs-header\[\]\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\[docs-sidebar\[\]\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\[docs-title\s\`_s) )))
(set doc (+( doc (SAtom config-doby-input) )))
(set doc (+( doc (SAtom '\\sDocumentation_s\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\[as\[\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\s\s\s\[main\[\s\[class\s\`l-docs__main_s\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\s\s\s\s\s\s\[div\[\s\[class\s\`row_s\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\s\s\s\s\s\s\s\s\s\[div\[\s\[class\s\`col-12_s\]\n_s) )))
(set doc (+( doc (doc-bound-symbols()) )))
(set doc (+( doc (SAtom '\s\s\s\s\s\s\s\s\s\s\s\s\]\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\s\s\s\s\s\s\]\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\s\s\s\]\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\]\sDocsContent+HTMLElement\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\[docs-meta\[\]\]\n_s) )))
(set doc (+( doc (SAtom '\s\s\s\[docs-footer\[\]\]\n_s) )))
(set doc (+( doc (SAtom '\]\]\n_s) )))
(clone-rope doc)
) String);
doc-bound-symbols := λ. (: (
(let doc SNil)
(let program ast-parsed-program)
(while (non-zero program) (match program (
()
( (Seq( (Seq( rst (Meta m) )) f )) (
(set doc (+( (doc-symbol( m f )) doc )))
(set program rst)
))
( (Seq( rst _ )) (
(set program rst)
))
)))
doc
) S);
doc-symbol := λ(: meta AST)(: binding AST). (: (
(let doc SNil)
(match binding (
()
( (Frg( k_t abs )) (
(set doc (+( doc (SAtom '\[hr\[\]\]\n\[h4\[\s\[text\s\`_s) )))
(set doc (+( doc (doc-signature( k abs )) )))
(set doc (+( doc (SAtom '_s\]\]\]\n_s) )))
(set doc (+( doc (doc-meta meta) )))
))
( (Glb( k_t abs )) (
(set doc (+( doc (SAtom '\[hr\[\]\]\n\[h4\[\s\[text\s\`_s) )))
(set doc (+( doc (doc-signature( k abs )) )))
(set doc (+( doc (SAtom '_s\]\]\]\n_s) )))
(set doc (+( doc (doc-meta meta) )))
))
( (Typedef( lhs rhs )) (
(set doc (+( doc (SAtom '\[hr\[\]\]\n\[h4\[\s\[text\s\`type\\s_s) )))
(set doc (+( doc (doc-type-lhs( lhs )) )))
(set doc (+( doc (SAtom '_s\]\]\]_s) )))
(set doc (+( doc (doc-meta meta) )))
))
( _ (
(print 'Unknown\sSymbol\sBinding\sin\sdoc-symbol:\s_s)
(print binding)
(exit 1_u64)
))
))
doc
) S);
doc-type-lhs := λ(: lhs AST). (: (
(let doc SNil)
(match lhs (
()
( (Lit( base _ )) (
(set doc (SAtom base))
))
))
doc
) S);
doc-signature := λ(: k String)(: abs AST). (: (
(+(
(+(
(SAtom '_s)
(SAtom(sanitize-html( k )))
))
(+(
(SAtom '\\s:\\s_s)
(SAtom(sanitize-html(clone-rope(doc-signature abs))))
))
))
) S);
doc-signature := λ(: abs AST). (: (
(let r SNil)
(match abs (
()
( (Abs( lhs (App( (Lit ':_t) (App( _ (AType tt) )) )) _ )) (
(set r (+(
(doc-signature( lhs ))
(+(
(SAtom '\\s->\\s_s)
(SAtom(to-string tt))
))
)))
))
( (App( rst (App( (Lit ':_t) (App( (Var k_t) (AType tt) )) )) )) (
(set r (+(
(doc-signature( rst ))
(+(
(SAtom '\\[_s)
(+(
(+(
(SAtom k)
(SAtom ':\\s_s)
))
(+(
(SAtom(to-string tt))
(SAtom '\\]_s)
))
))
))
)))
))
( (App( (Lit ':_t) (App( (Var k_t) (AType tt) )) )) (
(set r (+(
(SAtom '\\[_s)
(+(
(+(
(SAtom k)
(SAtom ':\\s_s)
))
(+(
(SAtom(to-string tt))
(SAtom '\\]_s)
))
))
)))
))
( ASTNil (
(set r (SAtom '\\[\\]_s))
))
( _ (
(print 'Invalid\sSignature:\s_s)(print abs)(print '\n_s)
))
))
r
) S);
doc-meta := λ(: meta AST). (: (
(let doc SNil)
(match meta (
()
( (App( (Var m-key_t) m-item )) (
(set doc (doc-meta-item( m-key m-item )))
))
( (App( m-rst (App( (Var m-key_t) m-item )) )) (
(set doc (+(
(doc-meta( m-rst ))
(doc-meta-item( m-key m-item ))
)))
))
))
doc
) S);
doc-meta-item := λ(: m-key String)(: m-item AST). (: (
(let doc SNil)
(match (Tuple( m-key m-item )) (
()
( (Tuple( 'description_s (Lit description_t) )) (
(set doc (+( doc (SAtom '\[p\[\s\[text\s\`_s) )))
(set doc (+( doc (SAtom description) )))
(set doc (+( doc (SAtom '_s\]\]\]\n_s) )))
))
( (Tuple( 'example_s term )) (
(set doc (+( doc (SAtom '\[pre\[\s\[code\[\s\[text\s\`_s) )))
(set doc (+( doc (doc-code term) )))
(set doc (+( doc (SAtom '_s\]\]\]\]\]\n_s) )))
))
( _ (
(print 'Unrecognized\sMeta\sItem:\s_s)(print m-key)(print '\n_s)
))
))
doc
) S);
doc-code-arg-is-simple := λ(: term AST). (: (
(let r 1_u64)
(match term (
()
( (App( _ _ )) (set r 0_u64) )
( _ () )
))
r
) U64);
doc-code := λ(: term AST). (: (doc-code( 0_u64 term )) S);
doc-code := λ(: indent U64)(: term AST). (: (
(let doc SNil)
(match term (
()
( (App( (Var( f-name _ )) args )) (
(if (doc-code-arg-is-simple( args )) (
(set doc (+(
(+(
(SAtom(*( '\\s\\s\\s_s indent )))
(SAtom '\\[_s)
))
(+(
(+(
(SAtom f-name)
(SAtom '\\[\\s_s)
))
(+(
(doc-code( indent args ))
(SAtom '\\s\\]\\]\\n_s)
))
))
)))
) (
(set doc (+(
(+(
(SAtom(*( '\\s\\s\\s_s indent )))
(SAtom '\\[_s)
))
(+(
(+(
(SAtom f-name)
(SAtom '\\[\\n_s)
))
(+(
(doc-code( (+( indent 1_u64 )) args ))
(SAtom '\\]\\]\\n_s)
))
))
)))
))
))
( (App( arg1 arg2 )) (
(if (doc-code-arg-is-simple( arg1 )) (
(set doc (+(
(doc-code( indent arg1 ))
(+(
(+(
(SAtom '\\n_s)
(SAtom(*( '\\s\\s\\s_s indent )))
))
(doc-code( indent arg2 ))
))
)))
) (
(set doc (+(
(doc-code( indent arg1 ))
(doc-code( indent arg2 ))
)))
))
))
( (App( (Lit( ':_s _ )) (App( t (AType tt) )) )) (
(set doc (+(
(+(
(SAtom '\\[:\\s_s)
(doc-code( indent t ))
))
(+(
(SAtom '\\s_s)
(+(
(SAtom(to-string tt))
(SAtom '\\]_s)
))
))
)))
))
( ASTNil (
(set doc (SAtom '\\[\\]_s))
))
( (Lit( l _ )) (
(set doc (+(
(SAtom '\\`_s)
(SAtom l)
)))
))
( t (
(print 'Unmatched\sTerm\sIn\sdoc-code:\s_s)(print t)(print '\n_s)
))
))
doc
) S);