selfhosting-dev: finalize local changes post-rebase abort (dep_tree tools, runner, grammar); keep tmp deps json in-tree
This commit is contained in:
@ -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)
|
||||
|
||||
@ -50,7 +50,6 @@ pub static SYNTAX_ALLOWED_STATEMENTS: &[&str] = &[
|
||||
"print",
|
||||
"nowait",
|
||||
"include",
|
||||
"import",
|
||||
"local",
|
||||
"outbox",
|
||||
"try",
|
||||
|
||||
@ -438,7 +438,7 @@ impl NyashParser {
|
||||
self.consume(TokenType::RBRACE)?;
|
||||
self.skip_newlines();
|
||||
continue;
|
||||
} else if self.match_token(&TokenType::IDENTIFIER) {
|
||||
} else if matches!(self.current_token().token_type, TokenType::IDENTIFIER(_)) {
|
||||
// 単行形式: public name[: Type]
|
||||
let fname = if let TokenType::IDENTIFIER(n) = &self.current_token().token_type { n.clone() } else { unreachable!() };
|
||||
self.advance();
|
||||
|
||||
@ -115,47 +115,28 @@ impl NyashRunner {
|
||||
}
|
||||
return;
|
||||
}
|
||||
// CLI using/module overrides (MVP): apply early so JSON pipeline can observe them
|
||||
if self.config.using.is_some() || self.config.using_path.is_some() || self.config.modules.is_some()
|
||||
|| std::env::var("NYASH_USING_PATH").is_ok() || std::env::var("NYASH_MODULES").is_ok() {
|
||||
let mut using_paths: Vec<String> = Vec::new();
|
||||
if let Some(p) = self.config.using_path.clone() { for s in p.split(':') { let s=s.trim(); if !s.is_empty() { using_paths.push(s.to_string()); } } }
|
||||
if let Ok(p) = std::env::var("NYASH_USING_PATH") { for s in p.split(':') { let s=s.trim(); if !s.is_empty() { using_paths.push(s.to_string()); } } }
|
||||
if using_paths.is_empty() { using_paths.extend(["apps","lib","."].into_iter().map(|s| s.to_string())); }
|
||||
|
||||
// modules mapping
|
||||
let mut modules: Vec<(String,String)> = Vec::new();
|
||||
if let Some(m) = self.config.modules.clone() { for ent in m.split(',') { if let Some((k,v)) = ent.split_once('=') { let k=k.trim(); let v=v.trim(); if !k.is_empty() && !v.is_empty() { modules.push((k.to_string(), v.to_string())); } } } }
|
||||
if let Ok(ms) = std::env::var("NYASH_MODULES") { for ent in ms.split(',') { if let Some((k,v)) = ent.split_once('=') { let k=k.trim(); let v=v.trim(); if !k.is_empty() && !v.is_empty() { modules.push((k.to_string(), v.to_string())); } } } }
|
||||
for (ns, path) in &modules { let sb = crate::box_trait::StringBox::new(path.clone()); crate::runtime::modules_registry::set(ns.clone(), Box::new(sb)); }
|
||||
|
||||
// using specs
|
||||
let mut pending_using: Vec<(String, Option<String>, bool)> = Vec::new(); // (target, alias, is_path)
|
||||
if let Some(u) = self.config.using.clone() {
|
||||
for ent in u.split(',') {
|
||||
let s = ent.trim().trim_end_matches(';').trim(); if s.is_empty() { continue; }
|
||||
let (tgt, alias) = if let Some(pos) = s.find(" as ") { (s[..pos].trim().to_string(), Some(s[pos+4..].trim().to_string())) } else { (s.to_string(), None) };
|
||||
let is_path = tgt.starts_with('"') || tgt.starts_with("./") || tgt.starts_with('/') || tgt.ends_with(".nyash");
|
||||
pending_using.push((tgt.trim_matches('"').to_string(), alias, is_path));
|
||||
// Using/module overrides via env only (MVP)
|
||||
// Prepare shared accumulators for script/env processing
|
||||
let mut using_paths: Vec<String> = Vec::new();
|
||||
let mut pending_modules: Vec<(String, String)> = Vec::new();
|
||||
let mut pending_using: Vec<(String, Option<String>)> = Vec::new();
|
||||
// Using-paths from env, with defaults
|
||||
if let Ok(p) = std::env::var("NYASH_USING_PATH") {
|
||||
for s in p.split(':') { let s=s.trim(); if !s.is_empty() { using_paths.push(s.to_string()); } }
|
||||
}
|
||||
if using_paths.is_empty() { using_paths.extend(["apps","lib","."].into_iter().map(|s| s.to_string())); }
|
||||
// Modules mapping from env (e.g., FOO=path)
|
||||
if let Ok(ms) = std::env::var("NYASH_MODULES") {
|
||||
for ent in ms.split(',') {
|
||||
if let Some((k,v)) = ent.split_once('=') {
|
||||
let k=k.trim(); let v=v.trim();
|
||||
if !k.is_empty() && !v.is_empty() { pending_modules.push((k.to_string(), v.to_string())); }
|
||||
}
|
||||
}
|
||||
// Resolve using (priority: modules > relative(file) > using-paths; ambiguous=error if strict)
|
||||
let strict = std::env::var("NYASH_USING_STRICT").ok().as_deref() == Some("1");
|
||||
let verbose = std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1");
|
||||
let ctx = self.config.file.as_deref().and_then(|f| std::path::Path::new(f).parent());
|
||||
for (tgt, alias, is_path) in pending_using.into_iter() {
|
||||
if is_path && !std::path::Path::new(&tgt).exists() {
|
||||
if strict { eprintln!("❌ using: path not found: {}", tgt); std::process::exit(1); }
|
||||
if verbose { eprintln!("[using] path not found (continuing): {}", tgt); }
|
||||
}
|
||||
let value = match resolve_using_target(&tgt, is_path, &modules, &using_paths, ctx, strict, verbose) {
|
||||
Ok(v) => v,
|
||||
Err(e) => { eprintln!("❌ using: {}", e); std::process::exit(1); }
|
||||
};
|
||||
let sb = crate::box_trait::StringBox::new(value.clone());
|
||||
crate::runtime::modules_registry::set(tgt.clone(), Box::new(sb));
|
||||
if let Some(a) = alias { let sb2 = crate::box_trait::StringBox::new(value); crate::runtime::modules_registry::set(a, Box::new(sb2)); }
|
||||
}
|
||||
}
|
||||
for (ns, path) in pending_modules.iter() {
|
||||
let sb = crate::box_trait::StringBox::new(path.clone());
|
||||
crate::runtime::modules_registry::set(ns.clone(), Box::new(sb));
|
||||
}
|
||||
// Stage-1: Optional dependency tree bridge (log-only)
|
||||
if let Ok(dep_path) = std::env::var("NYASH_DEPS_JSON") {
|
||||
|
||||
Reference in New Issue
Block a user