⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resourcestatement.java

📁 外国人写的c#语法解析器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            controlElement.addContent(dataElement);
            do
            {
              node = node.getNextSibling();
              processEntryWithEvaluation(node, "data-element", dataElement);
            }
            while (node != null);
          }
        }
      }
    }
  }

  //------------------------------------------------------------------------------------------------
  
  /**
   * Converts a "cursor" entry to XML.
   * 
   * @param sourceNode The node containing the AST data to convert.
   * @param resourceElement The entry to which the new nodes must be added.
   */
  private void convertCursorEntry(AST sourceNode, Element resourceElement)
  {
    resourceElement.setAttribute("type", "cursor");

    AST currentNode = sourceNode.getFirstChild();
    if (currentNode != null)
    {
      if (currentNode.getType() == RCParserTokenTypes.RESOURCE_ATTRIBUTES)
      {
        convertResourceAttributes(resourceElement, currentNode);
        currentNode = currentNode.getNextSibling();
      }
    }    

    if (currentNode != null)
    {
      if (currentNode.getType() == RCParserTokenTypes.FILE_NAME)
      {
        String filename = currentNode.getFirstChild().getText();
        if (filename.startsWith("\""))
          filename = filename.substring(1, filename.length() - 1);
        resourceElement.setAttribute("file-name", filename);
      }
      else
      {
        // Must be raw data, e.g. single literals (string, character, integer etc.) or
        // a collection of hex numbers enclosed by single quotes.
        convertRawDataToXML(currentNode, resourceElement);
      }
    }
  }

  //------------------------------------------------------------------------------------------------
  
  /**
   * Converts a "designinfo" entry to XML.
   * 
   * @param sourceNode The node containing the AST data to convert.
   * @param resourceElement The entry to which the new nodes must be added.
   */
  private void convertDesignInfoEntry(AST sourceNode, Element resourceElement)
  {
    resourceElement.setAttribute("type", "design-info");

    AST currentNode = sourceNode.getFirstChild();
    if (currentNode != null)
    {
      if (currentNode.getType() == RCParserTokenTypes.RESOURCE_ATTRIBUTES)
      {
        convertResourceAttributes(resourceElement, currentNode);
        currentNode = currentNode.getNextSibling();
      }
      
      // The design info consists of a list of blocks for a certain control/dialog etc.
      // where each block itself consists of a list of design info values.
      while (currentNode != null)
      {
        // currentNode must always be of type DESIGN_INFO_CONTROL_BLOCK. The parser takes care for this.
        AST blockNode = currentNode.getFirstChild();
        
        // Add the block identification.
        Element blockElement = processEntryWithEvaluation(blockNode, "control-block", resourceElement);
        
        // Next is the resource entry class.
        blockNode = blockNode.getNextSibling();
        blockElement.setAttribute("class", blockNode.getText());
        
        blockNode = blockNode.getNextSibling();
        AST entryNode = blockNode.getFirstChild();
        while (entryNode != null)
        {
          Element entryElement = new Element("entry");
          entryElement.setAttribute("name", entryNode.getText());
          blockElement.addContent(entryElement);
          entryNode = entryNode.getNextSibling();
          Object value = evaluate(entryNode.getText(), entryNode.getLine(), entryNode.getColumn());
          if (value != null)
            entryElement.setAttribute("value", value.toString());
          
          entryNode = entryNode.getNextSibling();
        }
        
        currentNode = currentNode.getNextSibling();
      }
    }    
  }

  //------------------------------------------------------------------------------------------------
  
  /**
   * Converts a "dialog" entry to XML.
   * 
   * @param sourceNode The node containing the AST data to convert.
   * @param resourceElement The entry to which the new nodes must be added.
   */
  private void convertDialogEntry(AST sourceNode, Element resourceElement)
  {
    resourceElement.setAttribute("type", "dialog");

    AST currentNode = sourceNode.getFirstChild();
    if (currentNode != null)
    {
      if (currentNode.getType() == RCParserTokenTypes.RESOURCE_ATTRIBUTES)
      {
        convertResourceAttributes(resourceElement, currentNode);
        currentNode = currentNode.getNextSibling();
      }
    }    
    
    // Four fix expressions come now, giving left, top, width and height coordinates.
    processEntryWithEvaluation(currentNode, "left", resourceElement);
    currentNode = currentNode.getNextSibling();
    processEntryWithEvaluation(currentNode, "top", resourceElement);
    currentNode = currentNode.getNextSibling();
    processEntryWithEvaluation(currentNode, "width", resourceElement);
    currentNode = currentNode.getNextSibling();
    processEntryWithEvaluation(currentNode, "height", resourceElement);
    currentNode = currentNode.getNextSibling();
    
    // There might also be an optional set of common resource info.
    currentNode = convertCommonDialogInfo(currentNode, resourceElement);
    
    // Now there can be two ways how definition continues, generic controls or concrete controls.
    // The chain is finished when we encounter the common trailing (which starts with an expression).
    while (currentNode != null && currentNode.getType() != RCParserTokenTypes.EXPR)
    {
      if (currentNode.getType() == RCParserTokenTypes.CONCRETE_CONTROL)
        convertConcreteControl(currentNode.getFirstChild(), resourceElement);
      else
        convertGenericControl(currentNode.getFirstChild(), resourceElement);
      currentNode = currentNode.getNextSibling();
    }
  }

  //------------------------------------------------------------------------------------------------
  
  /**
   * Converts a "dialogex" entry to XML.
   * 
   * @param sourceNode The node containing the AST data to convert.
   * @param resourceElement The entry to which the new nodes must be added.
   */
  private void convertDialogExEntry(AST sourceNode, Element resourceElement)
  {
    resourceElement.setAttribute("type", "dialogex");

    AST currentNode = sourceNode.getFirstChild();
    if (currentNode != null)
    {
      if (currentNode.getType() == RCParserTokenTypes.RESOURCE_ATTRIBUTES)
      {
        convertResourceAttributes(resourceElement, currentNode);
        currentNode = currentNode.getNextSibling();
      }

      // Four fix expressions come now, giving left, top, width and height coordinates.
      processEntryWithEvaluation(currentNode.getFirstChild(), "left", resourceElement);
      currentNode = currentNode.getNextSibling();
      processEntryWithEvaluation(currentNode.getFirstChild(), "top", resourceElement);
      currentNode = currentNode.getNextSibling();
      processEntryWithEvaluation(currentNode.getFirstChild(), "width", resourceElement);
      currentNode = currentNode.getNextSibling();
      processEntryWithEvaluation(currentNode.getFirstChild(), "height", resourceElement);
      
      // There might be an optional help id value.
      currentNode = currentNode.getNextSibling();
      if (currentNode != null && currentNode.getType() == RCParserTokenTypes.EXPR)
      {
        processEntryWithEvaluation(currentNode.getFirstChild(), "help-id", resourceElement);
        currentNode = currentNode.getNextSibling();
      }
      
      // There might also be an optional set of common resource info.
      currentNode = convertCommonDialogInfo(currentNode, resourceElement);
      
      // Now there can be two ways how definition continues, generic controls or concrete controls.
      // The chain is finished when we encounter the common trailing (which starts with an expression).
      while (currentNode != null && currentNode.getType() != RCParserTokenTypes.EXPR)
      {
        if (currentNode.getType() == RCParserTokenTypes.CONCRETE_CONTROL)
          convertConcreteControl(currentNode.getFirstChild(), resourceElement);
        else
          convertGenericControl(currentNode.getFirstChild(), resourceElement);
        currentNode = currentNode.getNextSibling();
      }
    }    
  }

  //------------------------------------------------------------------------------------------------
  
  /**
   * Converts a "dlginit" entry to XML.
   * 
   * @param sourceNode The node containing the AST data to convert.
   * @param resourceElement The entry to which the new nodes must be added.
   */
  private void convertDlgInitEntry(AST sourceNode, Element resourceElement)
  {
    resourceElement.setAttribute("type", "dlginit");
    
    AST currentNode = sourceNode.getFirstChild();
    if (currentNode != null)
    {
      if (currentNode.getType() == RCParserTokenTypes.RESOURCE_ATTRIBUTES)
      {
        convertResourceAttributes(resourceElement, currentNode);
        currentNode = currentNode.getNextSibling();
      }
      
      // DLGINIT values are organized in chunks each beginning with an identifier.
      // One or more values follow this identifier.
      while (currentNode != null)
      {
        String symbol = currentNode.getText();
        Element dataElement = new Element("data");
        resourceElement.addContent(dataElement);
        dataElement.setAttribute("name", symbol);
        currentNode = currentNode.getNextSibling();
        while (currentNode != null)
        {
          // An identifier indicates the start of a new set of values.
          if (currentNode.getType() == RCParserTokenTypes.IDENTIFIER)
            break;
          
          processEntryWithEvaluation(currentNode, "entry", dataElement);
          currentNode = currentNode.getNextSibling(); 
        }
      }
    }
  }

  //------------------------------------------------------------------------------------------------
  
  /**
   * Converts a list of expressions (addressed by node) to XML subelements of <b>element</b>. The
   * method loops through all siblings of the given node until there aren't anymore.
   * 
   * @param node The node to convert.
   * @param element The target node to add the converted elements to.
   */
  private void convertExpressionList(AST node, Element element)
  {
    AST currentNode = node;
    while (currentNode != null)
    {
      Element valueElement = new Element("entry");
      element.addContent(valueElement);
      Object value = null;
      if (currentNode.getType() == RCParserTokenTypes.EXPR)
        value = evaluate(currentNode);
      else
      {
        String expression = currentNode.getText();
        value = evaluate(expression, currentNode.getLine(), currentNode.getColumn());
        valueElement.setAttribute("expression", expression);
      }
      if (value != null)
        valueElement.setAttribute("value", value.toString());
      else
        valueElement.setAttribute("value", convertExpressionToText(currentNode.getFirstChild()));
      currentNode = currentNode.getNextSibling();
    }
  }

  //------------------------------------------------------------------------------------------------
  
  /**
   * In the case an expression cannot be evaluated (e.g. because a macro cannot be resolved)
   * it is useful to print out at least the expression in text form. This method converts an AST
   * expression tree into plain text.
   * 
   * @param node
   * @return
   */
  private String convertExpressionToText(AST node)
  {
    if (node == null)
      return "";
    else
    {
      StringBuffer buffer = new StringBuffer();
      
      AST left = node.getFirstChild();
      AST right = null;
      if (left != null)
        right = left.getNextSibling();
      if (left != null)
      {
        String leftString = convertExpressionToText(left);
        buffer.append(leftString);
        buffer.append(" ");
      }
      buffer.append(node.getText());
      if (right != null)
      {
        buffer.append(" ");
        buffer.append(convertExpressionToText(right));
      }
      
      return buffer.toString();
    }
  }

  //------------------------------------------------------------------------------------------------
  
  /**
   * Converts a "font" entry to XML.
   * 
   * @param sourceNode The node containing the AST data to convert.
   * @param resourceElement The entry to which the new nodes must be added.
   */
  private void convertFontEntry(AST sourceNode, Element resourceElement)
  {
    resourceElement.setAttribute("type", "font");

    AST currentNode = sourceNode.getFirstChild();
    if (currentNode != null)
    {
      if (currentNode.getType() == RCParserTokenTypes.RESOURCE_ATTRIBUTES)
      {
        convertResourceAttributes(resourceElement, currentNode);
        currentNode = currentNode.getNextSibling();
      }

      // Must be a file name node.
      String filename = currentNode.getText();
      if (filename.startsWith("\""))
        filename = filename.substring(1, filename.length());
      resourceElement.setAttribute("file-name", filename);
    }    
  }

  //------------------------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -