Alphabet.sleela
lib/alphabet/Alphabet.sleela · 161 line(s) · sleela
<< lib/alphabet/Alphabet.sleela
SLeeLa Standard Library Definition.
Definition: Defines Alphabet, the base writing-system Master Class a developer
extends to describe any ordered set of Letters — Latin, Greek, Cyrillic, or
a user's own invention. It is thematically important to ALL users of
Sleela: text is just an Alphabet, replayed.
A concrete alphabet is created exactly like a lib/compiler front end:
subclass Alphabet and override compose() to append its Letters in order. The
base provides the shared machinery — append(), letter lookup, vowel counting,
and the loadable-module contract — so a subclass only has to spell its own
letters.
Alphabet is a NATURAL / LOADABLE MODULE sharing the common module contract
(load / loaded / moduleName / describe). It owns an ordered run of Letters.
Syntax 1.8+: in addition to append(glyph, vowel), an Alphabet now accepts a
pre-built Letter via appendLetter(Letter) — the hook AlphabetBuilder uses to
add Letters constructed in one line with `new Letter(glyph, order, vowel)`.
The classic compose()/append() path is retained unchanged, so every existing
concrete alphabet (Latin / Greek / Cyrillic and any 1.3 subclass) keeps
working exactly as before.
Family: alphabet. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class Alphabet {
< ---- 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 = 10292;
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-07";
< 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; }
static final String MODULE = "Alphabet";
static final int MAX = 256;
int loadedFlag;
< e.g. "Latin", "Greek", "Cyrillic" >
String scriptName;
Letter[] letters;
int count;
< --- loadable-module contract ------------------------------------------ >
void load() {
loadedFlag = 1;
scriptName = "Unnamed";
letters = new Letter[MAX];
count = 0;
}
boolean loaded() { return loadedFlag == 1; }
String moduleName() { return MODULE; }
< A subclass calls this from its own setup to declare the script name, then >
< appends its letters via compose(). Mirrors the declare()/configure() >
< pattern used across the standard library. >
void begin(String name) {
load();
if (name != null) { scriptName = name; }
compose();
}
< Overridable: a concrete alphabet appends its Letters here, in order. The >
< base version writes nothing, so an un-overridden Alphabet is honestly empty. >
void compose() { }
< Append one letter. Vowel-ness is passed in because only the script knows. >
void append(String glyph, boolean vowel) {
if (count >= MAX) { return; }
Letter L = new Letter();
L.load();
L.set(glyph, count + 1, vowel);
letters[count] = L;
count = count + 1;
}
< Syntax 1.8+: append a pre-built Letter (e.g. one made with the Letter >
< constructor `new Letter(glyph, order, vowel)`). The letter's order is >
< normalised to its real position so a builder need not track indices. >
void appendLetter(Letter L) {
if (count >= MAX) { return; }
if (L == null) { return; }
L.set(L.symbol(), count + 1, L.isVowel());
letters[count] = L;
count = count + 1;
}
Letter at(int i) {
if (i < 0 || i >= count) { return null; }
return letters[i];
}
< The first letter whose glyph matches, or null. >
Letter find(String glyph) {
if (glyph == null) { return null; }
int i = 0;
while (i < count) {
if (letters[i].symbol() == glyph) { return letters[i]; }
i = i + 1;
}
return null;
}
boolean has(String glyph) { return find(glyph) != null; }
int vowelCount() {
int n = 0;
int i = 0;
while (i < count) {
if (letters[i].isVowel()) { n = n + 1; }
i = i + 1;
}
return n;
}
int consonantCount() { return count - vowelCount(); }
int size() { return count; }
String script() { return scriptName; }
String describe() {
return MODULE + "/" + scriptName + " letters=" + count
+ " vowels=" + vowelCount() + " consonants=" + consonantCount();
}
}