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]
|
i*: Option[string]
|
||||||
u*: Option[string]
|
u*: Option[string]
|
||||||
|
|
||||||
Penta*[T] = ref object
|
Penta* = ref object
|
||||||
spelling*: string
|
spelling*: string
|
||||||
name*: string
|
name*: string
|
||||||
exts*: Extremes
|
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
|
Dictionary* = object
|
||||||
glyphs*: seq[Glyph]
|
glyphs*: seq[Glyph]
|
||||||
dialects*: Table[string, seq[Replacement]]
|
dialects*: Table[string, seq[Replacement]]
|
||||||
words*: seq[Word]
|
words*: seq[Word]
|
||||||
pentas*: seq[Penta[Word]]
|
pentas*: seq[Penta]
|
||||||
icosipentas*: seq[Penta[Penta[Word]]]
|
icosipentas*: seq[Icosapenta]
|
||||||
|
|
||||||
const
|
const
|
||||||
Vowel2Char*: array[V, char] = [
|
Vowel2Char*: array[V, char] = [
|
||||||
|
@ -73,6 +84,11 @@ proc replaceFirst(haystack: string, needle: char, content: char): string =
|
||||||
result = haystack
|
result = haystack
|
||||||
result[idx] = content
|
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 =
|
macro makeposprocs(): untyped =
|
||||||
result = nnkStmtList.newNimNode
|
result = nnkStmtList.newNimNode
|
||||||
|
|
||||||
|
@ -171,7 +187,7 @@ template dictionary*(body: untyped) =
|
||||||
|
|
||||||
template penta(ortho: string, pname: string, defns: untyped) =
|
template penta(ortho: string, pname: string, defns: untyped) =
|
||||||
block:
|
block:
|
||||||
var p {.inject.}: Penta[Word] = Penta[Word](
|
var p {.inject.}: Penta = Penta(
|
||||||
spelling: ortho,
|
spelling: ortho,
|
||||||
name: pname,
|
name: pname,
|
||||||
exts: Extremes(i: string.none, u: string.none)
|
exts: Extremes(i: string.none, u: string.none)
|
||||||
|
@ -201,15 +217,39 @@ template dictionary*(body: untyped) =
|
||||||
|
|
||||||
template icosipenta(iortho: string, iname: string, idefns: untyped) =
|
template icosipenta(iortho: string, iname: string, idefns: untyped) =
|
||||||
block:
|
block:
|
||||||
var i {.inject.}: Penta[Penta[Word]] = Penta[Penta[Word]](
|
var i {.inject.}: Icosapenta = Icosapenta(
|
||||||
spelling: iortho,
|
spelling: iortho,
|
||||||
name: iname,
|
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:
|
for v in V:
|
||||||
penta iortho.replaceFirst(' ', Vowel2Char[v]), Vowel2Char[v] & "x " & iname:
|
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
|
# 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)
|
result["u"] = newJString(exts.u.get)
|
||||||
|
|
||||||
|
|
||||||
proc toJson(penta: Penta[Word], dict: Dictionary): JsonNode =
|
proc toJson(penta: Penta, dict: Dictionary): JsonNode =
|
||||||
result = newJObject()
|
result = newJObject()
|
||||||
|
|
||||||
result["extremes"] = penta.exts.toJson
|
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
|
# 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()
|
result = newJObject()
|
||||||
|
|
||||||
for penta in pentas:
|
for penta in pentas:
|
||||||
|
|
Loading…
Reference in a new issue