summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2025-07-12 22:28:56 +0200
committerMarc Vertes <mvertes@free.fr>2025-07-12 22:28:56 +0200
commita1bd922ef46440a2bf99d7ee4e44749e10d9e66d (patch)
tree400cd4d73e64545690486c6dd83fcc23e6c967f2
parentf89f3d28a14d0d8ea8c02acf115c9c1c972b70cf (diff)
improve repl
-rwxr-xr-xmp65
1 files 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") {
+ }
+}