pbwest      2002/10/08 23:02:51

  Modified:    src/org/apache/fop/fo/expr Tag: FOP_0-20-0_Alt-Design
                        PropertyParser.java PropertyTokenizer.java
  Log:
  Bug fixes and debugging output.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.5.2.13  +133 -44   xml-fop/src/org/apache/fop/fo/expr/PropertyParser.java
  
  Index: PropertyParser.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/expr/PropertyParser.java,v
  retrieving revision 1.5.2.12
  retrieving revision 1.5.2.13
  diff -u -r1.5.2.12 -r1.5.2.13
  --- PropertyParser.java       2 Oct 2002 07:23:18 -0000       1.5.2.12
  +++ PropertyParser.java       9 Oct 2002 06:02:51 -0000       1.5.2.13
  @@ -237,6 +237,7 @@
        */
       private PropertyValue parseAdditiveExpr() throws PropertyException {
           // Evaluate and put result on the operand stack
  +        System.out.println("parseAdd");
           PropertyValue prop = parseMultiplicativeExpr();
           loop:
           for (; ; ) {
  @@ -261,24 +262,109 @@
        * the resulting PropertyValue.
        */
       private PropertyValue parseMultiplicativeExpr() throws PropertyException {
  +        System.out.println("parseMult");
           PropertyValue prop = parseUnaryExpr();
  -        loop:
  +        PropertyValue pv;
  +        outer:
  +        // Outer loop exists to handle a sequence of multiplicative operations
  +        // e.g. 5 * 4 / 2
  +        // break outer; will terminate the multiplicative expression parsing
  +        // break inner; will look for another trailing multiplicative
  +        // operator.
           for (; ; ) {
  -            switch (currentToken) {
  -            case DIV:
  -                next();
  -                ((Numeric)prop).divide((Numeric)parseUnaryExpr());
  -                break;
  -            case MOD:
  -                next();
  -                ((Numeric)prop).mod((Numeric)parseUnaryExpr());
  -                break;
  -            case MULTIPLY:
  -                next();
  -                ((Numeric)prop).multiply((Numeric)parseUnaryExpr());
  -                break;
  +            inner:
  +            switch (prop.getType()) {
  +            case PropertyValue.NUMERIC:
  +                switch (currentToken) {
  +                case DIV:
  +                    next();
  +                    System.out.println("Dividing......");
  +                    pv = parseUnaryExpr();
  +                    if (pv.getType() == PropertyValue.INTEGER) {
  +                        ((Numeric)prop).divide
  +                                        ((double)(((IntegerType)pv).getInt()));
  +                        break inner;
  +                    }  // else must be Numeric
  +                    ((Numeric)prop).divide((Numeric)pv);
  +                    break inner;
  +                case MOD:
  +                    next();
  +                    pv = parseUnaryExpr();
  +                    if (pv.getType() == PropertyValue.INTEGER) {
  +                        ((Numeric)prop).mod
  +                                        ((double)(((IntegerType)pv).getInt()));
  +                        break inner;
  +                    }  // else must be Numeric
  +                    ((Numeric)prop).mod((Numeric)parseUnaryExpr());
  +                    break inner;
  +                case MULTIPLY:
  +                    next();
  +                    System.out.println("Multiplying......");
  +                    pv = parseUnaryExpr();
  +                    System.out.println("...by " + pv);
  +                    if (pv.getType() == PropertyValue.INTEGER) {
  +                        ((Numeric)prop).multiply
  +                                        ((double)(((IntegerType)pv).getInt()));
  +                        break inner;
  +                    }  // else must be Numeric
  +                    ((Numeric)prop).multiply((Numeric)pv);
  +                    break inner;
  +                default:
  +                    break outer;
  +                }
  +                // N.B. The above case cannot fall through to here
  +            case PropertyValue.INTEGER:
  +                // This code treats all multiplicative operations as implicit
  +                // operations on doubles.  It might be reasonable to allow
  +                // an integer multiply.
  +                switch (currentToken) {
  +                case DIV:
  +                    next();
  +                    System.out.println("Dividing......");
  +                    pv = parseUnaryExpr();
  +                    if (pv.getType() == PropertyValue.INTEGER) {
  +                        prop = new Numeric(property,
  +                                (double)(((IntegerType)prop).getInt()) /
  +                                                 ((IntegerType)pv).getInt());
  +                        break inner;
  +                    }  // else must be Numeric
  +                    prop = (new Numeric(property,
  +                                    (double)(((IntegerType)prop).getInt())))
  +                            .divide((Numeric)pv);
  +                    break inner;
  +                case MOD:
  +                    next();
  +                    pv = parseUnaryExpr();
  +                    if (pv.getType() == PropertyValue.INTEGER) {
  +                        prop = new Numeric(property,
  +                                (double)(((IntegerType)prop).getInt()) %
  +                                                 ((IntegerType)pv).getInt());
  +                        break inner;
  +                    }  // else must be Numeric
  +                    prop = (new Numeric(property,
  +                                    (double)(((IntegerType)prop).getInt())))
  +                            .mod((Numeric)pv);
  +                    break inner;
  +                case MULTIPLY:
  +                    next();
  +                    System.out.println("Multiplying......");
  +                    pv = parseUnaryExpr();
  +                    System.out.println("...by " + pv);
  +                    if (pv.getType() == PropertyValue.INTEGER) {
  +                        prop = new Numeric(property,
  +                                (double)(((IntegerType)prop).getInt()) *
  +                                                 ((IntegerType)pv).getInt());
  +                        break inner;
  +                    }  // else must be Numeric
  +                    prop = (new Numeric(property,
  +                                    (double)(((IntegerType)prop).getInt())))
  +                            .multiply((Numeric)pv);
  +                    break inner;
  +                default:
  +                    break outer;
  +                }
               default:
  -                break loop;
  +                break outer;
               }
           }
           return prop;
  @@ -289,8 +375,10 @@
        * resulting PropertyValue.
        */
       private PropertyValue parseUnaryExpr() throws PropertyException {
  +        System.out.println("Unary entry");
           if (currentToken == MINUS) {
               next();
  +            System.out.println("Unary");
               return ((Numeric)parseUnaryExpr()).negate();
           }
           return parsePrimaryExpr();
  @@ -317,6 +405,8 @@
        */
       private PropertyValue parsePrimaryExpr() throws PropertyException {
           PropertyValue prop;
  +        System.out.println("Primary currentToken:" + currentToken + " "
  +                           + currentTokenValue);
           switch (currentToken) {
           case LPAR:
               next();
  @@ -417,47 +507,46 @@
               // and the return from this method must be premature
               prop = null;
               int funcType = PropertyValue.NO_TYPE;
  +            String function = currentTokenValue;
  +            next();
               do {
                   // Numeric functions
  -                if (currentTokenValue.equals("floor")) {
  +                if (function.equals("floor")) {
                       PropertyValue[] args = parseArgs(1);
                       prop = new Numeric
                               (property, ((Numeric)args[0]).floor());
                       break;
                   }
  -                if (currentTokenValue.equals("ceiling")) {
  +                if (function.equals("ceiling")) {
                       PropertyValue[] args = parseArgs(1);
                       prop = new Numeric
                               (property, ((Numeric)args[0]).ceiling());
                       break;
                   }
  -                if (currentTokenValue.equals("round")) {
  +                if (function.equals("round")) {
                       PropertyValue[] args = parseArgs(1);
                       prop = new Numeric
                               (property, ((Numeric)args[0]).round());
                       break;
                   }
  -                if (currentTokenValue.equals("min")) {
  +                if (function.equals("min")) {
                       PropertyValue[] args = parseArgs(2);
  -                    prop = new Numeric
  -                        (property, ((Numeric)args[0]).min((Numeric)args[1]));
  +                    prop = ((Numeric)args[0]).min((Numeric)args[1]);
                       break;
                   }
  -                if (currentTokenValue.equals("max")) {
  +                if (function.equals("max")) {
                       PropertyValue[] args = parseArgs(2);
  -                    prop = new Numeric
  -                        (property, ((Numeric)args[0]).max((Numeric)args[1]));
  +                    prop = ((Numeric)args[0]).max((Numeric)args[1]);
                       break;
                   }
  -                if (currentTokenValue.equals("abs")) {
  +                if (function.equals("abs")) {
                       PropertyValue[] args = parseArgs(1);
  -                    prop = new Numeric
  -                            (property, ((Numeric)args[0]).abs());
  +                    prop = ((Numeric)args[0]).abs();
                       break;
                   }
   
                   // Color functions
  -                if (currentTokenValue.equals("rgb")) {
  +                if (function.equals("rgb")) {
                       PropertyValue[] args = parseArgs(3);
                       prop = new ColorType
                               (property, ((Numeric)args[0]).asInt(),
  @@ -465,12 +554,12 @@
                                ((Numeric)args[2]).asInt());
                       break;
                   }
  -                if (currentTokenValue.equals("rgb-icc")) {
  +                if (function.equals("rgb-icc")) {
                       PropertyValue[] args = parseArgs(6);
                       throw new FunctionNotImplementedException("rgb-icc");
                       //break;
                   }
  -                if (currentTokenValue.equals("system-color")) {
  +                if (function.equals("system-color")) {
                       PropertyValue[] args = parseArgs(1);
                       prop = new ColorType
                               (property, ((StringType)args[0]).getString());
  @@ -478,7 +567,7 @@
                   }
   
                   // Font function
  -                if (currentTokenValue.equals("system-font")) {
  +                if (function.equals("system-font")) {
                       PropertyValue[] args = parseArgs(1, 2);
                       if (args.length == 1) {
                           prop = SystemFontFunction.systemFontCharacteristic
  @@ -495,17 +584,17 @@
                   }
   
                   // Property value functions
  -                if (currentTokenValue.equals("label-end")) {
  +                if (function.equals("label-end")) {
                       PropertyValue[] args = parseArgs(0);
                       throw new FunctionNotImplementedException("label-end");
                       //break;
                   }
  -                if (currentTokenValue.equals("body-start")) {
  +                if (function.equals("body-start")) {
                       PropertyValue[] args = parseArgs(0);
                       throw new FunctionNotImplementedException("body-start");
                       //break;
                   }
  -                if (currentTokenValue.equals("inherited-property-value")) {
  +                if (function.equals("inherited-property-value")) {
                       int propindex = property;
                       PropertyValue[] args = parseArgs(0, 1);
                       if (args.length != 0)
  @@ -530,9 +619,9 @@
                   }
                   // N.B. see comments on classes FromNearestSpecified and
                   // FromParent for explanation of this section
  -                if (currentTokenValue.equals("from-parent"))
  +                if (function.equals("from-parent"))
                       funcType = PropertyValue.FROM_PARENT;
  -                if (currentTokenValue.equals("from-nearest-specified-value"))
  +                if (function.equals("from-nearest-specified-value"))
                       funcType = PropertyValue.FROM_NEAREST_SPECIFIED;
                   if (funcType == PropertyValue.FROM_PARENT
                       || funcType == PropertyValue.FROM_NEAREST_SPECIFIED)
  @@ -564,7 +653,7 @@
                       } else { // one argument - it must be a property name
                           if ( ! (args[0] instanceof NCName))
                               throw new PropertyException
  -                                    (currentTokenValue + " function requires"
  +                                    (function + " function requires"
                                        + " property name arg.");
                           // else arg[0] is an NCName
                           NCName ncname = (NCName)args[0];
  @@ -579,7 +668,7 @@
                               // see 5.10.4 Property Value Functions
                               if ( ! (nameindex == property))
                                   throw new PropertyException
  -                                        (currentTokenValue +
  +                                        (function +
                                            " argument " + propname +
                                            " does not match property " +
                                            PropNames.getPropertyName(property));
  @@ -601,26 +690,26 @@
                       }
                       break;
                   }
  -                if (currentTokenValue.equals("from-table-column")) {
  +                if (function.equals("from-table-column")) {
                       PropertyValue[] args = parseArgs(0, 1);
                       throw new FunctionNotImplementedException
                               ("from-table-column");
                       //break;
                   }
  -                if (currentTokenValue.equals("proportional-column-width")) {
  +                if (function.equals("proportional-column-width")) {
                       PropertyValue[] args = parseArgs(1);
                       throw new FunctionNotImplementedException
                               ("proportional-column-width");
                       //break;
                   }
  -                if (currentTokenValue.equals("merge-property-values")) {
  +                if (function.equals("merge-property-values")) {
                       PropertyValue[] args = parseArgs(0, 1);
                       throw new FunctionNotImplementedException
                               ("merge-property-values");
                       //break;
                   }
                   throw new PropertyException("no such function: "
  -                                                        + currentTokenValue);
  +                                                        + function);
               } while (false);
               return prop;
           }
  
  
  
  1.4.4.5   +9 -4      xml-fop/src/org/apache/fop/fo/expr/PropertyTokenizer.java
  
  Index: PropertyTokenizer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/expr/PropertyTokenizer.java,v
  retrieving revision 1.4.4.4
  retrieving revision 1.4.4.5
  diff -u -r1.4.4.4 -r1.4.4.5
  --- PropertyTokenizer.java    2 Oct 2002 07:19:59 -0000       1.4.4.4
  +++ PropertyTokenizer.java    9 Oct 2002 06:02:51 -0000       1.4.4.5
  @@ -132,6 +132,7 @@
        * @throws PropertyException If un unrecognized token is encountered.
        */
       void next() throws PropertyException {
  +        System.out.println("expr:" + expr + ":  exprIndex: " + exprIndex);
           currentTokenValue = null;
           currentTokenStartIndex = exprIndex;
           boolean bSawDecimal;
  @@ -154,6 +155,7 @@
                   //currentTokenValue = expr.substring(currentTokenStartIndex,
                   //                                   exprIndex);
                   //return;
  +                currentTokenStartIndex = exprIndex;
                   break;
               case ',':
                   currentToken = COMMA;
  @@ -225,6 +227,7 @@
                           && isDigit(expr.charAt(exprIndex))) {
                       ++exprIndex;
                       scanDigits();
  +                    currentUnitIndex = exprIndex;
                       if (exprIndex < exprLength
                               && expr.charAt(exprIndex) == '%') {
                           exprIndex++;
  @@ -236,7 +239,7 @@
                               currentToken = FLOAT;
                       }
                       currentTokenValue = expr.substring(currentTokenStartIndex,
  -                                                       exprIndex);
  +                                                       currentUnitIndex);
                       return;
                   }
                   throw new PropertyException("illegal character '.'");
  @@ -274,10 +277,11 @@
                                                      exprIndex);
                   if (currentTokenValue.equals("mod")) {
                       currentToken = MOD;
  -                    return;
  +                   return;
                   }
                   if (currentTokenValue.equals("div")) {
                       currentToken = DIV;
  +                    System.out.println("Returning DIV......");
                       return;
                   }
                   if (currentTokenValue.equals("inherit")) {
  @@ -338,6 +342,7 @@
                   }
                   if (followingParen()) {
                       currentToken = FUNCTION_LPAR;
  +                    System.out.println("FUNCTION_LPAR exprIndex:" + exprIndex);
                   } else {
                       currentToken = NCNAME;
                   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to