## 🎯 Checker/Analyzer拡張 ### ✅ 実装追加 - テストフレームワーク追加(tools/hako_check/tests/) - ルール改善(HC003グローバルassign、HC040静的箱トップレベルassign) - テストランナー(run_tests.sh) ### 🔧 Rust側修正 - AST utilities拡張(src/ast/utils.rs) - MIR lowerers新設(src/mir/lowerers/) - Parser制御フロー改善(src/parser/statements/control_flow.rs) - Tokenizer識別子処理改善(src/tokenizer/lex_ident.rs) ### 📁 主要変更 - tools/hako_check/cli.hako - CLI改善 - tools/hako_check/hako_source_checker.hako - Checker core更新 - tools/hako_check/tests/ - NEW (テストケース追加) - tools/hako_check/run_tests.sh - NEW (テストランナー) - src/mir/lowerers/ - NEW (MIR lowering utilities) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
40 lines
1.6 KiB
Plaintext
40 lines
1.6 KiB
Plaintext
using selfhost.shared.common.string_helpers as Str
|
||
|
||
static box RuleGlobalAssignBox {
|
||
apply(text, path, out) {
|
||
// HC010: global mutable state 禁止(top-levelの識別子= を雑に検出)
|
||
local lines = text.split("\n")
|
||
local in_box = 0; local in_method = 0
|
||
local i = 0; while i < lines.size() {
|
||
local ln = lines.get(i)
|
||
local t = me._ltrim(ln)
|
||
if t.indexOf("static box ") == 0 { in_box = 1; in_method = 0 }
|
||
if in_box == 1 && t == "}" { in_box = 0; in_method = 0 }
|
||
if in_box == 1 && t.indexOf("method ") == 0 { in_method = 1 }
|
||
if in_box == 1 && in_method == 0 {
|
||
// at top-level inside box: ident =
|
||
if me._looks_assign(t) == 1 {
|
||
out.push("[HC010] global assignment (top-level in box is forbidden): " + path + ":" + Str.int_to_str(i+1))
|
||
}
|
||
}
|
||
i = i + 1 }
|
||
}
|
||
_ltrim(s) { return me._ltrim_chars(s, " \t") }
|
||
_ltrim_chars(s, cs) {
|
||
local n=Str.len(s); local head=0
|
||
local i = 0; while i < n { local ch=s.substring(i,i+1); if ch!=" "&&ch!="\t" { head=i; break }; if i==n-1 { head=n }; i = i + 1 }
|
||
return s.substring(head)
|
||
}
|
||
_looks_assign(t) {
|
||
// very naive: identifier start followed by '=' somewhere (and not 'static box' or 'method')
|
||
if Str.len(t) < 3 { return 0 }
|
||
local c = t.substring(0,1)
|
||
if !((c>="A"&&c<="Z")||(c>="a"&&c<="z")||c=="_") { return 0 }
|
||
if t.indexOf("static box ") == 0 || t.indexOf("method ") == 0 { return 0 }
|
||
if t.indexOf("=") > 0 { return 1 }
|
||
return 0
|
||
}
|
||
}
|
||
|
||
static box RuleGlobalAssignMain { method main(args) { return 0 } }
|