mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 23:47:50 +00:00
Add support for Paralithic let expressions
This commit is contained in:
parent
02fdcee705
commit
5e43f0afef
@ -5,7 +5,7 @@ object Versions {
|
||||
|
||||
object Libraries {
|
||||
const val tectonic = "4.2.1"
|
||||
const val paralithic = "0.7.1"
|
||||
const val paralithic = "0.8.1"
|
||||
const val strata = "1.3.2"
|
||||
|
||||
const val cloud = "2.0.0"
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@ -88,6 +89,8 @@ public class NoiseAddon implements AddonInitializer {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
ParseOptions expressionParseOptions = event.getPack().getExpressionParseOptions();
|
||||
|
||||
CheckedRegistry<Supplier<ObjectTemplate<NoiseSampler>>> noiseRegistry = event.getPack().getOrCreateRegistry(
|
||||
NOISE_SAMPLER_TOKEN);
|
||||
event.getPack()
|
||||
@ -98,7 +101,7 @@ public class NoiseAddon implements AddonInitializer {
|
||||
.applyLoader(DistanceSampler.DistanceFunction.class,
|
||||
(type, o, loader, depthTracker) -> DistanceSampler.DistanceFunction.valueOf((String) o))
|
||||
.applyLoader(DimensionApplicableNoiseSampler.class, DimensionApplicableNoiseSampler::new)
|
||||
.applyLoader(FunctionTemplate.class, FunctionTemplate::new)
|
||||
.applyLoader(FunctionTemplate.class, () -> new FunctionTemplate(expressionParseOptions))
|
||||
.applyLoader(CubicSpline.Point.class, CubicSplinePointTemplate::new)
|
||||
.applyLoader(DerivativeNoiseSampler.class, DerivativeNoiseSamplerTemplate::new);
|
||||
|
||||
@ -156,9 +159,9 @@ public class NoiseAddon implements AddonInitializer {
|
||||
|
||||
Map<String, DimensionApplicableNoiseSampler> packSamplers = new LinkedHashMap<>();
|
||||
Map<String, FunctionTemplate> packFunctions = new LinkedHashMap<>();
|
||||
noiseRegistry.register(addon.key("EXPRESSION"), () -> new ExpressionFunctionTemplate(packSamplers, packFunctions));
|
||||
noiseRegistry.register(addon.key("EXPRESSION"), () -> new ExpressionFunctionTemplate(packSamplers, packFunctions, expressionParseOptions));
|
||||
noiseRegistry.register(addon.key("EXPRESSION_NORMALIZER"),
|
||||
() -> new ExpressionNormalizerTemplate(packSamplers, packFunctions));
|
||||
() -> new ExpressionNormalizerTemplate(packSamplers, packFunctions, expressionParseOptions));
|
||||
|
||||
NoiseConfigPackTemplate template = event.loadTemplate(new NoiseConfigPackTemplate());
|
||||
packSamplers.putAll(template.getSamplers());
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.config.templates;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
@ -20,6 +21,8 @@ import com.dfsek.terra.api.config.meta.Meta;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class FunctionTemplate implements ObjectTemplate<FunctionTemplate> {
|
||||
private final ParseOptions parseOptions;
|
||||
|
||||
@Value("arguments")
|
||||
private List<String> args;
|
||||
|
||||
@ -30,6 +33,10 @@ public class FunctionTemplate implements ObjectTemplate<FunctionTemplate> {
|
||||
@Default
|
||||
private @Meta LinkedHashMap<String, @Meta FunctionTemplate> functions = new LinkedHashMap<>();
|
||||
|
||||
public FunctionTemplate(ParseOptions parseOptions) {
|
||||
this.parseOptions = parseOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionTemplate get() {
|
||||
return this;
|
||||
@ -47,6 +54,10 @@ public class FunctionTemplate implements ObjectTemplate<FunctionTemplate> {
|
||||
return functions;
|
||||
}
|
||||
|
||||
public ParseOptions getParseOptions() {
|
||||
return parseOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(this == o) return true;
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.config.templates.noise;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
@ -29,6 +30,7 @@ import static com.dfsek.terra.addons.noise.paralithic.FunctionUtil.convertFuncti
|
||||
public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFunction> {
|
||||
private final Map<String, DimensionApplicableNoiseSampler> globalSamplers;
|
||||
private final Map<String, FunctionTemplate> globalFunctions;
|
||||
private final ParseOptions parseOptions;
|
||||
@Value("variables")
|
||||
@Default
|
||||
private @Meta Map<String, @Meta Double> vars = new HashMap<>();
|
||||
@ -42,9 +44,11 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
||||
private @Meta LinkedHashMap<String, @Meta FunctionTemplate> functions = new LinkedHashMap<>();
|
||||
|
||||
public ExpressionFunctionTemplate(Map<String, DimensionApplicableNoiseSampler> globalSamplers,
|
||||
Map<String, FunctionTemplate> globalFunctions) {
|
||||
Map<String, FunctionTemplate> globalFunctions,
|
||||
ParseOptions parseOptions) {
|
||||
this.globalSamplers = globalSamplers;
|
||||
this.globalFunctions = globalFunctions;
|
||||
this.parseOptions = parseOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,7 +58,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
||||
var mergedSamplers = new HashMap<>(globalSamplers);
|
||||
mergedSamplers.putAll(samplers);
|
||||
try {
|
||||
return new ExpressionFunction(convertFunctionsAndSamplers(mergedFunctions, mergedSamplers), expression, vars);
|
||||
return new ExpressionFunction(convertFunctionsAndSamplers(mergedFunctions, mergedSamplers), expression, vars, parseOptions);
|
||||
} catch(ParseException e) {
|
||||
throw new RuntimeException("Failed to parse expression.", e);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.config.templates.normalizer;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
@ -29,6 +30,7 @@ public class ExpressionNormalizerTemplate extends NormalizerTemplate<ExpressionN
|
||||
|
||||
private final Map<String, DimensionApplicableNoiseSampler> globalSamplers;
|
||||
private final Map<String, FunctionTemplate> globalFunctions;
|
||||
private final ParseOptions parseOptions;
|
||||
|
||||
@Value("expression")
|
||||
private @Meta String expression;
|
||||
@ -46,9 +48,11 @@ public class ExpressionNormalizerTemplate extends NormalizerTemplate<ExpressionN
|
||||
private @Meta LinkedHashMap<String, @Meta FunctionTemplate> functions = new LinkedHashMap<>();
|
||||
|
||||
public ExpressionNormalizerTemplate(Map<String, DimensionApplicableNoiseSampler> globalSamplers,
|
||||
Map<String, FunctionTemplate> globalFunctions) {
|
||||
Map<String, FunctionTemplate> globalFunctions,
|
||||
ParseOptions parseOptions) {
|
||||
this.globalSamplers = globalSamplers;
|
||||
this.globalFunctions = globalFunctions;
|
||||
this.parseOptions = parseOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,7 +62,7 @@ public class ExpressionNormalizerTemplate extends NormalizerTemplate<ExpressionN
|
||||
var mergedSamplers = new HashMap<>(globalSamplers);
|
||||
mergedSamplers.putAll(samplers);
|
||||
try {
|
||||
return new ExpressionNormalizer(function, convertFunctionsAndSamplers(mergedFunctions, mergedSamplers), expression, vars);
|
||||
return new ExpressionNormalizer(function, convertFunctionsAndSamplers(mergedFunctions, mergedSamplers), expression, vars, parseOptions);
|
||||
} catch(ParseException e) {
|
||||
throw new RuntimeException("Failed to parse expression.", e);
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ package com.dfsek.terra.addons.noise.normalizer;
|
||||
|
||||
import com.dfsek.paralithic.Expression;
|
||||
import com.dfsek.paralithic.eval.parser.Parser;
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.paralithic.functions.Function;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
@ -15,12 +17,24 @@ public class ExpressionNormalizer extends Normalizer {
|
||||
|
||||
private final Expression expression;
|
||||
|
||||
public ExpressionNormalizer(NoiseSampler sampler, Map<String, Function> functions, String eq, Map<String, Double> vars)
|
||||
public ExpressionNormalizer(NoiseSampler sampler, Map<String, Function> functions, String eq, Map<String, Double> vars, ParseOptions parseOptions)
|
||||
throws ParseException {
|
||||
super(sampler);
|
||||
Parser p = new Parser();
|
||||
|
||||
Parser p = new Parser(parseOptions);
|
||||
Scope scope = new Scope();
|
||||
scope.addInvocationVariable("in");
|
||||
|
||||
// 'in' was used as the invocation variable but conflicts with
|
||||
// the new 'in' keyword in Paralithic used to denote the end of a let
|
||||
// expression. To maintain backwards compatibility but also enable the use
|
||||
// of let expressions, if they're enabled then use the longer 'input'
|
||||
// invocation variable instead.
|
||||
if (parseOptions.useLetExpressions()) {
|
||||
scope.addInvocationVariable("input");
|
||||
} else {
|
||||
scope.addInvocationVariable("in");
|
||||
}
|
||||
|
||||
vars.forEach(scope::create);
|
||||
functions.forEach(p::registerFunction);
|
||||
expression = p.parse(eq, scope);
|
||||
|
@ -35,7 +35,7 @@ public class UserDefinedFunction implements DynamicFunction {
|
||||
public static UserDefinedFunction newInstance(FunctionTemplate template) throws ParseException {
|
||||
UserDefinedFunction function = CACHE.get(template);
|
||||
if(function == null) {
|
||||
Parser parser = new Parser();
|
||||
Parser parser = new Parser(template.getParseOptions());
|
||||
Scope parent = new Scope();
|
||||
|
||||
Scope functionScope = new Scope().withParent(parent);
|
||||
|
@ -9,6 +9,7 @@ package com.dfsek.terra.addons.noise.samplers.noise;
|
||||
|
||||
import com.dfsek.paralithic.Expression;
|
||||
import com.dfsek.paralithic.eval.parser.Parser;
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.paralithic.functions.Function;
|
||||
@ -24,8 +25,8 @@ import com.dfsek.terra.addons.noise.paralithic.noise.SeedContext;
|
||||
public class ExpressionFunction extends NoiseFunction {
|
||||
private final Expression expression;
|
||||
|
||||
public ExpressionFunction(Map<String, Function> functions, String eq, Map<String, Double> vars) throws ParseException {
|
||||
Parser p = new Parser();
|
||||
public ExpressionFunction(Map<String, Function> functions, String eq, Map<String, Double> vars, ParseOptions parseOptions) throws ParseException {
|
||||
Parser p = new Parser(parseOptions);
|
||||
Scope scope = new Scope();
|
||||
|
||||
scope.addInvocationVariable("x");
|
||||
|
@ -2,6 +2,7 @@ package com.dfsek.terra.addons.numberpredicate;
|
||||
|
||||
import com.dfsek.paralithic.Expression;
|
||||
import com.dfsek.paralithic.eval.parser.Parser;
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
@ -15,6 +16,13 @@ import java.util.function.DoublePredicate;
|
||||
|
||||
|
||||
public class DoublePredicateLoader implements TypeLoader<DoublePredicate> {
|
||||
|
||||
private final ParseOptions parseOptions;
|
||||
|
||||
public DoublePredicateLoader(ParseOptions parseOptions) {
|
||||
this.parseOptions = parseOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoublePredicate load(@NotNull AnnotatedType annotatedType, @NotNull Object o, @NotNull ConfigLoader configLoader,
|
||||
DepthTracker depthTracker) throws LoadException {
|
||||
@ -22,7 +30,7 @@ public class DoublePredicateLoader implements TypeLoader<DoublePredicate> {
|
||||
Scope scope = new Scope();
|
||||
scope.addInvocationVariable("value");
|
||||
try {
|
||||
Expression expression = new Parser().parse(expressionString, scope);
|
||||
Expression expression = new Parser(parseOptions).parse(expressionString, scope);
|
||||
return d -> expression.evaluate(d) != 0; // Paralithic expressions treat '!= 0' as true
|
||||
} catch(ParseException e) {
|
||||
throw new LoadException("Failed to parse double predicate expression", e, depthTracker);
|
||||
|
@ -30,7 +30,7 @@ public class NumberPredicateAddon implements AddonInitializer {
|
||||
plugin.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> event.getPack().applyLoader(DoublePredicate.class, new DoublePredicateLoader()))
|
||||
.then(event -> event.getPack().applyLoader(DoublePredicate.class, new DoublePredicateLoader(event.getPack().getExpressionParseOptions())))
|
||||
.priority(50)
|
||||
.failThrough();
|
||||
}
|
||||
|
@ -8,4 +8,5 @@ dependencies {
|
||||
|
||||
api("com.github.ben-manes.caffeine", "caffeine", Versions.Libraries.caffeine)
|
||||
|
||||
api("com.dfsek", "paralithic", Versions.Libraries.paralithic)
|
||||
}
|
@ -13,6 +13,8 @@ import ca.solostudios.strata.version.VersionRange;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.properties.PropertyHolder;
|
||||
import com.dfsek.terra.api.registry.key.Keyed;
|
||||
@ -49,6 +51,8 @@ public interface ConfigPack extends LoaderRegistrar,
|
||||
|
||||
Version getVersion();
|
||||
|
||||
ParseOptions getExpressionParseOptions();
|
||||
|
||||
<T> ConfigPack registerShortcut(TypeKey<T> clazz, String shortcut, ShortcutLoader<T> loader);
|
||||
|
||||
default <T> ConfigPack registerShortcut(Class<T> clazz, String shortcut, ShortcutLoader<T> loader) {
|
||||
|
@ -19,6 +19,7 @@ package com.dfsek.terra.config;
|
||||
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import ca.solostudios.strata.version.VersionRange;
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
@ -31,6 +32,7 @@ import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.config.loaders.ExpressionParserOptionsTemplate;
|
||||
import com.dfsek.terra.config.loaders.LinkedHashMapLoader;
|
||||
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
||||
import com.dfsek.terra.config.loaders.ProbabilityCollectionLoader;
|
||||
@ -53,7 +55,8 @@ public class GenericLoaders implements LoaderRegistrar {
|
||||
.registerLoader(Version.class, new VersionLoader())
|
||||
.registerLoader(MaterialSet.class, new MaterialSetLoader())
|
||||
.registerLoader(VersionRange.class, new VersionRangeLoader())
|
||||
.registerLoader(LinkedHashMap.class, new LinkedHashMapLoader());
|
||||
.registerLoader(LinkedHashMap.class, new LinkedHashMapLoader())
|
||||
.registerLoader(ParseOptions.class, ExpressionParserOptionsTemplate::new);
|
||||
|
||||
if(platform != null) {
|
||||
registry.registerLoader(BaseAddon.class, platform.getAddons())
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
|
||||
public class ExpressionParserOptionsTemplate implements ObjectTemplate<ParseOptions> {
|
||||
|
||||
private static final ParseOptions DEFAULT_PARSE_OPTIONS = new ParseOptions();
|
||||
|
||||
@Value("use-let-expressions")
|
||||
@Default
|
||||
private boolean useLetExpressions = DEFAULT_PARSE_OPTIONS.useLetExpressions();
|
||||
|
||||
@Override
|
||||
public ParseOptions get() {
|
||||
return new ParseOptions(useLetExpressions);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.dfsek.terra.config.pack;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
|
||||
public class ConfigPackExpressionOptionsTemplate implements ConfigTemplate {
|
||||
@Value("expressions.options")
|
||||
@Default
|
||||
private ParseOptions parseOptions = new ParseOptions();
|
||||
|
||||
public ParseOptions getParseOptions() {
|
||||
return parseOptions;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ package com.dfsek.terra.config.pack;
|
||||
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import ca.solostudios.strata.version.VersionRange;
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.config.Configuration;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
@ -121,6 +122,8 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
private final RegistryKey key;
|
||||
|
||||
private final ParseOptions parseOptions;
|
||||
|
||||
public ConfigPackImpl(File folder, Platform platform) {
|
||||
this(new FolderLoader(folder.toPath()), Construct.construct(() -> {
|
||||
try {
|
||||
@ -176,6 +179,10 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
selfLoader.load(template, packManifest);
|
||||
|
||||
ConfigPackExpressionOptionsTemplate expressionOptionsTemplate = new ConfigPackExpressionOptionsTemplate();
|
||||
selfLoader.load(expressionOptionsTemplate, packManifest);
|
||||
this.parseOptions = expressionOptionsTemplate.getParseOptions();
|
||||
|
||||
String namespace;
|
||||
String id;
|
||||
if(template.getID().contains(":")) {
|
||||
@ -261,7 +268,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
selfLoader.registerPreprocessor(Meta.class, valuePreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, valuePreprocessor);
|
||||
|
||||
MetaNumberPreprocessor numberPreprocessor = new MetaNumberPreprocessor(configurations);
|
||||
MetaNumberPreprocessor numberPreprocessor = new MetaNumberPreprocessor(configurations, parseOptions);
|
||||
selfLoader.registerPreprocessor(Meta.class, numberPreprocessor);
|
||||
abstractConfigLoader.registerPreprocessor(Meta.class, numberPreprocessor);
|
||||
}
|
||||
@ -362,6 +369,11 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
return template.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseOptions getExpressionParseOptions() {
|
||||
return parseOptions;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked,rawtypes")
|
||||
@Override
|
||||
public <T> ConfigPack registerShortcut(TypeKey<T> clazz, String shortcut, ShortcutLoader<T> loader) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.dfsek.terra.config.preprocessor;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Parser;
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.tectonic.api.config.Configuration;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
@ -37,9 +38,11 @@ import java.util.Map;
|
||||
public class MetaNumberPreprocessor extends MetaPreprocessor<Meta> {
|
||||
public static final TypeKey<String> META_STRING_KEY = new TypeKey<@Meta String>() {
|
||||
};
|
||||
private final ParseOptions parseOptions;
|
||||
|
||||
public MetaNumberPreprocessor(Map<String, Configuration> configs) {
|
||||
public MetaNumberPreprocessor(Map<String, Configuration> configs, ParseOptions parseOptions) {
|
||||
super(configs);
|
||||
this.parseOptions = parseOptions;
|
||||
}
|
||||
|
||||
private static boolean isNumber(Class<?> clazz) {
|
||||
@ -57,7 +60,7 @@ public class MetaNumberPreprocessor extends MetaPreprocessor<Meta> {
|
||||
if(t.getType() instanceof Class && isNumber((Class<?>) t.getType()) && c instanceof String) {
|
||||
String expression = (String) loader.loadType(META_STRING_KEY.getAnnotatedType(), c, depthTracker);
|
||||
try {
|
||||
return (Result<T>) Result.overwrite(new Parser().eval(expression), depthTracker);
|
||||
return (Result<T>) Result.overwrite(new Parser(parseOptions).eval(expression), depthTracker);
|
||||
} catch(ParseException e) {
|
||||
throw new LoadException("Invalid expression: ", e, depthTracker);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.dfsek.paralithic.eval.parser.Parser.ParseOptions;
|
||||
import com.dfsek.tectonic.api.config.Configuration;
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
@ -32,7 +33,7 @@ public class MetaTest {
|
||||
loader.registerPreprocessor(Meta.class, new MetaStringPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap, new ParseOptions()));
|
||||
|
||||
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
|
||||
|
||||
@ -53,7 +54,7 @@ public class MetaTest {
|
||||
loader.registerPreprocessor(Meta.class, new MetaStringPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap, new ParseOptions()));
|
||||
|
||||
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
|
||||
|
||||
@ -75,7 +76,7 @@ public class MetaTest {
|
||||
loader.registerPreprocessor(Meta.class, new MetaStringPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap, new ParseOptions()));
|
||||
|
||||
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
|
||||
|
||||
@ -96,7 +97,7 @@ public class MetaTest {
|
||||
loader.registerPreprocessor(Meta.class, new MetaStringPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaListLikePreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaMapPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap));
|
||||
loader.registerPreprocessor(Meta.class, new MetaNumberPreprocessor(configurationMap, new ParseOptions()));
|
||||
|
||||
loader.registerPreprocessor(Meta.class, new MetaValuePreprocessor(configurationMap));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user