removed inspector

This commit is contained in:
gnembon committed 2020-03-17 10:14:36 -03:00
1 parent d93a0dbdf4
commit b041e05b47
8 files changed
+54 -86

No files matched your search

@@ -1,14 +1,8 @@
package carpet.commands;
import carpet.CarpetServer;
import carpet.script.CarpetScriptHost;
import carpet.script.*;
import carpet.CarpetSettings;
import carpet.script.CarpetEventServer;
import carpet.script.CarpetExpression;
import carpet.script.Expression;
import carpet.script.ExpressionInspector;
import carpet.script.LazyValue;
import carpet.script.Tokenizer;
import carpet.script.exception.CarpetExpressionException;
import carpet.script.value.FunctionValue;
import carpet.settings.SettingsManager;
@@ -31,11 +25,9 @@ import net.minecraft.util.Clearable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockBox;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
import java.util.function.Supplier;
@@ -47,6 +39,33 @@ import static net.minecraft.server.command.CommandSource.suggestMatching;
public class ScriptCommand
{
private static TreeSet<String> scarpetFunctions;
private static TreeSet<String> APIFunctions;
static
{
Set<String> allFunctions = (new CarpetExpression(null, "null", null, null)).getExpr().getFunctionNames();
scarpetFunctions = new TreeSet<>(Expression.none.getFunctionNames());
APIFunctions = allFunctions.stream().filter(s -> !scarpetFunctions.contains(s)).collect(Collectors.toCollection(TreeSet::new));
}
public static List<String> suggestFunctions(ScriptHost host, String previous, String prefix)
{
previous = previous.replace("\\'", "");
int quoteCount = StringUtils.countMatches(previous,'\'');
if (quoteCount % 2 == 1)
return Collections.emptyList();
int maxLen = prefix.length()<3 ? (prefix.length()*2+1) : 1234;
List<String> scarpetMatches = scarpetFunctions.stream().
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList());
scarpetMatches.addAll(APIFunctions.stream().
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList()));
// not that useful in commandline, more so in external scripts, so skipping here
//scarpetMatches.addAll(CarpetServer.scriptServer.events.eventHandlers.keySet().stream().
// filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> "__"+s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaFunctionNames(host.main, s -> s.startsWith(prefix)).map(s -> s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaVariableNames(host.main, s -> s.startsWith(prefix)).collect(Collectors.toList()));
return scarpetMatches;
}
private static CompletableFuture<Suggestions> suggestCode(
CommandContext<ServerCommandSource> context,
@@ -66,7 +85,7 @@ public class ScriptCommand
return suggestionsBuilder.buildFuture();
String prefix = lastToken.reverse().toString();
String previousString = previous.substring(0,previous.length()-prefix.length()) ;
ExpressionInspector.suggestFunctions(currentHost, previousString, prefix).forEach(text -> suggestionsBuilder.suggest(previousString+text));
suggestFunctions(currentHost, previousString, prefix).forEach(text -> suggestionsBuilder.suggest(previousString+text));
return suggestionsBuilder.buildFuture();
}
@@ -333,7 +352,7 @@ public class ScriptCommand
}
Expression expr = fun.getExpression();
Tokenizer.Token tok = fun.getToken();
List<String> snippet = ExpressionInspector.Expression_getExpressionSnippet(tok, expr);
List<String> snippet = expr.getExpressionSnippet(tok);
Messenger.m(source, "wb "+fun.fullName(),"t defined at: line "+(tok.lineno+1)+" pos "+(tok.linepos+1));
for (String snippetLine: snippet)
{
@@ -1,7 +1,7 @@
package carpet.mixins;
import carpet.CarpetServer;
import carpet.script.ExpressionInspector;
import carpet.script.CarpetExpression;
import carpet.CarpetSettings;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
@@ -32,9 +32,9 @@ public abstract class ArmorStandEntity_scarpetMarkerMixin extends LivingEntity
{
if ((CarpetSettings.scriptsAutoload || !CarpetSettings.commandScript.equals("false")) && !world.isClient)
{
if (getScoreboardTags().contains(ExpressionInspector.MARKER_STRING))
if (getScoreboardTags().contains(CarpetExpression.MARKER_STRING))
{
String prefix = ExpressionInspector.MARKER_STRING+"_";
String prefix = CarpetExpression.MARKER_STRING+"_";
Optional<String> owner = getScoreboardTags().stream().filter(s -> s.startsWith(prefix)).findFirst();
if (owner.isPresent())
{
@@ -139,10 +139,11 @@ public class CarpetExpression
private final ServerCommandSource source;
private final BlockPos origin;
private final Expression expr;
Expression getExpr() {return expr;}
public Expression getExpr() {return expr;}
private static long tickStart = 0L;
// dummy entity for dummy requirements in the loot tables (see snowball)
private static FallingBlockEntity DUMMY_ENTITY = new FallingBlockEntity(EntityType.FALLING_BLOCK, null);
public static final String MARKER_STRING = "__scarpet_marker";
private static boolean stopAll = false;
@@ -2377,8 +2378,8 @@ public class CarpetExpression
(float)pointLocator.yaw,
(float) pointLocator.pitch
);
armorstand.addScoreboardTag(ExpressionInspector.MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
armorstand.addScoreboardTag(ExpressionInspector.MARKER_STRING);
armorstand.addScoreboardTag(MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
armorstand.addScoreboardTag(MARKER_STRING);
if (targetBlock != null)
armorstand.equipStack(EquipmentSlot.HEAD, new ItemStack(targetBlock.getBlock().asItem()));
if (!name.isEmpty())
@@ -2399,7 +2400,7 @@ public class CarpetExpression
this.expr.addLazyFunction("remove_all_markers", 0, (c, t, lv) -> {
CarpetContext cc = (CarpetContext)c;
int total = 0;
String markerName = ExpressionInspector.MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName());
String markerName = MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName());
for (Entity e : cc.s.getWorld().getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
{
total ++;
@@ -346,7 +346,7 @@ public class CarpetScriptHost extends ScriptHost
}
});
String markerName = ExpressionInspector.MARKER_STRING+"_"+((getName()==null)?"":getName());
String markerName = CarpetExpression.MARKER_STRING+"_"+((getName()==null)?"":getName());
for (ServerWorld world : CarpetServer.minecraft_server.getWorlds())
{
for (Entity e : world.getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
+10 -4
View File
@@ -99,6 +99,12 @@ public class Expression
public Module module = null;
public String getModuleName()
{
return module == null?null:module.getName();
}
void asATextSource()
{
allowNewlineSubstitutions = false;
@@ -119,11 +125,11 @@ public class Expression
boolean isAnOperator(String opname) { return operators.containsKey(opname) || operators.containsKey(opname+"u");}
private final Map<String, ILazyFunction> functions = new Object2ObjectOpenHashMap<>();
Set<String> getFunctionNames() {return functions.keySet();}
public Set<String> getFunctionNames() {return functions.keySet();}
static List<String> getExpressionSnippet(Tokenizer.Token token, Expression expr)
public List<String> getExpressionSnippet(Tokenizer.Token token)
{
String code = expr.getCodeString();
String code = this.getCodeString();
List<String> output = new ArrayList<>();
for (String line: getExpressionSnippetLeftContext(token, code, 1))
{
@@ -1949,7 +1955,7 @@ public class Expression
return var;
}
static final Expression none = new Expression("null");
public static final Expression none = new Expression("null");
/**
* @param expression .
*/
@@ -1,55 +0,0 @@
package carpet.script;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
/**
* sole purpose of this package is to provide public access to package-private methods of Expression and CarpetExpression
* classes so they don't leave garbage in javadocs
*/
public class ExpressionInspector
{
public static final String MARKER_STRING = "__scarpet_marker";
public static List<String> Expression_getExpressionSnippet(Tokenizer.Token token, Expression expr)
{
return Expression.getExpressionSnippet(token, expr);
}
public static String Expression_getModuleName(Expression e)
{
return e.module == null?null:e.module.getName();
}
private static TreeSet<String> scarpetFunctions;
private static TreeSet<String> APIFunctions;
static
{
Set<String> allFunctions = (new CarpetExpression(null, "null", null, null)).getExpr().getFunctionNames();
scarpetFunctions = new TreeSet<>(Expression.none.getFunctionNames());
APIFunctions = allFunctions.stream().filter(s -> !scarpetFunctions.contains(s)).collect(Collectors.toCollection(TreeSet::new));
}
public static List<String> suggestFunctions(ScriptHost host, String previous, String prefix)
{
previous = previous.replace("\\'", "");
int quoteCount = StringUtils.countMatches(previous,'\'');
if (quoteCount % 2 == 1)
return Collections.emptyList();
int maxLen = prefix.length()<3 ? (prefix.length()*2+1) : 1234;
List<String> scarpetMatches = scarpetFunctions.stream().
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList());
scarpetMatches.addAll(APIFunctions.stream().
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList()));
// not that useful in commandline, more so in external scripts, so skipping here
//scarpetMatches.addAll(CarpetServer.scriptServer.events.eventHandlers.keySet().stream().
// filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> "__"+s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaFunctionNames(host.main, s -> s.startsWith(prefix)).map(s -> s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaVariableNames(host.main, s -> s.startsWith(prefix)).collect(Collectors.toList()));
return scarpetMatches;
}
}
@@ -9,9 +9,6 @@ import carpet.script.value.FunctionValue;
import java.util.ArrayList;
import java.util.List;
import static carpet.script.ExpressionInspector.Expression_getExpressionSnippet;
import static carpet.script.ExpressionInspector.Expression_getModuleName;
/* The expression evaluators exception class. */
public class ExpressionException extends RuntimeException implements ResolvedException
{
@@ -40,10 +37,10 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
{
List<String> errMsg = new ArrayList<>();
errmessage += Expression_getModuleName(expr) == null?"":(" in "+Expression_getModuleName(expr));
errmessage += expr.getModuleName() == null?"":(" in "+expr.getModuleName());
if (token != null)
{
List<String> snippet = Expression_getExpressionSnippet(token, expr);
List<String> snippet = expr.getExpressionSnippet(token);
errMsg.addAll(snippet);
if (snippet.size() != 1)