all repos — min @ 5e73d2a9d74dc65bf5340f3df9847723307edefa

A small but practical concatenative programming language.

Implemented tokenize symbol.
h3rald h3rald@h3rald.com
Sat, 18 Nov 2023 14:47:28 +0100
commit

5e73d2a9d74dc65bf5340f3df9847723307edefa

parent

46ff68550d097a53f899146336ee807184d32982

1 files changed, 21 insertions(+), 0 deletions(-)

jump to
M minpkg/lib/min_lang.nimminpkg/lib/min_lang.nim

@@ -5,6 +5,7 @@ sequtils,

json, parseopt, algorithm, + streams, nre, os, logging]

@@ -1095,6 +1096,26 @@ def.symbol("quotecmd") do (i: In):

let vals = i.expect("str") let s = vals[0] i.push(@[newCmd(s.strVal)].newVal) + + def.symbol("tokenize") do (i: In): + let vals = i.expect("str") + let s = vals[0].getString + var i2 = i.copy("string") + i2.open(newStringStream(s), "string") + var p = i2.parser + var t = p.getToken() + var q = newSeq[MinValue](0) + var dict = newDict(i.scope) + i.dset(dict, "type", newVal($t)) + i.dset(dict, "value", p.a.newVal) + q.add dict + while t != tkEof: + t = p.getToken() + var dict = newDict(i.scope) + i.dset(dict, "type", newVal($t)) + i.dset(dict, "value", p.a.newVal) + q.add dict + i.push q.newVal # Sigils