All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.skillw.asahi.internal.namespacing.infix.linking.InfixArray.kt Maven / Gradle / Ivy

There is a newer version: 1.6.7-beta-6
Show newest version
package com.skillw.asahi.internal.namespacing.infix.linking

import com.skillw.asahi.api.annotation.AsahiInfix
import com.skillw.asahi.api.member.parser.infix.namespacing.BaseInfix

/**
 * @className ActionArray
 *
 * @author Glom
 * @date 2022/8/9 16:26 Copyright 2022 user.
 */
@AsahiInfix
internal object InfixArray : BaseInfix>(Array::class.java) {
    init {
        //添加后缀动作        这个obj是当前操作的对象
        infix("get") { obj ->
            //预期下一个Token是 "at"
            expect("at")
            //          获取一个Int
            val index = parse()
            //返回结果
            return@infix obj[index]
        }

        infix("set") { obj ->
            obj as? Array ?: error("The tokenizer should be a Array")
            expect("at")
            val index = parse()
            expect("to")
            val value = parse()
            obj[index] = value
            return@infix value
        }
        infix("length") { it.size }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy