Пример #1
0
  @Nonnull
  private CSSExpressionMemberMath _createExpressionMathTerm(@Nonnull final CSSNode aNode) {
    _expectNodeType(aNode, ECSSNodeType.MATH);

    final CSSExpressionMemberMath ret = new CSSExpressionMemberMath();
    ret.setSourceLocation(aNode.getSourceLocation());

    // read all sums
    for (final CSSNode aChildNode : aNode) {
      if (ECSSNodeType.MATHPRODUCT.isNode(aChildNode, m_eVersion)) {
        ret.addMember(_createExpressionMathProduct(aChildNode));
      } else if (ECSSNodeType.MATHSUMOPERATOR.isNode(aChildNode, m_eVersion)) {
        final String sText = aChildNode.getText();
        final ECSSMathOperator eMathOp = ECSSMathOperator.getFromNameOrNull(sText);
        if (eMathOp == null) s_aLogger.error("Failed to parse math operator '" + sText + "'");
        else ret.addMember(eMathOp);
      } else
        s_aLogger.error(
            "Unsupported child of "
                + ECSSNodeType.getNodeName(aNode, m_eVersion)
                + ": "
                + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
    }

    return ret;
  }
Пример #2
0
  @Nonnull
  private CSSExpressionMemberMathProduct _createExpressionMathProduct(
      @Nonnull final CSSNode aNode) {
    _expectNodeType(aNode, ECSSNodeType.MATHPRODUCT);

    final CSSExpressionMemberMathProduct ret = new CSSExpressionMemberMathProduct();
    ret.setSourceLocation(aNode.getSourceLocation());

    // read all sums
    for (final CSSNode aChildNode : aNode) {
      if (ECSSNodeType.MATHUNIT.isNode(aChildNode, m_eVersion)) {
        final int nChildCount = aChildNode.jjtGetNumChildren();
        if (nChildCount == 0) {
          final CSSExpressionMemberMathUnitSimple aMember =
              new CSSExpressionMemberMathUnitSimple(aChildNode.getText());
          aMember.setSourceLocation(aChildNode.getSourceLocation());
          ret.addMember(aMember);
        } else {
          if (nChildCount != 1)
            _throwUnexpectedChildrenCount(
                aChildNode, "CSS math unit expected 1 child and got " + nChildCount);

          final CSSNode aChildChildNode = aChildNode.jjtGetChild(0);
          final CSSExpressionMemberMathProduct aNestedProduct =
              _createExpressionMathProduct(aChildChildNode);
          final CSSExpressionMemberMathUnitProduct aMember =
              new CSSExpressionMemberMathUnitProduct(aNestedProduct);
          // Source location is taken from aNestedProduct
          ret.addMember(aMember);
        }
      } else if (ECSSNodeType.MATHPRODUCTOPERATOR.isNode(aChildNode, m_eVersion)) {
        final String sText = aChildNode.getText();
        final ECSSMathOperator eMathOp = ECSSMathOperator.getFromNameOrNull(sText);
        if (eMathOp == null)
          s_aLogger.error("Failed to parse math product operator '" + sText + "'");
        else ret.addMember(eMathOp);
      } else
        s_aLogger.error(
            "Unsupported child of "
                + ECSSNodeType.getNodeName(aNode, m_eVersion)
                + ": "
                + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
    }

    return ret;
  }