selfhosting-dev: finalize local changes post-rebase abort (dep_tree tools, runner, grammar); keep tmp deps json in-tree

This commit is contained in:
Selfhosting Dev
2025-09-08 11:20:13 +09:00
parent f22082f67c
commit a45c22891c
4 changed files with 50 additions and 65 deletions

View File

@ -78,9 +78,7 @@ static box Main {
if in_cmt == 1 {
if ch == "\n" { in_cmt = 0 }
i = i + 1
continue
}
if in_str == 1 {
} else if in_str == 1 {
if ch == "\"" {
// if previous is not backslash, close
if i == 0 { in_str = 0 } else {
@ -89,24 +87,32 @@ static box Main {
}
}
i = i + 1
continue
}
// not in string/comment
if ch == "/" && i + 1 < n && src.substring(i+1, i+2) == "/" { in_cmt = 1; i = i + 2; continue }
if ch == "#" { in_cmt = 1; i = i + 1; continue }
if ch == "\"" { in_str = 1; i = i + 1; continue }
// look for include "
if i + 9 <= n && src.substring(i, i+9) == "include \"" {
} else if ch == "/" && i + 1 < n && src.substring(i+1, i+2) == "/" {
// start // comment
in_cmt = 1
i = i + 2
} else if ch == "#" {
// start # comment
in_cmt = 1
i = i + 1
} else if ch == "\"" {
// enter string
in_str = 1
i = i + 1
} else if i + 9 <= n && src.substring(i, i+9) == "include \"" {
// look for include "..."
local j = i + 9
// find closing quote (respect escapes)
loop(j < n) {
// find closing quote (respect escapes) without using break
local found = 0
loop(j < n && found == 0) {
if src.substring(j, j+1) == "\"" {
local prev = src.substring(j-1, j)
if prev != "\\" { break }
if prev != "\\" { found = 1 } else { j = j + 1 }
} else {
j = j + 1
}
j = j + 1
}
if j < n {
if found == 1 {
local p = src.substring(i+9, j)
if inc_first == 1 {
incs = incs + "\"" + me.esc_json(p) + "\""
@ -129,23 +135,22 @@ static box Main {
children = children + "," + cj
}
i = j + 1
continue
} else {
i = i + 1
}
} else {
i = i + 1
}
i = i + 1
}
return "{\\\"path\\\":\\\"" + me.esc_json(path) + "\\\",\\\"includes\\\":[" + incs + "],\\\"children\\\":[" + children + "]}"
}
main(args) {
local console = new ConsoleBox()
// Determine entry path (avoid stdin to keep VM path simple)
local entry = null
if args != null && args.length() >= 1 { entry = args.get(0) }
if entry == null || entry == "" {
// try stdin first line
local line = console.readLine()
if line != null && line != "" { entry = line } else { entry = "apps/selfhost/ny-parser-nyash/main.nyash" }
}
if entry == null || entry == "" { entry = "apps/selfhost/ny-parser-nyash/main.nyash" }
local tree = me.node_json(entry, "\n" + entry + "\n", 0)
local out = "{\\\"version\\\":1,\\\"root_path\\\":\\\"" + me.esc_json(entry) + "\\\",\\\"tree\\\":" + tree + "}"
console.println(out)