removed inspector
This commit is contained in:
1 parent
d93a0dbdf4
commit
b041e05b47
8 files changed
+54
-86
No files matched your search
@@ -7,7 +7,7 @@ as `(2+4)-3`, which in case of numbers doesn't matter, but since `scarpet` allow
|
|||||||
the associativity would matter, and may lead to unintended effects:
|
the associativity would matter, and may lead to unintended effects:
|
||||||
|
|
||||||
Important operator is function definition `->` operator. It will be covered
|
Important operator is function definition `->` operator. It will be covered
|
||||||
in {@link carpet.script.Expression#UserDefinedFunctionsAndControlFlow}
|
in [User Defined Functions and Program Control Flow](docs/scarpet/language/FunctionsAndControlFlow.md)
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
'123'+4-2 => ('123'+4)-2 => '1234'-2 => '134'
|
'123'+4-2 => ('123'+4)-2 => '1234'-2 => '134'
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
package carpet.commands;
|
package carpet.commands;
|
||||||
|
|
||||||
import carpet.CarpetServer;
|
import carpet.CarpetServer;
|
||||||
import carpet.script.CarpetScriptHost;
|
import carpet.script.*;
|
||||||
import carpet.CarpetSettings;
|
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.exception.CarpetExpressionException;
|
||||||
import carpet.script.value.FunctionValue;
|
import carpet.script.value.FunctionValue;
|
||||||
import carpet.settings.SettingsManager;
|
import carpet.settings.SettingsManager;
|
||||||
@@ -31,11 +25,9 @@ import net.minecraft.util.Clearable;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.BlockBox;
|
import net.minecraft.util.math.BlockBox;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -47,6 +39,33 @@ import static net.minecraft.server.command.CommandSource.suggestMatching;
|
|||||||
|
|
||||||
public class ScriptCommand
|
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(
|
private static CompletableFuture<Suggestions> suggestCode(
|
||||||
CommandContext<ServerCommandSource> context,
|
CommandContext<ServerCommandSource> context,
|
||||||
@@ -66,7 +85,7 @@ public class ScriptCommand
|
|||||||
return suggestionsBuilder.buildFuture();
|
return suggestionsBuilder.buildFuture();
|
||||||
String prefix = lastToken.reverse().toString();
|
String prefix = lastToken.reverse().toString();
|
||||||
String previousString = previous.substring(0,previous.length()-prefix.length()) ;
|
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();
|
return suggestionsBuilder.buildFuture();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,7 +352,7 @@ public class ScriptCommand
|
|||||||
}
|
}
|
||||||
Expression expr = fun.getExpression();
|
Expression expr = fun.getExpression();
|
||||||
Tokenizer.Token tok = fun.getToken();
|
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));
|
Messenger.m(source, "wb "+fun.fullName(),"t defined at: line "+(tok.lineno+1)+" pos "+(tok.linepos+1));
|
||||||
for (String snippetLine: snippet)
|
for (String snippetLine: snippet)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
import carpet.CarpetServer;
|
import carpet.CarpetServer;
|
||||||
import carpet.script.ExpressionInspector;
|
import carpet.script.CarpetExpression;
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.LivingEntity;
|
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 ((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();
|
Optional<String> owner = getScoreboardTags().stream().filter(s -> s.startsWith(prefix)).findFirst();
|
||||||
if (owner.isPresent())
|
if (owner.isPresent())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -139,10 +139,11 @@ public class CarpetExpression
|
|||||||
private final ServerCommandSource source;
|
private final ServerCommandSource source;
|
||||||
private final BlockPos origin;
|
private final BlockPos origin;
|
||||||
private final Expression expr;
|
private final Expression expr;
|
||||||
Expression getExpr() {return expr;}
|
public Expression getExpr() {return expr;}
|
||||||
private static long tickStart = 0L;
|
private static long tickStart = 0L;
|
||||||
// dummy entity for dummy requirements in the loot tables (see snowball)
|
// dummy entity for dummy requirements in the loot tables (see snowball)
|
||||||
private static FallingBlockEntity DUMMY_ENTITY = new FallingBlockEntity(EntityType.FALLING_BLOCK, null);
|
private static FallingBlockEntity DUMMY_ENTITY = new FallingBlockEntity(EntityType.FALLING_BLOCK, null);
|
||||||
|
public static final String MARKER_STRING = "__scarpet_marker";
|
||||||
|
|
||||||
private static boolean stopAll = false;
|
private static boolean stopAll = false;
|
||||||
|
|
||||||
@@ -2377,8 +2378,8 @@ public class CarpetExpression
|
|||||||
(float)pointLocator.yaw,
|
(float)pointLocator.yaw,
|
||||||
(float) pointLocator.pitch
|
(float) pointLocator.pitch
|
||||||
);
|
);
|
||||||
armorstand.addScoreboardTag(ExpressionInspector.MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
|
armorstand.addScoreboardTag(MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
|
||||||
armorstand.addScoreboardTag(ExpressionInspector.MARKER_STRING);
|
armorstand.addScoreboardTag(MARKER_STRING);
|
||||||
if (targetBlock != null)
|
if (targetBlock != null)
|
||||||
armorstand.equipStack(EquipmentSlot.HEAD, new ItemStack(targetBlock.getBlock().asItem()));
|
armorstand.equipStack(EquipmentSlot.HEAD, new ItemStack(targetBlock.getBlock().asItem()));
|
||||||
if (!name.isEmpty())
|
if (!name.isEmpty())
|
||||||
@@ -2399,7 +2400,7 @@ public class CarpetExpression
|
|||||||
this.expr.addLazyFunction("remove_all_markers", 0, (c, t, lv) -> {
|
this.expr.addLazyFunction("remove_all_markers", 0, (c, t, lv) -> {
|
||||||
CarpetContext cc = (CarpetContext)c;
|
CarpetContext cc = (CarpetContext)c;
|
||||||
int total = 0;
|
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)))
|
for (Entity e : cc.s.getWorld().getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
|
||||||
{
|
{
|
||||||
total ++;
|
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 (ServerWorld world : CarpetServer.minecraft_server.getWorlds())
|
||||||
{
|
{
|
||||||
for (Entity e : world.getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
|
for (Entity e : world.getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
|
||||||
|
|||||||
@@ -99,6 +99,12 @@ public class Expression
|
|||||||
|
|
||||||
public Module module = null;
|
public Module module = null;
|
||||||
|
|
||||||
|
public String getModuleName()
|
||||||
|
{
|
||||||
|
return module == null?null:module.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void asATextSource()
|
void asATextSource()
|
||||||
{
|
{
|
||||||
allowNewlineSubstitutions = false;
|
allowNewlineSubstitutions = false;
|
||||||
@@ -119,11 +125,11 @@ public class Expression
|
|||||||
boolean isAnOperator(String opname) { return operators.containsKey(opname) || operators.containsKey(opname+"u");}
|
boolean isAnOperator(String opname) { return operators.containsKey(opname) || operators.containsKey(opname+"u");}
|
||||||
|
|
||||||
private final Map<String, ILazyFunction> functions = new Object2ObjectOpenHashMap<>();
|
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<>();
|
List<String> output = new ArrayList<>();
|
||||||
for (String line: getExpressionSnippetLeftContext(token, code, 1))
|
for (String line: getExpressionSnippetLeftContext(token, code, 1))
|
||||||
{
|
{
|
||||||
@@ -1949,7 +1955,7 @@ public class Expression
|
|||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
static final Expression none = new Expression("null");
|
public static final Expression none = new Expression("null");
|
||||||
/**
|
/**
|
||||||
* @param expression .
|
* @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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static carpet.script.ExpressionInspector.Expression_getExpressionSnippet;
|
|
||||||
import static carpet.script.ExpressionInspector.Expression_getModuleName;
|
|
||||||
|
|
||||||
/* The expression evaluators exception class. */
|
/* The expression evaluators exception class. */
|
||||||
public class ExpressionException extends RuntimeException implements ResolvedException
|
public class ExpressionException extends RuntimeException implements ResolvedException
|
||||||
{
|
{
|
||||||
@@ -40,10 +37,10 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
|
|||||||
{
|
{
|
||||||
|
|
||||||
List<String> errMsg = new ArrayList<>();
|
List<String> errMsg = new ArrayList<>();
|
||||||
errmessage += Expression_getModuleName(expr) == null?"":(" in "+Expression_getModuleName(expr));
|
errmessage += expr.getModuleName() == null?"":(" in "+expr.getModuleName());
|
||||||
if (token != null)
|
if (token != null)
|
||||||
{
|
{
|
||||||
List<String> snippet = Expression_getExpressionSnippet(token, expr);
|
List<String> snippet = expr.getExpressionSnippet(token);
|
||||||
errMsg.addAll(snippet);
|
errMsg.addAll(snippet);
|
||||||
|
|
||||||
if (snippet.size() != 1)
|
if (snippet.size() != 1)
|
||||||
|
|||||||
Reference in new issue
Block a user