Package ch.njol.skript.lang
Class SkriptParser
java.lang.Object
ch.njol.skript.lang.SkriptParser
Used for parsing my custom patterns.
Note: All parse methods print one error at most xor any amount of warnings and lower level log messages. If the given string doesn't match any pattern then nothing is printed.
Note: All parse methods print one error at most xor any amount of warnings and lower level log messages. If the given string doesn't match any pattern then nothing is printed.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
final ParseContext
static final Pattern
Matches ',', 'and', 'or', etc.static final Pattern
Deprecated.static final Pattern
static final int
static final int
static final String
Deprecated.due to bad naming conventions, useWILDCARD
instead.static final String
-
Constructor Summary
ConstructorDescriptionSkriptParser
(SkriptParser other, String expr) SkriptParser
(String expr) SkriptParser
(String expr, int flags) SkriptParser
(String expr, int flags, ParseContext context) Constructs a new SkriptParser object that can be used to parse the given expression. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
next
(String expr, int startIndex, ParseContext context) Returns the next character in the expression, skipping strings, variables and parentheses (unlesscontext
isParseContext.COMMAND
orParseContext.PARSE
).static int
nextBracket
(String pattern, char closingBracket, char openingBracket, int start, boolean isGroup) Finds the closing bracket of the group at start (i.e.static int
nextOccurrence
(String haystack, String needle, int startIndex, ParseContext parseContext, boolean caseSensitive) Returns the next occurrence of the needle in the haystack.static String
static String
static @Nullable SkriptParser.ParseResult
parse
(String text, SkriptPattern pattern, int parseFlags, ParseContext parseContext) Parses the text as the given pattern with the given parse context and parse flags.static @Nullable SkriptParser.ParseResult
Parses the text as the given pattern asParseContext.COMMAND
.static @Nullable SkriptParser.ParseResult
parse
(String text, String pattern, int parseFlags, ParseContext parseContext) Parses the text as the given pattern with the given parse context and parse flags.static <T extends SyntaxElement>
Tparse
(String expr, Iterator<? extends SyntaxElementInfo<T>> source, @Nullable String defaultError) Parses a string as one of the given syntax elements.static boolean
parseArguments
(String args, ScriptCommand command, ScriptCommandEvent event) Prints parse errors (i.e.@Nullable Expression
<?> parseExpression
(SkriptParser.ExprInfo exprInfo) <T> @Nullable Expression
<? extends T> parseExpression
(Class<? extends T>... types) <T> @Nullable FunctionReference
<T> parseFunction
(@Nullable Class<? extends T>... types) static <T> @Nullable Literal
<? extends T> parseLiteral
(String expr, Class<T> expectedClass, ParseContext context) Parses a single literal, i.e.static <T extends SyntaxElement>
TparseStatic
(String expr, Iterator<? extends SyntaxElementInfo<? extends T>> source, ParseContext parseContext, @Nullable String defaultError) static <T extends SyntaxElement>
TparseStatic
(String expr, Iterator<? extends SyntaxElementInfo<? extends T>> source, @Nullable String defaultError) static boolean
validateLine
(String line) static @Nullable NonNullPair
<String, NonNullPair<ClassInfo<?>, Boolean>[]> validatePattern
(String pattern) Validates a user-defined pattern (used inExprParse
).
-
Field Details
-
PARSE_EXPRESSIONS
public static final int PARSE_EXPRESSIONS- See Also:
-
PARSE_LITERALS
public static final int PARSE_LITERALS- See Also:
-
ALL_FLAGS
public static final int ALL_FLAGS- See Also:
-
context
-
WILDCARD
- See Also:
-
LIST_SPLIT_PATTERN
Matches ',', 'and', 'or', etc. as well as surrounding whitespace.group 1 is null for ',', otherwise it's one of and/or/nor (not necessarily lowercase).
-
OR_PATTERN
-
listSplitPattern
Deprecated.due to bad naming conventions, useLIST_SPLIT_PATTERN
instead. -
wildcard
Deprecated.due to bad naming conventions, useWILDCARD
instead.- See Also:
-
-
Constructor Details
-
SkriptParser
-
SkriptParser
-
SkriptParser
Constructs a new SkriptParser object that can be used to parse the given expression.A SkriptParser can be re-used indefinitely for the given expression, but to parse a new expression a new SkriptParser has to be created.
- Parameters:
expr
- The expression to parseflags
- Some parse flags (PARSE_EXPRESSIONS
,PARSE_LITERALS
)context
- The parse context
-
SkriptParser
-
-
Method Details
-
parseLiteral
@Nullable public static <T> @Nullable Literal<? extends T> parseLiteral(String expr, Class<T> expectedClass, ParseContext context) Parses a single literal, i.e. not lists of literals.Prints errors.
-
parse
@Nullable public static <T extends SyntaxElement> T parse(String expr, Iterator<? extends SyntaxElementInfo<T>> source, @Nullable @Nullable String defaultError) Parses a string as one of the given syntax elements.Can print an error.
-
parseStatic
@Nullable public static <T extends SyntaxElement> T parseStatic(String expr, Iterator<? extends SyntaxElementInfo<? extends T>> source, @Nullable @Nullable String defaultError) -
parseStatic
@Nullable public static <T extends SyntaxElement> T parseStatic(String expr, Iterator<? extends SyntaxElementInfo<? extends T>> source, ParseContext parseContext, @Nullable @Nullable String defaultError) -
parseExpression
-
parseExpression
-
parseFunction
@Nullable public <T> @Nullable FunctionReference<T> parseFunction(@Nullable @Nullable Class<? extends T>... types) - Parameters:
types
- The required return type or null if it is not used (e.g. when calling a void function)- Returns:
- The parsed function, or null if the given expression is not a function call or is an invalid function call (check for an error to differentiate these two)
-
parseArguments
Prints parse errors (i.e. must start a ParseLog before calling this method) -
parse
Parses the text as the given pattern asParseContext.COMMAND
.Prints parse errors (i.e. must start a ParseLog before calling this method)
-
parse
@Nullable public static @Nullable SkriptParser.ParseResult parse(String text, String pattern, int parseFlags, ParseContext parseContext) Parses the text as the given pattern with the given parse context and parse flags.Prints parse errors (i.e. must start a ParseLog before calling this method)
-
parse
@Nullable public static @Nullable SkriptParser.ParseResult parse(String text, SkriptPattern pattern, int parseFlags, ParseContext parseContext) Parses the text as the given pattern with the given parse context and parse flags.Prints parse errors (i.e. must start a ParseLog before calling this method)
-
nextBracket
public static int nextBracket(String pattern, char closingBracket, char openingBracket, int start, boolean isGroup) throws MalformedPatternException Finds the closing bracket of the group at start (i.e. start has to be in a group).- Parameters:
pattern
- The string to search inclosingBracket
- The bracket to look for, e.g. ')'openingBracket
- A bracket that opens another group, e.g. '('start
- This must not be the index of the opening bracket!isGroup
- Whether start is assumed to be in a group (will print an error if this is not the case, otherwise it returns pattern.length())- Returns:
- The index of the next bracket
- Throws:
MalformedPatternException
- If the group is not closed
-
notOfType
- Parameters:
types
- The types to include in the message- Returns:
- "not an x" or "neither an x, a y nor a z"
-
notOfType
-
next
Returns the next character in the expression, skipping strings, variables and parentheses (unlesscontext
isParseContext.COMMAND
orParseContext.PARSE
).- Parameters:
expr
- The expression to traverse.startIndex
- The index to start at.- Returns:
- The next index (can be expr.length()), or -1 if
an invalid string, variable or bracket is found
or if
startIndex >= expr.length()
. - Throws:
StringIndexOutOfBoundsException
- ifstartIndex < 0
.
-
nextOccurrence
public static int nextOccurrence(String haystack, String needle, int startIndex, ParseContext parseContext, boolean caseSensitive) Returns the next occurrence of the needle in the haystack. Similar tonext(String, int, ParseContext)
, this method skips strings, variables and parentheses (unless context isParseContext.COMMAND
orParseContext.PARSE
).- Parameters:
haystack
- The string to search in.needle
- The string to search for.startIndex
- The index to start in within the haystack.caseSensitive
- Whether this search will be case-sensitive.- Returns:
- The next index representing the first character of the needle. May return -1 if an invalid string, variable or bracket is found or if startIndex >= hatsack.length().
- Throws:
StringIndexOutOfBoundsException
- if startIndex invalid input: '<' 0.
-
validatePattern
@Nullable public static @Nullable NonNullPair<String,NonNullPair<ClassInfo<?>, validatePatternBoolean>[]> (String pattern) Validates a user-defined pattern (used inExprParse
).- Parameters:
pattern
- The pattern string to validate- Returns:
- The pattern with %codenames% and a boolean array that contains whether the expressions are plural or not
-
validateLine
-
LIST_SPLIT_PATTERN
instead.