SLDocumentNaming.sleela
lib/sldocument/SLDocumentNaming.sleela · 136 line(s) · sleela
<< lib/sldocument/SLDocumentNaming.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLDocumentNaming, the naming convention that compares a
.sleela to a .sldocument and synthesizes function names where a document
step lacks one.
Why this exists:
A .sldocument may NOT have names for its functions — a step can be an
anonymous ordered operation (identified only by its position or role). That
is fine while it runs as a document. But if an engineer converts a
.sldocument to a .sleela for safekeeping, every step must become a named
method, because .sleela is class/method shaped. This class is the authority
on how an anonymous or role-only step is given a stable, legal .sleela
method name.
Convention (deterministic, so a conversion is reproducible):
1. If the step has an explicit method name, keep it (sanitized).
2. Else if it has a @function role, derive the name from the role
(e.g. "reconcile accounts" -> "reconcileAccounts").
3. Else synthesize from the ordered position: "step" + zero-padded order
(e.g. order 3 -> "step003"), which is stable and collision-resistant.
A synthesized or derived name is always a legal SLeeLa identifier.
Family: sldocument. Native VM/OS work crosses an explicit bridge. >>
#sleela 2.5
material;
< Unified SLeeLa standard-library front-end object. >
class SLDocumentNaming {
< ---- 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 = 10072;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-10-16";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-10-05";
< 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; }
< prefix for synthesized names (default "step") >
String prefix;
int state;
void configure() { prefix = "step"; state = 1; }
void withPrefix(String p) { prefix = p; }
boolean active() { return state == 1; }
< Does the step already carry an explicit method name (vs. being anonymous)? >
boolean isNamed(SLDocumentAnnotation ann) {
if (ann == null) { return false; }
if (ann.kindOf() == SLDocumentAnnotation.METHOD) {
String m = ann.method();
return m != null && m.length() > 0;
}
< ORDER/FUNCTION annotations may still carry a method identifier. >
String m = ann.method();
return m != null && m.length() > 0;
}
< Produce the stable .sleela method name for a step, per the convention. >
< `textualPosition` is the step's 1-based top-down position used when a name >
< must be synthesized. >
String nameFor(SLDocumentAnnotation ann, int textualPosition) {
if (!active()) { return ""; }
< 1. explicit method name wins (sanitized to a legal identifier). >
if (ann != null) {
String m = ann.method();
if (m != null && m.length() > 0) { return sanitize(m); }
< 2. derive from a @function role. >
if (ann.kindOf() == SLDocumentAnnotation.FUNCTION) {
String role = ann.role_();
if (role != null && role.length() > 0) {
String derived = camelFromRole(role);
if (derived.length() > 0) { return derived; }
}
}
}
< 3. synthesize from ordered position: prefix + zero-padded order. >
int ord = textualPosition;
if (ann != null && ann.hasExplicitOrder()) { ord = ann.orderValue(); }
return native sleela_sldocument_synth_name(prefix, ord);
}
< Was this name synthesized (vs. authored by the engineer)? >
boolean isSynthesized(SLDocumentAnnotation ann) {
if (ann == null) { return true; }
String m = ann.method();
if (m != null && m.length() > 0) { return false; }
if (ann.kindOf() == SLDocumentAnnotation.FUNCTION) {
String role = ann.role_();
if (role != null && role.length() > 0) { return false; }
}
return true;
}
< Make an arbitrary string a legal SLeeLa identifier. >
String sanitize(String raw) {
return native sleela_sldocument_sanitize_identifier(raw);
}
< Turn a human role ("reconcile accounts") into camelCase ("reconcileAccounts"). >
String camelFromRole(String role) {
return native sleela_sldocument_camel_from_role(role);
}
}