Ejemplo n.º 1
0
  /**
   * Inserts token location (beginLine, beginColumn, endLine, endColumn) information into the
   * NodeToken. Takes into account line-wrap. Does not update curLine and curColumn.
   */
  private void placeToken(NodeToken n, int line, int column) {
    int length = n.tokenImage.length();

    //
    // Find beginning of token.  Only line-wrap for single-line tokens
    //
    if (!lineWrap || n.tokenImage.indexOf('\n') != -1 || column + length <= wrapWidth)
      n.beginColumn = column;
    else {
      ++line;
      column = curIndent + indentAmt + 1;
      n.beginColumn = column;
    }

    n.beginLine = line;

    //
    // Find end of token; don't count \n if it's the last character
    //
    for (int i = 0; i < length; ++i) {
      if (n.tokenImage.charAt(i) == '\n' && i < length - 1) {
        ++line;
        column = 1;
      } else ++column;
    }

    n.endLine = line;
    n.endColumn = column;
  }
Ejemplo n.º 2
0
 /**
  * Constructs the node with only its non NodeToken child node(s).
  *
  * @param n0 first child node
  */
 public RIFConclusion(final RIFFormula n0) {
   f0 = new NodeToken("conclusion");
   if (f0 != null) f0.setParent(this);
   f1 = new NodeToken("(");
   if (f1 != null) f1.setParent(this);
   f2 = n0;
   if (f2 != null) f2.setParent(this);
   f3 = new NodeToken(")");
   if (f3 != null) f3.setParent(this);
 }
Ejemplo n.º 3
0
 /**
  * Constructs the node with all its children nodes.
  *
  * @param n0 first child node
  * @param n1 next child node
  * @param n2 next child node
  * @param n3 next child node
  */
 public RIFConclusion(
     final NodeToken n0, final NodeToken n1, final RIFFormula n2, final NodeToken n3) {
   f0 = n0;
   if (f0 != null) f0.setParent(this);
   f1 = n1;
   if (f1 != null) f1.setParent(this);
   f2 = n2;
   if (f2 != null) f2.setParent(this);
   f3 = n3;
   if (f3 != null) f3.setParent(this);
 }
 public ServiceDeclaration(AnnotationDeclaration n0, NodeChoice n1, NodeToken n2) {
   annotationDeclaration = n0;
   if (annotationDeclaration != null) annotationDeclaration.setParent(this);
   nodeChoice = n1;
   if (nodeChoice != null) nodeChoice.setParent(this);
   nodeToken = new NodeToken("Service");
   if (nodeToken != null) nodeToken.setParent(this);
   nodeToken1 = n2;
   if (nodeToken1 != null) nodeToken1.setParent(this);
   nodeToken2 = new NodeToken(";");
   if (nodeToken2 != null) nodeToken2.setParent(this);
 }
 public AdapterStatement(AnnotationDeclaration n0, NodeToken n1, NodeListOptional n2) {
   annotationDeclaration = n0;
   if (annotationDeclaration != null) annotationDeclaration.setParent(this);
   nodeToken = new NodeToken("public");
   if (nodeToken != null) nodeToken.setParent(this);
   nodeToken1 = new NodeToken("Adapter");
   if (nodeToken1 != null) nodeToken1.setParent(this);
   nodeToken2 = n1;
   if (nodeToken2 != null) nodeToken2.setParent(this);
   nodeToken3 = new NodeToken("{");
   if (nodeToken3 != null) nodeToken3.setParent(this);
   nodeListOptional = n2;
   if (nodeListOptional != null) nodeListOptional.setParent(this);
   nodeToken4 = new NodeToken("}");
   if (nodeToken4 != null) nodeToken4.setParent(this);
 }
Ejemplo n.º 6
0
  /**
   * Dumps the current NodeToken to the output stream being used.
   *
   * @throws IllegalStateException if the token position is invalid relative to the current
   *     position, i.e. its location places it before the previous token.
   */
  public void visit(NodeToken n) {
    if (n.beginLine == -1 || n.beginColumn == -1) {
      printToken(n.tokenImage);
      return;
    }

    //
    // Handle special tokens
    //
    if (printSpecials && n.numSpecials() > 0)
      for (Enumeration<NodeToken> e = n.specialTokens.elements(); e.hasMoreElements(); )
        visit(e.nextElement());

    //
    // Handle startAtNextToken option
    //
    if (startAtNextToken) {
      curLine = n.beginLine;
      curColumn = 1;
      startAtNextToken = false;

      if (n.beginColumn < curColumn) out.println();
    }

    //
    // Check for invalid token position relative to current position.
    //
    if (n.beginLine < curLine)
      throw new IllegalStateException(
          "at token \""
              + n.tokenImage
              + "\", n.beginLine = "
              + Integer.toString(n.beginLine)
              + ", curLine = "
              + Integer.toString(curLine));
    else if (n.beginLine == curLine && n.beginColumn < curColumn)
      throw new IllegalStateException(
          "at token \""
              + n.tokenImage
              + "\", n.beginColumn = "
              + Integer.toString(n.beginColumn)
              + ", curColumn = "
              + Integer.toString(curColumn));

    //
    // Move output "cursor" to proper location, then print the token
    //
    if (curLine < n.beginLine) {
      curColumn = 1;
      for (; curLine < n.beginLine; ++curLine) out.println();
    }

    for (; curColumn < n.beginColumn; ++curColumn) out.print(" ");

    printToken(n.tokenImage);
  }
Ejemplo n.º 7
0
  public TimesExpression(PrimaryExpression n0, PrimaryExpression n1) {
    f0 = n0;
    if (f0 != null) f0.setParent(this);
    f1 = new NodeToken("*");
    if (f1 != null) f1.setParent(this);
    f2 = n1;
    if (f2 != null) f2.setParent(this);

    buildSubNodesList();
  }
 public AdapterStatement(
     AnnotationDeclaration n0,
     NodeToken n1,
     NodeToken n2,
     NodeToken n3,
     NodeToken n4,
     NodeListOptional n5,
     NodeToken n6) {
   annotationDeclaration = n0;
   if (annotationDeclaration != null) annotationDeclaration.setParent(this);
   nodeToken = n1;
   if (nodeToken != null) nodeToken.setParent(this);
   nodeToken1 = n2;
   if (nodeToken1 != null) nodeToken1.setParent(this);
   nodeToken2 = n3;
   if (nodeToken2 != null) nodeToken2.setParent(this);
   nodeToken3 = n4;
   if (nodeToken3 != null) nodeToken3.setParent(this);
   nodeListOptional = n5;
   if (nodeListOptional != null) nodeListOptional.setParent(this);
   nodeToken4 = n6;
   if (nodeToken4 != null) nodeToken4.setParent(this);
 }
Ejemplo n.º 9
0
 public CompilationUnit(
     NodeOptional n0, NodeListOptional n1, NodeListOptional n2, NodeOptional n3, NodeOptional n4) {
   f0 = n0;
   if (f0 != null) f0.setParent(this);
   f1 = n1;
   if (f1 != null) f1.setParent(this);
   f2 = n2;
   if (f2 != null) f2.setParent(this);
   f3 = n3;
   if (f3 != null) f3.setParent(this);
   f4 = n4;
   if (f4 != null) f4.setParent(this);
   f5 = new NodeToken("");
   if (f5 != null) f5.setParent(this);
 }
Ejemplo n.º 10
0
  /**
   * Executes the commands waiting in the command queue, then inserts the proper location
   * information into the current NodeToken.
   *
   * <p>If there are any special tokens preceding this token, they will be given the current
   * location information. The token will follow on the next line, at the proper indentation level.
   * If this is not the behavior you want from special tokens, feel free to modify this method.
   */
  public void visit(NodeToken n) {
    for (Enumeration<FormatCommand> e = cmdQueue.elements(); e.hasMoreElements(); ) {
      FormatCommand cmd = e.nextElement();
      switch (cmd.getCommand()) {
        case FormatCommand.FORCE:
          curLine += cmd.getNumCommands();
          curColumn = curIndent + 1;
          break;
        case FormatCommand.INDENT:
          curIndent += indentAmt * cmd.getNumCommands();
          break;
        case FormatCommand.OUTDENT:
          if (curIndent >= indentAmt) curIndent -= indentAmt * cmd.getNumCommands();
          break;
        case FormatCommand.SPACE:
          curColumn += cmd.getNumCommands();
          break;
        default:
          throw new TreeFormatterException("Invalid value in command queue.");
      }
    }

    cmdQueue.removeAllElements();

    //
    // Handle all special tokens preceding this NodeToken
    //
    if (n.numSpecials() > 0)
      for (Enumeration<NodeToken> e = n.specialTokens.elements(); e.hasMoreElements(); ) {
        NodeToken special = e.nextElement();

        //
        // -Place the token.
        // -Move cursor to next line after the special token.
        // -Don't update curColumn--want to keep current indent level.
        //
        placeToken(special, curLine, curColumn);
        curLine = special.endLine + 1;
      }

    placeToken(n, curLine, curColumn);
    curLine = n.endLine;
    curColumn = n.endColumn;
  }
Ejemplo n.º 11
0
 public String toString() {
   return value.toString();
 }
Ejemplo n.º 12
0
 public AccessPart(NodeToken n0, NodeToken n1) {
   key = n0;
   if (key != null) key.setParent(this);
   value = n1;
   if (value != null) value.setParent(this);
 }
Ejemplo n.º 13
0
 public AccessPart() {
   key = new NodeToken("ACCESS?");
   key.kind = ACCESS;
   value = new NodeToken("NOT-ACCESSIBLE");
   value.kind = NOT_ACCESSIBLE;
 }
Ejemplo n.º 14
0
 public LiteralExpression() {
   f0 = new NodeToken("\"");
   if (f0 != null) f0.setParent(this);
 }
Ejemplo n.º 15
0
 public LiteralExpression(NodeToken n0) {
   f0 = n0;
   if (f0 != null) f0.setParent(this);
 }