fix(muscript): prepare muscript-ast for muscript-runtime
This commit is contained in:
parent
111cd13de2
commit
8bddb34c22
|
@ -1,13 +1,29 @@
|
|||
package io.gitlab.jfronny.muscript.ast.context;
|
||||
|
||||
import io.gitlab.jfronny.muscript.ast.Expr;
|
||||
import io.gitlab.jfronny.muscript.core.MuScriptVersion;
|
||||
import io.gitlab.jfronny.muscript.core.SourceFS;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public interface IExprParser {
|
||||
IExprParser INSTANCE = ServiceLoader.load(IExprParser.class)
|
||||
.findFirst()
|
||||
.orElseGet(() -> expr -> { throw new UnsupportedOperationException(); });
|
||||
.orElseGet(() -> new IExprParser() {
|
||||
@Override
|
||||
public Expr parse(MuScriptVersion ver, String expr) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
Expr parse(String expr);
|
||||
@Override
|
||||
public Script parseMultiScript(MuScriptVersion version, String path, SourceFS filesystem) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
});
|
||||
|
||||
default Expr parse(String expr) {
|
||||
return parse(MuScriptVersion.DEFAULT, expr);
|
||||
}
|
||||
Expr parse(MuScriptVersion version, String expr);
|
||||
Script parseMultiScript(MuScriptVersion version, String path, SourceFS filesystem);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package io.gitlab.jfronny.muscript.ast.context;
|
||||
|
||||
public interface IScope {
|
||||
}
|
|
@ -20,4 +20,8 @@ public record Script(DynamicExpr content) {
|
|||
public Stream<Expr> stream() {
|
||||
return content instanceof ExprGroup group ? group.stream() : Stream.of(content);
|
||||
}
|
||||
|
||||
public Script concat(Script other) {
|
||||
return new Script(Stream.concat(this.stream(), other.stream()).toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.gitlab.jfronny.muscript.ast.extensible;
|
|||
|
||||
import io.gitlab.jfronny.muscript.ast.BoolExpr;
|
||||
import io.gitlab.jfronny.muscript.ast.Expr;
|
||||
import io.gitlab.jfronny.muscript.ast.context.IScope;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -15,4 +16,6 @@ public non-sealed interface ExtensibleBoolExpr extends BoolExpr, ExtensibleExpr
|
|||
default Stream<Expr> extractSideEffects() {
|
||||
return Stream.of(this);
|
||||
}
|
||||
|
||||
boolean evaluate(IScope scope);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package io.gitlab.jfronny.muscript.ast.extensible;
|
|||
|
||||
import io.gitlab.jfronny.muscript.ast.DynamicExpr;
|
||||
import io.gitlab.jfronny.muscript.ast.Expr;
|
||||
import io.gitlab.jfronny.muscript.ast.context.IScope;
|
||||
import io.gitlab.jfronny.muscript.core.IDynamic;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -15,4 +17,6 @@ public non-sealed interface ExtensibleDynamicExpr extends DynamicExpr, Extensibl
|
|||
default Stream<Expr> extractSideEffects() {
|
||||
return Stream.of(this);
|
||||
}
|
||||
|
||||
IDynamic evaluate(IScope scope);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.gitlab.jfronny.muscript.ast.extensible;
|
|||
|
||||
import io.gitlab.jfronny.muscript.ast.Expr;
|
||||
import io.gitlab.jfronny.muscript.ast.NumberExpr;
|
||||
import io.gitlab.jfronny.muscript.ast.context.IScope;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -15,4 +16,6 @@ public non-sealed interface ExtensibleNumberExpr extends NumberExpr, ExtensibleE
|
|||
default Stream<Expr> extractSideEffects() {
|
||||
return Stream.of(this);
|
||||
}
|
||||
|
||||
double evaluate(IScope scope);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.gitlab.jfronny.muscript.ast.extensible;
|
|||
|
||||
import io.gitlab.jfronny.muscript.ast.Expr;
|
||||
import io.gitlab.jfronny.muscript.ast.StringExpr;
|
||||
import io.gitlab.jfronny.muscript.ast.context.IScope;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -15,4 +16,6 @@ public non-sealed interface ExtensibleStringExpr extends StringExpr, ExtensibleE
|
|||
default Stream<Expr> extractSideEffects() {
|
||||
return Stream.of(this);
|
||||
}
|
||||
|
||||
String evaluate(IScope scope);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue