More progress
This commit is contained in:
parent
63d7e13e11
commit
12b9a7a1be
60
dsl.nim
60
dsl.nim
|
@ -46,18 +46,29 @@ type
|
|||
i*: Option[string]
|
||||
u*: Option[string]
|
||||
|
||||
Penta*[T] = ref object
|
||||
Penta* = ref object
|
||||
spelling*: string
|
||||
name*: string
|
||||
exts*: Extremes
|
||||
elems*: array[V, T]
|
||||
elems*: array[V, Word]
|
||||
|
||||
BiExtremes* = object
|
||||
first*: Extremes
|
||||
second*: Extremes
|
||||
|
||||
Icosapenta* = ref object
|
||||
spelling*: string
|
||||
name*: string
|
||||
exts*: BiExtremes
|
||||
first*: array[V, Penta]
|
||||
second*: array[V, Penta]
|
||||
|
||||
Dictionary* = object
|
||||
glyphs*: seq[Glyph]
|
||||
dialects*: Table[string, seq[Replacement]]
|
||||
words*: seq[Word]
|
||||
pentas*: seq[Penta[Word]]
|
||||
icosipentas*: seq[Penta[Penta[Word]]]
|
||||
pentas*: seq[Penta]
|
||||
icosipentas*: seq[Icosapenta]
|
||||
|
||||
const
|
||||
Vowel2Char*: array[V, char] = [
|
||||
|
@ -73,6 +84,11 @@ proc replaceFirst(haystack: string, needle: char, content: char): string =
|
|||
result = haystack
|
||||
result[idx] = content
|
||||
|
||||
proc replaceLast(haystack: string, needle: char, content: char): string =
|
||||
let idx = haystack.rfind(needle)
|
||||
result = haystack
|
||||
result[idx] = content
|
||||
|
||||
macro makeposprocs(): untyped =
|
||||
result = nnkStmtList.newNimNode
|
||||
|
||||
|
@ -171,7 +187,7 @@ template dictionary*(body: untyped) =
|
|||
|
||||
template penta(ortho: string, pname: string, defns: untyped) =
|
||||
block:
|
||||
var p {.inject.}: Penta[Word] = Penta[Word](
|
||||
var p {.inject.}: Penta = Penta(
|
||||
spelling: ortho,
|
||||
name: pname,
|
||||
exts: Extremes(i: string.none, u: string.none)
|
||||
|
@ -201,15 +217,39 @@ template dictionary*(body: untyped) =
|
|||
|
||||
template icosipenta(iortho: string, iname: string, idefns: untyped) =
|
||||
block:
|
||||
var i {.inject.}: Penta[Penta[Word]] = Penta[Penta[Word]](
|
||||
var i {.inject.}: Icosapenta = Icosapenta(
|
||||
spelling: iortho,
|
||||
name: iname,
|
||||
exts: Extremes(i: string.none, u: string.none)
|
||||
exts: BiExtremes(
|
||||
first: Extremes(i: string.none, u: string.none),
|
||||
second: Extremes(i: string.none, u: string.none)
|
||||
)
|
||||
)
|
||||
for v in V:
|
||||
penta iortho.replaceFirst(' ', Vowel2Char[v]), Vowel2Char[v] & "x " & iname:
|
||||
i.elems[v] = p
|
||||
i.first[v] = p
|
||||
|
||||
penta iortho.replaceLast(' ', Vowel2Char[v]), "x" & Vowel2Char[v] & " " & iname:
|
||||
i.second[v] = p
|
||||
|
||||
proc firsts(i {.inject.}: string, u {.inject.}: string) {.used.} =
|
||||
i.exts.first.i = some(i)
|
||||
i.exts.first.u = some(u)
|
||||
|
||||
proc seconds(i {.inject.}: string, u {.inject.}: string) {.used.} =
|
||||
i.exts.second.i = some(i)
|
||||
i.exts.second.u = some(u)
|
||||
|
||||
template ix(defns2: untyped) {.used.} =
|
||||
edit_penta i.first[V_I]: defns2
|
||||
|
||||
# TODO: rest of the -x and x-, plus write edit_penta
|
||||
|
||||
template ii(defns2: untyped) {.used.} =
|
||||
edit_word i.first[V_I].elems[V_I]: defns2
|
||||
# TODO: check that this also edits i.second[V_I].elems[V_I]
|
||||
|
||||
# TODO: rest of the --
|
||||
|
||||
# NOTE: first extremes is exts, second extremes is elems[*].exts
|
||||
|
||||
|
@ -247,7 +287,7 @@ proc toJsonHook(exts: Extremes): JsonNode =
|
|||
result["u"] = newJString(exts.u.get)
|
||||
|
||||
|
||||
proc toJson(penta: Penta[Word], dict: Dictionary): JsonNode =
|
||||
proc toJson(penta: Penta, dict: Dictionary): JsonNode =
|
||||
result = newJObject()
|
||||
|
||||
result["extremes"] = penta.exts.toJson
|
||||
|
@ -255,7 +295,7 @@ proc toJson(penta: Penta[Word], dict: Dictionary): JsonNode =
|
|||
# TODO: Consider looking up i/e/a/o/u in dict
|
||||
|
||||
|
||||
proc toJson(pentas: seq[Penta[Word]], dict: Dictionary): JsonNode =
|
||||
proc toJson(pentas: seq[Penta], dict: Dictionary): JsonNode =
|
||||
result = newJObject()
|
||||
|
||||
for penta in pentas:
|
||||
|
|
Loading…
Reference in a new issue