refactor(stageb): Phase 25.3 FuncScanner boxification完了
- FuncScannerBox helper SSOT確立(8個のhelperに詳細コメント追加) - StageBFuncScannerBox → FuncScannerBox完全委譲(約380行削減) - scan_all_boxes状態フラグ整理(4つの状態遷移を明確化) - 常時出力print削除(dev専用ログのみ保持) - SSAテスト全pass(mir_funcscanner_scan_methods/fib_min) Phase 25.3-B完了、次はfib defs canary緑化へ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -20,6 +20,13 @@ static box FuncScannerBox {
|
||||
local s = "" + source
|
||||
local n = s.length()
|
||||
local i = 0
|
||||
// ────────────────────────────────────────────────────────────
|
||||
// State flags: コメント/文字列スキップ状態管理(4本)
|
||||
// ────────────────────────────────────────────────────────────
|
||||
// in_str: 文字列リテラル内("..." の中)= 1, それ以外 = 0
|
||||
// esc: 文字列内エスケープ直後(次の文字をスキップ)= 1, それ以外 = 0
|
||||
// in_line: 行コメント内(// から改行まで)= 1, それ以外 = 0
|
||||
// in_block: ブロックコメント内(/* から */ まで)= 1, それ以外 = 0
|
||||
local in_str = 0
|
||||
local esc = 0
|
||||
local in_line = 0
|
||||
@ -31,33 +38,48 @@ static box FuncScannerBox {
|
||||
local next_i = i + 1
|
||||
local ch = s.substring(i, i + 1)
|
||||
|
||||
// ────────────────────────────────────────────────────────────
|
||||
// State 1: 行コメントモード(// から改行まで)
|
||||
// ────────────────────────────────────────────────────────────
|
||||
if in_line == 1 {
|
||||
if ch == "\n" { in_line = 0 }
|
||||
if ch == "\n" { in_line = 0 } // 改行で行コメント終了
|
||||
// ────────────────────────────────────────────────────────────
|
||||
// State 2: ブロックコメントモード(/* から */ まで)
|
||||
// ────────────────────────────────────────────────────────────
|
||||
} else if in_block == 1 {
|
||||
if ch == "*" && i + 1 < n && s.substring(i + 1, i + 2) == "/" {
|
||||
in_block = 0
|
||||
in_block = 0 // */ でブロックコメント終了
|
||||
next_i = i + 2
|
||||
}
|
||||
// ────────────────────────────────────────────────────────────
|
||||
// State 3: 文字列リテラルモード("..." の中)
|
||||
// ────────────────────────────────────────────────────────────
|
||||
} else if in_str == 1 {
|
||||
if esc == 1 {
|
||||
esc = 0
|
||||
esc = 0 // エスケープ直後文字処理完了
|
||||
} else if ch == "\\" {
|
||||
esc = 1
|
||||
esc = 1 // バックスラッシュでエスケープ開始
|
||||
} else if ch == "\"" {
|
||||
in_str = 0
|
||||
in_str = 0 // 閉じクォートで文字列終了
|
||||
}
|
||||
// ────────────────────────────────────────────────────────────
|
||||
// State 4: 通常モード(コメント/文字列の外)→ box キーワード検出
|
||||
// ────────────────────────────────────────────────────────────
|
||||
} else {
|
||||
// 文字列リテラル開始(" 検出)
|
||||
if ch == "\"" {
|
||||
in_str = 1
|
||||
in_str = 1 // 文字列モードへ遷移
|
||||
// コメント開始判定(/ の次の文字で行/ブロック判別)
|
||||
} else if ch == "/" && i + 1 < n {
|
||||
local ch2 = s.substring(i + 1, i + 2)
|
||||
if ch2 == "/" {
|
||||
in_line = 1
|
||||
in_line = 1 // 行コメントモードへ遷移(// 検出)
|
||||
next_i = i + 2
|
||||
} else if ch2 == "*" {
|
||||
in_block = 1
|
||||
in_block = 1 // ブロックコメントモードへ遷移(/* 検出)
|
||||
next_i = i + 2
|
||||
}
|
||||
// box キーワード検出(境界チェック付き)
|
||||
} else {
|
||||
if i + 3 <= n && s.substring(i, i + 3) == "box" && me._kw_boundary_before(s, i) == 1 && me._kw_boundary_after(s, i + 3) == 1 {
|
||||
local cursor = i + 3
|
||||
@ -272,6 +294,13 @@ static box FuncScannerBox {
|
||||
}
|
||||
}
|
||||
|
||||
// ────────────────────────────────────────────────────────────
|
||||
// Core Text Scanning Helpers (SSOT: single source of truth)
|
||||
// Stage-B および他の箱からも参照される共通処理群
|
||||
// ────────────────────────────────────────────────────────────
|
||||
|
||||
// Helper: 空白文字(space/tab/newline/CR)を idx 位置からスキップ
|
||||
// 戻り値: スキップ後の位置(空白でない文字の位置、または文字列末尾)
|
||||
method _skip_whitespace(s, idx) {
|
||||
local i = idx
|
||||
local n = s.length()
|
||||
@ -282,6 +311,8 @@ static box FuncScannerBox {
|
||||
return i
|
||||
}
|
||||
|
||||
// Helper: キーワード前の境界チェック("box" などが識別子の一部でないことを確認)
|
||||
// 戻り値: 1=境界OK(キーワードとして有効), 0=境界NG(識別子の一部)
|
||||
method _kw_boundary_before(s, idx) {
|
||||
if idx <= 0 { return 1 }
|
||||
local ch = s.substring(idx - 1, idx)
|
||||
@ -289,6 +320,8 @@ static box FuncScannerBox {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Helper: キーワード後の境界チェック("box" などが識別子の一部でないことを確認)
|
||||
// 戻り値: 1=境界OK(キーワードとして有効), 0=境界NG(識別子の一部)
|
||||
method _kw_boundary_after(s, idx) {
|
||||
if idx >= s.length() { return 1 }
|
||||
local ch = s.substring(idx, idx + 1)
|
||||
@ -296,6 +329,8 @@ static box FuncScannerBox {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Helper: 識別子として有効な文字かチェック(0-9, A-Z, a-z, _)
|
||||
// 戻り値: 1=識別子文字, 0=非識別子文字
|
||||
method _is_ident_char(ch) {
|
||||
if ch == null || ch == "" { return 0 }
|
||||
if ch >= "0" && ch <= "9" { return 1 }
|
||||
@ -362,7 +397,9 @@ static box FuncScannerBox {
|
||||
return -1
|
||||
}
|
||||
|
||||
// Helper: parse comma-separated parameter names
|
||||
// Helper: カンマ区切りパラメータリストをパース(例: "a, b, c" → ["a", "b", "c"])
|
||||
// FuncScannerBox._trim を使用(static helper パターン)
|
||||
// 戻り値: ArrayBox(トリム済みパラメータ名のリスト)
|
||||
method _parse_params(params_str) {
|
||||
local params = new ArrayBox()
|
||||
local pstr = "" + params_str
|
||||
@ -395,7 +432,8 @@ static box FuncScannerBox {
|
||||
return params
|
||||
}
|
||||
|
||||
// Helper: strip comments from source
|
||||
// Helper: "//" と "/* */" コメントを削除(文字列リテラル内は保持、改行は保持)
|
||||
// 戻り値: コメント削除後のソースコード(null の場合は空文字)
|
||||
method _strip_comments(source) {
|
||||
// source が null の場合はそのまま空文字として扱う(コメント除去する対象がないだけ)
|
||||
if source == null { return "" }
|
||||
@ -439,7 +477,8 @@ static box FuncScannerBox {
|
||||
return out
|
||||
}
|
||||
|
||||
// Helper: trim whitespace
|
||||
// Helper: 前後の空白文字(space/tab/newline/CR)を削除
|
||||
// 戻り値: トリム済み文字列(null の場合は空文字)
|
||||
method _trim(s) {
|
||||
if s == null { return "" }
|
||||
local str = "" + s
|
||||
|
||||
Reference in New Issue
Block a user