package io.gitlab.jfronny.muscript.compiler.expr.dynamic; import io.gitlab.jfronny.muscript.compiler.expr.*; import io.gitlab.jfronny.muscript.compiler.expr.annotations.*; import io.gitlab.jfronny.muscript.dynamic.*; import io.gitlab.jfronny.muscript.error.*; @CanThrow @UncheckedDynamic public class Variable extends DynamicExpr { private final String name; public Variable(int character, String name) { super(character); this.name = name; } @Override public Dynamic get(Dynamic dataRoot) { if (dataRoot.asObject().has(name)) return dataRoot.asObject().get(name); else if (name.contains("::")) { Dynamic res = dataRoot; for (String s : name.split("::")) { if (!res.asObject().has(s)) throw new LocationalException(character, "This object doesn't contain that name"); res = res.asObject().get(s); } return res; } else throw new LocationalException(character, "This object doesn't contain that name"); } }