import reports imports

This commit is contained in:
gnembon committed 2020-01-10 17:31:26 -04:00
1 parent a841755d61
commit 953dd1c2a5
2 files changed
+21 -3

No files matched your search

+6 -2
View File
@@ -857,11 +857,15 @@ public class Expression
// artificial construct to handle user defined functions and function definitions // artificial construct to handle user defined functions and function definitions
addLazyFunction("import", -1, (c, t, lv) -> addLazyFunction("import", -1, (c, t, lv) ->
{ {
if (lv.size() < 2) throw new InternalExpressionException("'import' needs at least a module name to import, and list of values to import"); if (lv.size() < 1) throw new InternalExpressionException("'import' needs at least a module name to import, and list of values to import");
String moduleName = lv.get(0).evalValue(c).getString(); String moduleName = lv.get(0).evalValue(c).getString();
c.host.importModule(c, moduleName); c.host.importModule(c, moduleName);
if (lv.size() > 1)
c.host.importNames(c, module, moduleName, lv.subList(1, lv.size()).stream().map((l) -> l.evalValue(c).getString()).collect(Collectors.toList())); c.host.importNames(c, module, moduleName, lv.subList(1, lv.size()).stream().map((l) -> l.evalValue(c).getString()).collect(Collectors.toList()));
return (cc, tt) -> Value.NULL; if (t == Context.VOID)
return LazyValue.NULL;
ListValue list = ListValue.wrap(c.host.availableImports(moduleName).map(StringValue::new).collect(Collectors.toList()));
return (cc, tt) -> list;
}); });
addLazyFunctionWithDelegation("call",-1, (c, t, expr, tok, lv) -> { // adjust based on c addLazyFunctionWithDelegation("call",-1, (c, t, expr, tok, lv) -> { // adjust based on c
+15 -1
View File
@@ -14,7 +14,7 @@ import java.util.stream.Stream;
public abstract class ScriptHost public abstract class ScriptHost
{ {
public class ModuleData public static class ModuleData
{ {
Module parent; Module parent;
public Map<String, FunctionValue> globalFunctions = new Object2ObjectOpenHashMap<>(); public Map<String, FunctionValue> globalFunctions = new Object2ObjectOpenHashMap<>();
@@ -134,6 +134,20 @@ public abstract class ScriptHost
} }
} }
public Stream<String> availableImports(String moduleName)
{
Module source = modules.get(moduleName);
ModuleData sourceData = moduleData.get(source);
if (sourceData == null)
{
throw new InternalExpressionException("Cannot import from module that is not imported");
}
return Stream.concat(
globaVariableNames(source, s -> s.startsWith("global_")),
globaFunctionNames(source, s -> true)
).distinct().sorted();
}
protected abstract Module getModuleOrLibraryByName(String name); // this should be shell out in the executor protected abstract Module getModuleOrLibraryByName(String name); // this should be shell out in the executor
protected abstract void runModuleCode(Context c, Module module); // this should be shell out in the executor protected abstract void runModuleCode(Context c, Module module); // this should be shell out in the executor