public static Script buildScript(
    @NotNull String scriptName,
    @NotNull String scriptText,
    @NotNull MatchOptions matchOptions
  ) throws MalformedPatternException {
    try {
      final GroovyShell shell = new GroovyShell(Objects.requireNonNull(matchOptions.getDialect()).getClass().getClassLoader());
      return shell.parse(scriptText, scriptName + UUID + ".groovy");
    }
    catch (MultipleCompilationErrorsException e) {
      final ErrorCollector errorCollector = e.getErrorCollector();
      final List<? extends Message> errors = errorCollector.getErrors();
      for (Message error : errors) {
        if (error instanceof SyntaxErrorMessage syntaxError) {
          final SyntaxException cause = syntaxError.getCause();
          throw new MalformedPatternException(cause.getLocalizedMessage());
        }
      }
      throw new MalformedPatternException(e.getLocalizedMessage());
    }
    catch (CompilationFailedException ex) {
      throw new MalformedPatternException(ex.getLocalizedMessage());
    }
    catch (Throwable e) {
      // to catch errors in groovy parsing
      LOG.warn(e);
      throw new MalformedPatternException(SSRBundle.message("error.in.groovy.parser"));
    }
  }
public static Script buildScript(
    @NotNull String scriptName,
    @NotNull String scriptText,
    @NotNull MatchOptions matchOptions
  )