Class VariableString

java.lang.Object
io.github.syst3ms.skriptparser.lang.base.TaggedExpression
io.github.syst3ms.skriptparser.lang.VariableString
All Implemented Interfaces:
Expression<String>, SyntaxElement

public class VariableString extends TaggedExpression
A string that possibly contains expressions inside it, meaning that its value may be unknown at parse time
  • Method Details

    • newInstanceWithQuotes

      public static Optional<VariableString> newInstanceWithQuotes(String s, ParserState parserState, SkriptLogger logger)
      Creates a new instance of a VariableString.
      Parameters:
      s - the text to create a new instance from, with its surrounding quotes
      logger - the logger
      Returns:
      null if either:
      • The argument isn't quoted correctly
      • newInstance(String, ParserState, SkriptLogger) returned null, which can happen when the string literal is of the form "..."
      • Something went very wrong when parsing a raw literal R"possible delimiter(...)possible delimiter'
      . Returns a new instance of a VariableString otherwise.
    • newInstance

      public static Optional<VariableString> newInstance(String s, ParserState parserState, SkriptLogger logger)
      Creates a new instance of a VariableString from the text inside a string literal.
      Parameters:
      s - the content of the string literal, without quotes
      parserState - the current parser state
      logger - the logger
      Returns:
      a new instance of a VariableString, or null if there are unbalanced % symbols
    • init

      @Contract("_, _, _ -> fail") public boolean init(Expression<?>[] expressions, int matchedPattern, ParseContext parseContext)
      Description copied from interface: SyntaxElement
      Initializes this SyntaxElement before being used. This method is always called before all the others in an extending class, the only exception being CodeSection.loadSection(FileSection, ParserState, SkriptLogger).
      Parameters:
      expressions - an array of expressions representing all the expressions that are being passed to this syntax element. As opposed to Skript, elements of this array can't be null.
      matchedPattern - the index of the pattern that was successfully matched. It corresponds to the order of the syntaxes in registration
      parseContext - an object containing additional information about the parsing of this syntax element, like regex matches and parse marks
      Returns:
      true if the syntax element was initialized successfully, false otherwise.
      See Also:
    • isSingle

      public boolean isSingle()
      Returns:
      whether this expression returns a single value. By default, this is defined on registration, but it can be overridden.
    • getReturnType

      public Class<? extends String> getReturnType()
      Returns:
      the return type of this expression. By default, this is defined on registration, but, like Expression.isSingle(), can be overriden.
    • toString

      public String toString(TriggerContext ctx)
    • toString

      public String toString(TriggerContext ctx, String tagCtx)
      Description copied from class: TaggedExpression
      Returns the value of this string after applying the tags according to the given tag context.
      Specified by:
      toString in class TaggedExpression
      Parameters:
      ctx - the event
      tagCtx - the tag context
      Returns:
      the applied string
    • toString

      public String toString(TriggerContext ctx, boolean debug)
      Parameters:
      ctx - the event
      debug - whether to show additional information or not
      Returns:
      a String that should aim to resemble what is written in the script as closely as possible
    • isSimple

      public boolean isSimple()
      Returns:
      whether this VariableString is actually constant and whose value can be known at parse time
    • defaultVariableName

      public String defaultVariableName()