Home /Modules/sleeladoc/sleeladoc-demo.sleela

sleeladoc-demo.sleela

lib/sleeladoc/sleeladoc-demo.sleela · 120 line(s) · sleela

#sleela 3.0
material;
<< sleeladoc-demo.sleela -- the self-contained, runnable reference for the
   SleelaDoc extractor (the Javadoc-tool analogue for SLeeLa).

   The compiler runs one directory as a unit, so this demo drives the sibling
   classes directly. It feeds the scanner the TOKENIZED lines of a small
   documented unit (a caller tokenizes at the char-cell boundary; here the lines
   are spelled out as token arrays), then prints the rendered Markdown and HTML
   API pages.

   The documented unit modeled here is a class "Reason" with a class-level doc
   block (title/intent/axiom/evidence tags), a one-line doc on an "int
   confidence" field, and a doc block on an "int check()" method (intent and
   returns tags). The exact SleelaDoc source forms are shown in
   lib/sleeladoc/README.md -- they are not repeated here, because an angle block
   comment cannot itself contain the angle delimiters it would quote. >>
class SleeladocDemo {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 7948;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-28";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-28";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }

  < ---- token-array builders (index-fill; array literals are not a feature) ---- >

  String[] t1(String a) {
    String[] x = new String[1]; x[0] = a; return x;
  }
  String[] t2(String a, String b) {
    String[] x = new String[2]; x[0] = a; x[1] = b; return x;
  }
  String[] t3(String a, String b, String c) {
    String[] x = new String[3]; x[0]=a; x[1]=b; x[2]=c; return x;
  }
  String[] t4(String a, String b, String c, String d) {
    String[] x = new String[4]; x[0]=a; x[1]=b; x[2]=c; x[3]=d; return x;
  }
  String[] t6(String a, String b, String c, String d, String e, String f) {
    String[] x = new String[6]; x[0]=a; x[1]=b; x[2]=c; x[3]=d; x[4]=e; x[5]=f; return x;
  }

  void main() {
    print("=== SleelaDoc extractor demonstration ===");

    SLSleelaDoc doc = new SLSleelaDoc();
    doc.begin("Reason");

    < Feed the tokenized lines of the documented unit, in declaration order. >
    < class-level doc block >
    doc.feed(t2("<<", "@doc"), false);
    doc.feed(t3("@title", "Reason", ""), false);
    doc.feed(t6("@intent", "Model", "the", "smallest", "unit", "checkable."), false);
    doc.feed(t4("@axiom", "Checkable", "is", "knowledge."), false);
    doc.feed(t2("@evidence", "DERIVED"), false);
    doc.feed(t1(">>"), false);
    < the class declaration (upperInitial = true: "Reason") >
    doc.feed(t3("class", "Reason", "{"), true);

    < field doc (one-line) + the field declaration >
    doc.feed(t6("<", "@doc", "The", "confidence", "after", ">"), false);
    doc.feed(t2("int", "confidence"), false);

    < method doc block + the method declaration >
    doc.feed(t2("<<", "@doc"), false);
    doc.feed(t4("@intent", "Check", "and", "report."), false);
    doc.feed(t3("@returns", "the", "confidence."), false);
    doc.feed(t1(">>"), false);
    doc.feed(t4("int", "check", "(", ")"), false);

    print("members        : " + doc.memberCount());
    print("documented     : " + doc.documentedCount());

    print("");
    print("--- rendered Markdown API page ---");
    print(doc.toMarkdown());

    print("--- rendered HTML API fragment ---");
    print(doc.toHtml());

    print("=== demonstration complete ===");
  }
}