It doesn't feel like Nim code because it has pointers, can you show me the Nim
way?
type
TokenKind = enum tokenNested, tokenSingle
Token = ref object
case kind: TokenKind
of tokenNested:
tokens: seq[Token]
of tokenSingle:
content: char
else: nil
proc tokenize(text: string): seq[Token] =
result = @[]
var current, latest: ptr seq[Token]
current = addr result
for it in text:
case it
of '[':
latest = current
let t = Token(kind: tokenNested, tokens: @[])
current = addr t.tokens
latest[].add(t)
of ']':
current = latest
of '>', '<', '+', '-', '.', ',':
current[].add(Token(kind: tokenSingle, content: it))