From a1bd922ef46440a2bf99d7ee4e44749e10d9e66d Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sat, 12 Jul 2025 22:28:56 +0200 Subject: improve repl --- mp | 65 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/mp b/mp index 6bd2fdf..816994c 100755 --- a/mp +++ b/mp @@ -10,45 +10,38 @@ BEGIN { " Prints cmd help or general help text.\n" \ " Example: help help\n" +SUBSEP="." filename = ARGV[1] ARGV[1] = "/dev/stdin" tty = 1 - system("test -t 0") if (filename) src = getfile(filename) - prompt("mp-" version " meta parser. Type \"help\" for help.\n") -} -{ ERROR = "" } -$1 == "help" { - prompt(help[$2]) - next -} -$1 == "src" { - printf "%s", src - prompt() - next -} -$1 == "read" { - sub(/^[[:space:]]+/, "") - $0 = substr($0, 6) - src = getfile($0) - prompt() - next -} -$1 == "format" { - print format_json(v, "", $2) - prompt() - next -} -$1 == "parse" { - delete v - sub(/^[[:space:]]+/, "") - $0 = substr($0, 7) - if ($0) src = $0 - parse_json(src, v) - prompt() - next + prompt("mp-" version " meta parser. Try \"help\".\n") } { - if (NF) error("invalid command: " $1) + ERROR = "" + if ($1 == "help") { + print help[$2] + } else if ($1 == "src") { + printf "%s", src + } else if ($1 == "format") { + print format_json(v, "", $2) + } else if ($1 == "key") { + key(v, $2) + } else if ($1 == "keys") { + for (k in v) print k + } else if ($1 == "parse") { + delete v + sub(/^[[:space:]]+/, "") + $0 = substr($0, 7) + if ($0) src = $0 + parse_json(src, v) + } else if ($1 == "read") { + sub(/^[[:space:]]+/, "") + $0 = substr($0, 6) + src = getfile($0) + } else if (NF) { + error("invalid command: " $1) + } prompt() } END { if (ERROR) exit 1 } @@ -160,3 +153,9 @@ function space(n, i, s) { for (i = 0; i < n; i++) s = s " " return s } + +function key(a, s, p, k) { + print "# s:" s + if (a[p, "type"] == "object") { + } +} -- cgit v1.2.3