public int matchingSize(String line) {
   final Matcher2 m = p.matcher(line);
   if (m.find() == false) {
     return 0;
   }
   return m.group(1).length();
 }
 public String executeAndGetRemaining(final String line, StripeSimple stripe) {
   final Matcher2 m = p.matcher(line);
   if (m.find() == false) {
     throw new IllegalStateException();
   }
   final FontConfiguration fc1 = stripe.getActualFontConfiguration();
   final FontConfiguration fc2 = new AddStyle(style, getExtendedColor(m)).apply(fc1);
   stripe.setActualFontConfiguration(fc2);
   final int groupCount = m.groupCount();
   stripe.analyzeAndAdd(m.group(groupCount));
   stripe.setActualFontConfiguration(fc1);
   return line.substring(m.group(1).length());
 }
Example #3
0
  public CharSequence2 readLine() throws IOException {
    final CharSequence2 s = source.readLine();
    if (s == null) {
      return null;
    }
    if (StartUtils.isArobaseStartDiagram(s)) {
      this.defines.restoreState();
    }

    Matcher2 m = definePattern.matcher(s);
    if (m.find()) {
      return manageDefine(m);
    }

    m = definelongPattern.matcher(s);
    if (m.find()) {
      return manageDefineLong(m);
    }

    m = undefPattern.matcher(s);
    if (m.find()) {
      return manageUndef(m);
    }

    if (ignoreDefineDuringSeveralLines > 0) {
      ignoreDefineDuringSeveralLines--;
      return s;
    }

    final List<String> result = defines.applyDefines(s.toString2());
    if (result.size() > 1) {
      ignoreDefineDuringSeveralLines = result.size() - 2;
      source.insert(result.subList(1, result.size() - 1), s.getLocation());
    }
    return new CharSequence2Impl(result.get(0), s.getLocation());
  }
Example #4
0
 private CharSequence2 manageDefineLong(Matcher2 m) throws IOException {
   final String group1 = m.group(1);
   final List<String> def = new ArrayList<String>();
   while (true) {
     final CharSequence2 read = this.readLine();
     if (read == null) {
       return null;
     }
     def.add(read.toString2());
     if (enddefinelongPattern.matcher(read).find()) {
       defines.define(group1, def);
       return this.readLine();
     }
   }
 }
  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;
  }
 public String[] getDescription() {
   return new String[] {"BRACKET: " + starting.pattern()};
 }