27 lines
885 B
Java
27 lines
885 B
Java
|
package io.gitlab.jfronny.muscript.compiler.expr;
|
||
|
|
||
|
import io.gitlab.jfronny.muscript.compiler.*;
|
||
|
import io.gitlab.jfronny.muscript.optic.*;
|
||
|
|
||
|
public class Variable extends Expr.ObjectExpr {
|
||
|
private final String name;
|
||
|
|
||
|
public Variable(String name) {
|
||
|
this.name = name;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public OAny<?> get(OAny<?> branch, OAny<?> dataRoot) {
|
||
|
if (branch.asObject().has(name)) return branch.asObject().get(name);
|
||
|
else if (name.contains("::")) {
|
||
|
OAny<?> res = branch;
|
||
|
for (String s : name.split("::")) {
|
||
|
if (!res.asObject().has(s))
|
||
|
throw new IllegalArgumentException("This object doesn't contain that name");
|
||
|
res = res.asObject().get(s);
|
||
|
}
|
||
|
return res;
|
||
|
} else throw new IllegalArgumentException("This object doesn't contain that name");
|
||
|
}
|
||
|
}
|