38 lines
802 B
Nim
38 lines
802 B
Nim
import std/macros
|
|
import std/genasts
|
|
|
|
type
|
|
VowelAttribute* = enum Outer, Slashed, Inner
|
|
GlyphKind* = enum Vowel
|
|
Glyph* = object
|
|
spelling*: string
|
|
case kind*: GlyphKind
|
|
of Vowel: vattrs*: set[VowelAttribute]
|
|
|
|
Dictionary* = object
|
|
glyphs*: seq[Glyph]
|
|
|
|
template dictionary*(body: untyped) =
|
|
var dict {.inject.}: Dictionary
|
|
dict.glyphs = @[]
|
|
|
|
macro vowel(arg: untyped) =
|
|
var v: Glyph = Glyph(spelling: arg[0].strVal)
|
|
echo arg.treeRepr
|
|
|
|
# TODO: populate attributes of v, then implement similar for other glyphs
|
|
|
|
let x = newLit(v)
|
|
result = genAst(x):
|
|
dict.glyphs.add `x`
|
|
|
|
echo result.repr
|
|
|
|
body
|
|
|
|
when isMainModule:
|
|
dictionary:
|
|
vowel "x" outer slashed inner
|
|
|
|
echo dict
|