Esempio n. 1
0
 public final CommandControl isValid(BlocLines lines) {
   if (lines.size() != 1) {
     return CommandControl.NOT_OK;
   }
   lines = lines.removeInnerComments();
   if (isCommandForbidden()) {
     return CommandControl.NOT_OK;
   }
   final String line = StringUtils.trin(lines.getFirst499());
   final boolean result = pattern.match(line);
   if (result) {
     actionIfCommandValid();
   }
   return result ? CommandControl.OK : CommandControl.NOT_OK;
 }
Esempio n. 2
0
  public final CommandExecutionResult execute(S system, BlocLines lines) {
    if (lines.size() != 1) {
      throw new IllegalArgumentException();
    }
    lines = lines.removeInnerComments();
    final String line = StringUtils.trin(lines.getFirst499());
    if (isForbidden(line)) {
      return CommandExecutionResult.error("Forbidden line " + line);
    }

    final RegexResult arg = pattern.matcher(line);
    if (arg == null) {
      return CommandExecutionResult.error("Cannot parse line " + line);
    }
    if (system instanceof PSystemError) {
      return CommandExecutionResult.error("PSystemError cannot be cast");
    }
    // System.err.println("lines="+lines);
    // System.err.println("pattern="+pattern.getPattern());
    return executeArg(system, arg);
  }
  public final CommandControl isValid(BlocLines lines) {
    if (isCommandForbidden()) {
      return CommandControl.NOT_OK;
    }
    final Matcher2 m1 = starting.matcher(StringUtils.trim(lines.getFirst499()));
    if (m1.matches() == false) {
      return CommandControl.NOT_OK;
    }
    if (lines.size() == 1) {
      return CommandControl.OK_PARTIAL;
    }

    int level = 1;
    for (CharSequence cs : lines.subExtract(1, 0)) {
      final String s = StringUtils.trim(cs);
      if (isLineConsistent(s, level) == false) {
        return CommandControl.NOT_OK;
      }
      if (s.endsWith("{")) {
        level++;
      }
      if (s.endsWith("}")) {
        level--;
      }
      if (level < 0) {
        return CommandControl.NOT_OK;
      }
    }

    if (level != 0) {
      return CommandControl.OK_PARTIAL;
    }

    actionIfCommandValid();
    return CommandControl.OK;
  }