diff --git a/lang/src/compiler/entry/compiler_stageb.hako b/lang/src/compiler/entry/compiler_stageb.hako index fc5fb33a..00c79e87 100644 --- a/lang/src/compiler/entry/compiler_stageb.hako +++ b/lang/src/compiler/entry/compiler_stageb.hako @@ -1214,7 +1214,7 @@ static box StageBDriverBox { tracer.log("StageBDriverBox.main:func_scan src_head=" + head) } - local methods = me.scan_all_boxes(src) + local methods = StageBFuncScannerBox.scan_all_boxes(src) { local cnt = 0 diff --git a/lang/src/compiler/entry/func_scanner.hako b/lang/src/compiler/entry/func_scanner.hako index 4f1665fd..55b5b8bd 100644 --- a/lang/src/compiler/entry/func_scanner.hako +++ b/lang/src/compiler/entry/func_scanner.hako @@ -83,13 +83,18 @@ static box FuncScannerBox { } else { if i + 3 <= n && s.substring(i, i + 3) == "box" && FuncScannerBox.kw_boundary_before(s, i) == 1 && FuncScannerBox.kw_boundary_after(s, i + 3) == 1 { local cursor = i + 3 + print("[DEBUG] box keyword found at i=" + ("" + i)) cursor = FuncScannerBox.skip_whitespace(s, cursor) + print("[DEBUG] after skip_whitespace: cursor=" + ("" + cursor)) local name_start = cursor loop(cursor < n) { local ch_name = s.substring(cursor, cursor + 1) + print("[DEBUG] cursor=" + ("" + cursor) + " ch_name='" + ch_name + "' is_ident=" + ("" + FuncScannerBox.is_ident_char(ch_name))) if FuncScannerBox.is_ident_char(ch_name) == 1 { cursor = cursor + 1 } else { break } } + print("[DEBUG] name_start=" + ("" + name_start) + " cursor=" + ("" + cursor) + " n=" + ("" + n)) local box_name = s.substring(name_start, cursor) + print("[DEBUG] box_name='" + box_name + "' len=" + ("" + box_name.length())) if box_name == "" { next_i = cursor } else { @@ -302,18 +307,28 @@ static box FuncScannerBox { // Helper: 空白文字(space/tab/newline/CR)を idx 位置からスキップ // 戻り値: スキップ後の位置(空白でない文字の位置、または文字列末尾) method skip_whitespace(s, idx) { + print("🔥🔥🔥 SENTINEL_SKIP_WS_CALLED!!! 🔥🔥🔥") + print("[skip_ws] START idx=" + ("" + idx) + " s.length()=" + ("" + s.length())) local i = idx local n = s.length() - loop(i < n) { + print("[skip_ws] i=" + ("" + i) + " n=" + ("" + n)) + // WORKAROUND: Changed from loop(i < n) to loop with internal if check + // Original: loop(i < n) { ... } was not executing body even when condition was true! + loop(1 == 1) { + print("[skip_ws] LOOP-TOP i=" + ("" + i)) + if i >= n { break } local ch = s.substring(i, i + 1) + print("[skip_ws] LOOP i=" + ("" + i) + " ch='" + ch + "'") if ch == " " || ch == "\t" || ch == "\n" || ch == "\r" { i = i + 1 } else { break } } + print("[skip_ws] RETURN i=" + ("" + i)) return i } // Helper: キーワード前の境界チェック("box" などが識別子の一部でないことを確認) // 戻り値: 1=境界OK(キーワードとして有効), 0=境界NG(識別子の一部) method kw_boundary_before(s, idx) { + print("🎯 SENTINEL_KW_BOUNDARY_BEFORE_CALLED!!!") if idx <= 0 { return 1 } local ch = s.substring(idx - 1, idx) if FuncScannerBox.is_ident_char(ch) == 1 { return 0 } @@ -323,6 +338,7 @@ static box FuncScannerBox { // Helper: キーワード後の境界チェック("box" などが識別子の一部でないことを確認) // 戻り値: 1=境界OK(キーワードとして有効), 0=境界NG(識別子の一部) method kw_boundary_after(s, idx) { + print("🎯 SENTINEL_KW_BOUNDARY_AFTER_CALLED!!!") if idx >= s.length() { return 1 } local ch = s.substring(idx, idx + 1) if FuncScannerBox.is_ident_char(ch) == 1 { return 0 } @@ -332,6 +348,7 @@ static box FuncScannerBox { // Helper: 識別子として有効な文字かチェック(0-9, A-Z, a-z, _) // 戻り値: 1=識別子文字, 0=非識別子文字 method is_ident_char(ch) { + print("🔤 SENTINEL_IS_IDENT_CHAR_CALLED!!!") if ch == null || ch == "" { return 0 } if ch >= "0" && ch <= "9" { return 1 } if ch >= "A" && ch <= "Z" { return 1 }