Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Optional<? extends Statement> walk(TriggerContext ctx) {
? ((SelfReferencing) val).getActualNext()
: val.getNext());

// Because otherwise SelfReferencing sections will getFirst reference to themselves
// Because otherwise SelfReferencing sections will first reference to themselves
if (current.filter(val -> val instanceof Finishing).isEmpty())
am--;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, ParseContex
|| firstEach && first.isSingle() != second.isSingle()
|| second.isSingle() != third.isSingle())) {
/*
* What is ruled out here is using "each" when "getSecond" and "third" don't match in number or in and/or type.
* What is ruled out here is using "each" when "second" and "third" don't match in number or in and/or type.
* Otherwise these are fundamentally the same checks as above but when "third" is present.
*/
logger.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* Basic list operators that return the following elements:
* <ul>
* <li>{@code pop}: the last element</li>
* <li>{@code shift/poll}: the getFirst element</li>
* <li>{@code extract}: a specific (or just the getFirst/last) element</li>
* <li>{@code shift/poll}: the first element</li>
* <li>{@code extract}: a specific (or just the first/last) element</li>
* <li>{@code splice}: elements in a certain bound</li>
* </ul>
* However, this syntax can also be used as an effect. If this is the case, instead of returning
Expand All @@ -32,7 +32,7 @@
* @author Mwexim
* @name List Operators
* @type EFFECT/EXPRESSION
* @pattern extract [the] (last|getFirst|%integer%(st|nd|rd|th)) element out [of] %objects%
* @pattern extract [the] (last|first|%integer%(st|nd|rd|th)) element out [of] %objects%
* @pattern pop %objects%
* @pattern (shift | poll) %objects%
* @pattern splice %objects% (from %integer% to %integer%|starting (at|from) %integer%|up to %integer%) [[with] step %integer%]
Expand All @@ -45,14 +45,14 @@ public class ExecExprListOperators extends ExecutableExpression<Object> {
ExecExprListOperators.class,
Object.class,
false,
"extract [the] (0:last|1:getFirst|2:%integer%(st|nd|rd|th)) element out [of] %objects%",
"extract [the] (0:last|1:first|2:%integer%(st|nd|rd|th)) element out [of] %objects%",
"pop %objects%",
"(shift|poll) %objects%",
"splice %objects% (0:from %integer% to %integer%|1:starting (at|from) %integer%|2:up to %integer%) [[with] step %integer%]"
);
}

// 0 = last, 1 = getFirst, 2 = indexed, 3 = spliced
// 0 = last, 1 = first, 2 = indexed, 3 = spliced
private int type;
private Expression<Object> list;
private Expression<Integer> index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
* @author Mwexim
* @name Replace
* @type EFFECT/EXPRESSION
* @pattern replace [(all|every|[the] getFirst|[the] last)] [regex [pattern[s]]] %strings% in %strings% with %string%
* @pattern replace [(all|every|[the] getFirst|[the] last)] [regex [pattern[s]]] %strings% with %string% in %strings%
* @pattern replace [(all|every|[the] first|[the] last)] [regex [pattern[s]]] %strings% in %strings% with %string%
* @pattern replace [(all|every|[the] first|[the] last)] [regex [pattern[s]]] %strings% with %string% in %strings%
* @see ExprElement
* @since ALPHA
*/
public class ExecExprReplace extends ExecutableExpression<String> {
static {
// TODO add "new" so we can add docs
Parser.getMainRegistration().addExecutableExpression(ExecExprReplace.class, String.class, false,
"replace [(0:all|0:every|1:[the] getFirst|2:[the] last)] [:regex [pattern[s]]] %strings% in %strings% with %string%",
"replace [(0:all|0:every|1:[the] getFirst|2:[the] last)] [:regex [pattern[s]]] %strings% with %string% in %strings%"
"replace [(0:all|0:every|1:[the] first|2:[the] last)] [:regex [pattern[s]]] %strings% in %strings% with %string%",
"replace [(0:all|0:every|1:[the] first|2:[the] last)] [:regex [pattern[s]]] %strings% with %string% in %strings%"
);
}

Expand Down Expand Up @@ -136,7 +136,7 @@ public String[] getValues(TriggerContext ctx, boolean isEffect) {
@Override
public String toString(TriggerContext ctx, boolean debug) {
return "replace "
+ new String[]{"all ", "getFirst ", "last "}[type] + toMatch.toString(ctx, debug)
+ new String[]{"all ", "first ", "last "}[type] + toMatch.toString(ctx, debug)
+ " in " + toReplace.toString(ctx, debug)
+ " with " + replacement.toString(ctx, debug);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* The amount of elements in a given list.
* Note that when getting the size of a list variable, it will only return the size of the getFirst layer of elements.
* Note that when getting the size of a list variable, it will only return the size of the first layer of elements.
* If you want to get the whole list size, including nested layers in a variable, use the recursive size instead.
*
* @author Olyno, Mwexim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Mwexim
* @name Date Information
* @type EXPRESSION
* @pattern [the] (year[s]|month[s]|day[s] (of|in) year|day[s] (of|in) month|day[s] (of|in) week|hour[s]|minute[s]|getSecond[s]|milli[getSecond][s]) (of|in) %date/time%
* @pattern [the] (year[s]|month[s]|day[s] (of|in) year|day[s] (of|in) month|day[s] (of|in) week|hour[s]|minute[s]|second[s]|milli[second][s]) (of|in) %date/time%
* @pattern [the] (era|month|weekday|day [(of|in) week]) [name] (of|in) [date] %date%
* @since ALPHA
*/
Expand All @@ -32,8 +32,8 @@ public class ExprDateInformation implements Expression<Object> {
{"day[s] (of|in) week", (Function<LocalDateTime, Number>) val -> val.getDayOfWeek().getValue()},
{"hour[s]", (Function<LocalDateTime, Number>) LocalDateTime::getHour},
{"minute[s]", (Function<LocalDateTime, Number>) LocalDateTime::getMinute},
{"getSecond[s]", (Function<LocalDateTime, Number>) LocalDateTime::getSecond},
{"milli[getSecond][s]", (Function<LocalDateTime, Number>) val -> val.getNano() / 1_000_000}
{"second[s]", (Function<LocalDateTime, Number>) LocalDateTime::getSecond},
{"milli[second][s]", (Function<LocalDateTime, Number>) val -> val.getNano() / 1_000_000}
});

private static final PatternInfos<Function<LocalDateTime, String>> STRING_VALUES = new PatternInfos<>(new Object[][]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.github.syst3ms.skriptparser.parsing.ParseContext;

/**
* A shorthand expression for giving things a default value. If the getFirst thing isn't set, the getSecond thing will be returned.
* A shorthand expression for giving things a default value. If the first thing isn't set, the second thing will be returned.
*
* @author Olyno
* @name Default Value
Expand All @@ -18,7 +18,7 @@ public class ExprDefaultValue implements Expression<Object> {
Parser.getMainRegistration().newExpression(ExprDefaultValue.class, Object.class, false,
"%objects% (otherwise|?) %objects%")
.name("Default Value")
.description("Returns the getFirst expression if it's set, otherwise the getSecond expression.")
.description("Returns the first expression if it's set, otherwise the second expression.")
.examples("set {_var} to {_otherVarIfSet} otherwise \"world\"",
"send {_varIfSet} ? \"ruh roh, no message\"")
.since("1.0.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

/**
* Compares the given date with the current date.
* Note that the getFirst pattern is to compare with the past
* and the getSecond one to compare with the future.
* Note that the first pattern is to compare with the past
* and the second one to compare with the future.
* Note that the accuracy can be off some milliseconds.
*
* @author Mwexim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* @author Mwexim
* @name Element
* @type EXPRESSION
* @pattern ([the] getFirst | [the] last | [a] random | [the] % integer % ( st | nd | rd | th)) element out [of] %objects%
* @pattern [the] (getFirst|last) %integer% elements out [of] %objects%
* @pattern ([the] first | [the] last | [a] random | [the] % integer % ( st | nd | rd | th)) element out [of] %objects%
* @pattern [the] (first|last) %integer% elements out [of] %objects%
* @pattern %integer% random elements out [of] %objects%
* @pattern %objects%\[%integer%\]
* @since ALPHA
Expand All @@ -27,8 +27,8 @@ public class ExprElement implements Expression<Object> {

static {
Parser.getMainRegistration().newExpression(ExprElement.class, Object.class, true,
"(0:[the] getFirst|1:[the] last|2:[a] random|3:[the] %integer%(st|nd|rd|th)) element [out] of %objects%",
"[the] (0:getFirst|1:last) %integer% elements [out] of %objects%",
"(0:[the] first|1:[the] last|2:[a] random|3:[the] %integer%(st|nd|rd|th)) element [out] of %objects%",
"[the] (0:first|1:last) %integer% elements [out] of %objects%",
"%integer% random elements [out] of %objects%",
"%objects%\\[%integer%\\]")
.name("Element")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Function<? super List<? extends SecLoop>, Optional<? extends SecLoop>> ge
return sections -> {
int j = 1;
SecLoop loop = null;
// The closest section is getFirst, let's reverse this behavior for convenience
// The closest section is first, let's reverse this behavior for convenience
Collections.reverse(sections);
for (SecLoop l : sections) {
Class<?> loopedType = l.getLoopedExpression().getReturnType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
import io.github.syst3ms.skriptparser.util.DoubleOptional;

/**
* The index of the getFirst or last occurrence of a given string in a string.
* The index of the first or last occurrence of a given string in a string.
* Note that indices in Skript start at 1.
*
* @author Mwexim
* @name Occurrence
* @type EXPRESSION
* @pattern [the] (getFirst|last) occurrence of %string% in %string%
* @pattern [the] (first|last) occurrence of %string% in %string%
* @since ALPHA
*/
public class ExprStringOccurrence implements Expression<Number> {
static {
Parser.getMainRegistration().newExpression(ExprStringOccurrence.class, Number.class, true,
"[the] (0:getFirst|1:last) occurrence of %string% in %string%")
"[the] (0:first|1:last) occurrence of %string% in %string%")
.name("Occurrence")
.description("Returns the index of the getFirst or last occurrence of a given string in a string.")
.description("Returns the index of the first or last occurrence of a given string in a string.")
.since("1.0.0")
.register();
}
Expand Down Expand Up @@ -50,7 +50,7 @@ public Number[] getValues(TriggerContext ctx) {

@Override
public String toString(TriggerContext ctx, boolean debug) {
return (first ? "getFirst" : "last") + " occurrence of " + needle.toString(ctx, debug) + " in " + haystack.toString(ctx, debug);
return (first ? "first" : "last") + " occurrence of " + needle.toString(ctx, debug) + " in " + haystack.toString(ctx, debug);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class ExprSubstring implements Expression<String> {
static {
Parser.getMainRegistration().newExpression(ExprSubstring.class, String.class, true,
"[the] (part|sub[ ](text|string)) of %string% (between|from) [(ind(ex[es]|ices)|char[acter][s])] %integer% (and|to) [(index|char[acter])] %integer%",
"[the] (0:getFirst|1:last) [%integer%] char[acter][s] (of|in) %string%",
"[the] %integer% (0:getFirst|1:last) char[acter]s (of|in) %string%")
"[the] (0:first|1:last) [%integer%] char[acter][s] (of|in) %string%",
"[the] %integer% (0:first|1:last) char[acter]s (of|in) %string%")
.name("Substring")
.description("Extracts a part of a string.")
.since("1.0.0")
Expand Down Expand Up @@ -93,7 +93,7 @@ public String toString(TriggerContext ctx, boolean debug) {
return "substring of " + value.toString(ctx, debug)
+ " from " + lower.toString(ctx, debug) + " to " + upper.toString(ctx, debug);
} else {
return (first ? "getFirst " : "last ") + (lower != null ? lower.toString(ctx, debug) : "")
return (first ? "first " : "last ") + (lower != null ? lower.toString(ctx, debug) : "")
+ " characters of " + value.toString(ctx, debug);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ExprTernary implements Expression<Object> {
"%objects% if %=boolean%[,] (otherwise|else) %objects%",
"%=boolean% ? %objects% \\: %objects%")
.name("Ternary")
.description("Returns the getFirst object if the boolean is true, otherwise the getSecond object.")
.description("Returns the first object if the boolean is true, otherwise the second object.")
.since("1.0.0")
.register();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class FileParser {
*
* @param fileName the name of the file the lines belong to
* @param lines the list of lines to parse
* @param expectedIndentation the indentation level the getFirst line is expected to be at
* @param expectedIndentation the indentation level the first line is expected to be at
* @param lastLine a parameter that keeps track of the line count throughout recursive calls of this method when
* parsing sections
* @param logger the logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public final void setItems(List<Statement> items) {
}

/**
* @return the getFirst item of this section, or the item after the section if it's empty, or {@code null} if there is
* @return the first item of this section, or the item after the section if it's empty, or {@code null} if there is
* no item after this section, in the latter case
*/
public final Optional<? extends Statement> getFirst() {
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/io/github/syst3ms/skriptparser/lang/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
public abstract class Statement implements SyntaxElement {
public static Consumer<IllegalStateException> illegalStateRunnable;
public static Consumer<Exception> exceptionHandler;
@Nullable
protected CodeSection parent;
@Nullable
Expand All @@ -22,11 +23,15 @@ public static void setIllegalStateHandler(Consumer<IllegalStateException> consum
Statement.illegalStateRunnable = consumer;
}

public static void setExceptionHandler(Consumer<Exception> consumer) {
Statement.exceptionHandler = consumer;
}

/**
* Runs all code starting at a given point sequentially.
* Do note this will not clear local variables after running.
*
* @param start the Statement the method should getFirst run
* @param start the Statement the method should first run
* @param context the context
* @return {@code true} if the code ran normally, and {@code false} if any exception occurred
*/
Expand All @@ -48,8 +53,12 @@ public static boolean runAll(Statement start, TriggerContext context) {
}
return false;
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.accept(e);
}
System.err.println("An exception occurred. Stack trace:");
e.printStackTrace();

}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ public static <T extends TriggerContext> List<Trigger> getTriggersByContext(Clas
* @param <T> Trigger context type
*/
public static <T extends TriggerContext> void callTriggersByContext(T context) {
getTriggersByContext(context.getClass()).forEach(t -> Statement.runAll(t, context));
Variables.clearLocalVariables(context);
getTriggersByContext(context.getClass()).forEach(t -> {
Statement.runAll(t, context);
Variables.clearLocalVariables(context);
});

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/**
* A reference to a variable, whose value is only known at runtime. It can be local to the event, meaning it isn't
* defined outside of the event it was getFirst defined in. It can also be a list of multiple values. It can also be both.
* defined outside of the event it was first defined in. It can also be a list of multiple values. It can also be both.
*
* @param <T> the common supertype of the possibly multiple values of the variable
*/
Expand Down
Loading
Loading