/**
   * Writes the method definition.
   *
   * @param rule the rule node
   * @throws SemanticException never
   */
  @Override
  public void visit(Rule rule) throws SemanticException {
    currentRule = rule;
    isDefaultCase = false;

    String secondParameter = rule.hasOnlyOneName() ? "" : ", int rule";

    put(
        "private void "
            + currentRule.getMethodName()
            + "(int start"
            + secondParameter
            + ") throws InvalidInstructionException {");
    rule.acceptChildren(this);
    put("}", true);
  }
  /**
   * Writes the code for the recognized variant.
   *
   * @param variant the variant node
   * @throws SemanticException never
   */
  @Override
  public void visit(Variant variant) throws SemanticException {
    if (variant.returns()) {
      String field = "rule";
      String value;

      if (currentRule.hasOnlyOneName())
        field = currentRule.getFieldName(currentRule.getNames().get(0));

      if (variant.getReturnString() != null) {
        value = '"' + variant.getReturnString() + "\", " + variant.getFieldName();
      } else {
        int start = variant.getReturnSubrule().getStart();
        int length = variant.getReturnSubrule().getLength();

        value = String.format("readBytes(start + %d, %d)", start, length);
      }

      put(String.format("instruction.add(%s, %s);", field, value));
    }

    variant.acceptChildren(this);
  }