
use json

value scope_type_each (1)
value scope_type_if (2)

- class Scope {
    type: int
    parent: ?Scope (null)
    start: int
    start_line: int
    start_col: int
    list: Array[json:Value] (.{})
    index: int (0)
    list_keys: ?Array[String] (null)
    vname: String ("")
    kname: ?String (null)
    iname: ?String (null)
    ignore: bool (false)
    if_is_handled: bool (false)
    data: ?Map[json:Value] (null)

    fn set_list_index(index: uint) !range {
        this.index = index
        //
        let item = this.list.get(index) ! throw range
        let d = this.get_data()
        // Value
        d.set(this.vname, item)
        // Key
        let kname = this.kname
        if isset(kname) {
            let keys = this.list_keys
            if isset(keys) {
                let key = keys.get(index) !? index
                d.set(kname, json:new_string(key))
            } else {
                d.set(kname, json:new_int(index))
            }
        }
        // Index
        let iname = this.iname
        if isset(iname) : d.set(iname, json:new_int(index))
    }
    fn get_data() Map[json:Value] {
        let d = this.data
        if !isset(d) {
            d = .{}
            this.data = d
        }
        return d
    }
}
