コード例 #1
0
        private Property parsePrimaryExpr()
        {
            Property prop;

            switch (currentToken)
            {
            case TOK_LPAR:
                next();
                prop = parseAdditiveExpr();
                expectRpar();
                return(prop);

            case TOK_LITERAL:
                prop = new StringProperty(currentTokenValue);
                break;

            case TOK_NCNAME:
                prop = new NCnameProperty(currentTokenValue);
                break;

            case TOK_FLOAT:
                prop = new NumberProperty(ParseDouble(currentTokenValue));
                break;

            case TOK_INTEGER:
                prop = new NumberProperty(Int32.Parse(currentTokenValue));
                break;

            case TOK_PERCENT:
                double pcval = ParseDouble(
                    currentTokenValue.Substring(0, currentTokenValue.Length - 1)) / 100.0;
                IPercentBase pcBase = this.propInfo.GetPercentBase();
                if (pcBase != null)
                {
                    if (pcBase.GetDimension() == 0)
                    {
                        prop = new NumberProperty(pcval * pcBase.GetBaseValue());
                    }
                    else if (pcBase.GetDimension() == 1)
                    {
                        prop = new LengthProperty(new PercentLength(pcval,
                                                                    pcBase));
                    }
                    else
                    {
                        throw new PropertyException("Illegal percent dimension value");
                    }
                }
                else
                {
                    prop = new NumberProperty(pcval);
                }
                break;

            case TOK_NUMERIC:
                int    numLen   = currentTokenValue.Length - currentUnitLength;
                string unitPart = currentTokenValue.Substring(numLen);
                double numPart  = ParseDouble(currentTokenValue.Substring(0, numLen));
                Length length   = null;
                if (unitPart.Equals(RELUNIT))
                {
                    length = new FixedLength(numPart, propInfo.currentFontSize());
                }
                else
                {
                    length = new FixedLength(numPart, unitPart);
                }
                if (length == null)
                {
                    throw new PropertyException("unrecognized unit name: " + currentTokenValue);
                }
                else
                {
                    prop = new LengthProperty(length);
                }
                break;

            case TOK_COLORSPEC:
                prop = new ColorTypeProperty(new ColorType(currentTokenValue));
                break;

            case TOK_FUNCTION_LPAR:
            {
                IFunction function =
                    (IFunction)functionTable[currentTokenValue];
                if (function == null)
                {
                    throw new PropertyException("no such function: "
                                                + currentTokenValue);
                }
                next();
                propInfo.pushFunction(function);
                prop = function.Eval(parseArgs(function.NumArgs), propInfo);
                propInfo.popFunction();
                return(prop);
            }

            default:
                throw new PropertyException("syntax error");
            }
            next();
            return(prop);
        }
コード例 #2
0
ファイル: PropertyParser.cs プロジェクト: nholik/Fo.Net
        private Property parsePrimaryExpr()
        {
            Property prop;
            switch (currentToken)
            {
                case TOK_LPAR:
                    next();
                    prop = parseAdditiveExpr();
                    expectRpar();
                    return prop;

                case TOK_LITERAL:
                    prop = new StringProperty(currentTokenValue);
                    break;

                case TOK_NCNAME:
                    prop = new NCnameProperty(currentTokenValue);
                    break;

                case TOK_FLOAT:
                    prop = new NumberProperty(ParseDouble(currentTokenValue));
                    break;

                case TOK_INTEGER:
                    prop = new NumberProperty(Int32.Parse(currentTokenValue));
                    break;

                case TOK_PERCENT:
                    double pcval = ParseDouble(
                        currentTokenValue.Substring(0, currentTokenValue.Length - 1)) / 100.0;
                    IPercentBase pcBase = this.propInfo.GetPercentBase();
                    if (pcBase != null)
                    {
                        if (pcBase.GetDimension() == 0)
                        {
                            prop = new NumberProperty(pcval * pcBase.GetBaseValue());
                        }
                        else if (pcBase.GetDimension() == 1)
                        {
                            prop = new LengthProperty(new PercentLength(pcval,
                                                                        pcBase));
                        }
                        else
                        {
                            throw new PropertyException("Illegal percent dimension value");
                        }
                    }
                    else
                    {
                        prop = new NumberProperty(pcval);
                    }
                    break;

                case TOK_NUMERIC:
                    int numLen = currentTokenValue.Length - currentUnitLength;
                    string unitPart = currentTokenValue.Substring(numLen);
                    double numPart = ParseDouble(currentTokenValue.Substring(0, numLen));
                    Length length = null;
                    if (unitPart.Equals(RELUNIT))
                    {
                        length = new FixedLength(numPart, propInfo.currentFontSize());
                    }
                    else
                    {
                        length = new FixedLength(numPart, unitPart);
                    }
                    if (length == null)
                    {
                        throw new PropertyException("unrecognized unit name: " + currentTokenValue);
                    }
                    else
                    {
                        prop = new LengthProperty(length);
                    }
                    break;

                case TOK_COLORSPEC:
                    prop = new ColorTypeProperty(new ColorType(currentTokenValue));
                    break;

                case TOK_FUNCTION_LPAR:
                    {
                        IFunction function =
                            (IFunction)functionTable[currentTokenValue];
                        if (function == null)
                        {
                            throw new PropertyException("no such function: "
                                + currentTokenValue);
                        }
                        next();
                        propInfo.pushFunction(function);
                        prop = function.Eval(parseArgs(function.NumArgs), propInfo);
                        propInfo.popFunction();
                        return prop;
                    }
                default:
                    throw new PropertyException("syntax error");
            }
            next();
            return prop;
        }