// Phase 99: json_loader escape with trailing backslash
// Purpose: Exercise escape loop with incomplete escape sequence (trailing \).
//          This fixture documents current behavior: trailing \ is silently ignored.

static box Main {
    main() {
        // Input: "hello\" - string ending with backslash (incomplete escape)
        local s = "\"hello\\\\"
        local pos = 0
        local i = pos

        // Skip opening quote
        if s.substring(i, i + 1) != "\"" { return "NG" }
        i = i + 1

        local out = ""
        local n = s.length()

        loop(i < n) {
            local ch = s.substring(i, i + 1)
            if ch == "\"" { break }

            if ch == "\\" {
                i = i + 1
                if i < n {
                    ch = s.substring(i, i + 1)
                }
            }

            out = out + ch
            i = i + 1
        }

        // Current behavior: trailing backslash is included in output
        print(out)
        return "OK"
    }
}
