示例#1
0
        /// <summary>
        /// Syntax: rule : keyword ':' condition keyword: <identifier>
        /// </summary>
        ///
        private static PluralRules.Rule  ParseRule(String description)
        {
            int x = description.IndexOf(':');

            if (x == -1)
            {
                throw new ILOG.J2CsMapping.Util.ParseException("missing ':' in rule description '"
                                                               + description + "'" + 0);
            }

            String keyword = description.Substring(0, (x) - (0)).Trim();

            if (!IsValidKeyword(keyword))
            {
                throw new ILOG.J2CsMapping.Util.ParseException("keyword '" + keyword + " is not valid" + 0);
            }

            description = description.Substring(x + 1).Trim();
            if (description.Length == 0)
            {
                throw new ILOG.J2CsMapping.Util.ParseException("missing constraint in '" + description
                                                               + "'" + x + 1);
            }
            PluralRules.Constraint constraint = ParseConstraint(description);
            PluralRules.Rule       rule       = new PluralRules.ConstrainedRule(keyword, constraint);
            return(rule);
        }
示例#2
0
 public PluralRules.Rule  Or(PluralRules.Constraint c)
 {
     return(new PluralRules.ConstrainedRule(keyword, new PluralRules.OrConstraint(constraint, c)));
 }
示例#3
0
 public ConstrainedRule(String keyword_0, PluralRules.Constraint constraint_1)
 {
     this.keyword    = keyword_0;
     this.constraint = constraint_1;
 }
示例#4
0
 internal OrConstraint(PluralRules.Constraint a_0, PluralRules.Constraint b_1) : base(a_0, b_1, " || ")
 {
 }
示例#5
0
 internal AndConstraint(PluralRules.Constraint a_0, PluralRules.Constraint b_1) : base(a_0, b_1, " && ")
 {
 }
示例#6
0
 protected internal BinaryConstraint(PluralRules.Constraint a_0, PluralRules.Constraint b_1, String c)
 {
     this.a           = a_0;
     this.b           = b_1;
     this.conjunction = c;
 }
示例#7
0
        /// <summary>
        /// syntax: condition : or_condition and_condition or_condition :
        /// and_condition 'or' condition and_condition : relation relation 'and'
        /// relation relation : is_relation in_relation 'n' EOL is_relation : expr
        /// 'is' value expr 'is' 'not' value in_relation : expr 'in' range expr 'not'
        /// 'in' range expr : 'n' 'n' 'mod' value value : digit+ digit :
        /// 0|1|2|3|4|5|6|7|8|9 range : value'..'value
        /// </summary>
        ///
        private static PluralRules.Constraint  ParseConstraint(String description)
        {
            description = description.Trim().ToLower(System.Globalization.CultureInfo.CreateSpecificCulture("en"));

            PluralRules.Constraint result = null;
            String[] or_together          = IBM.ICU.Impl.Utility.SplitString(description, "or");
            for (int i = 0; i < or_together.Length; ++i)
            {
                PluralRules.Constraint andConstraint = null;
                String[] and_together = IBM.ICU.Impl.Utility.SplitString(or_together[i], "and");
                for (int j = 0; j < and_together.Length; ++j)
                {
                    PluralRules.Constraint newConstraint = NO_CONSTRAINT;

                    String   condition = and_together[j].Trim();
                    String[] tokens    = IBM.ICU.Impl.Utility.SplitWhitespace(condition);

                    int  mod       = 0;
                    bool within    = true;
                    long lowBound  = -1;
                    long highBound = -1;

                    bool isRange = false;

                    int    x = 0;
                    String t = tokens[x++];
                    if (!"n".Equals(t))
                    {
                        throw Unexpected(t, condition);
                    }
                    if (x < tokens.Length)
                    {
                        t = tokens[x++];
                        if ("mod".Equals(t))
                        {
                            mod = Int32.Parse(tokens[x++]);
                            t   = NextToken(tokens, x++, condition);
                        }
                        if ("is".Equals(t))
                        {
                            t = NextToken(tokens, x++, condition);
                            if ("not".Equals(t))
                            {
                                within = false;
                                t      = NextToken(tokens, x++, condition);
                            }
                        }
                        else
                        {
                            isRange = true;
                            if ("not".Equals(t))
                            {
                                within = false;
                                t      = NextToken(tokens, x++, condition);
                            }
                            if ("in".Equals(t))
                            {
                                t = NextToken(tokens, x++, condition);
                            }
                            else
                            {
                                throw Unexpected(t, condition);
                            }
                        }

                        if (isRange)
                        {
                            String[] pair = IBM.ICU.Impl.Utility.SplitString(t, "..");
                            if (pair.Length == 2)
                            {
                                lowBound  = ((Int64 )Int64.Parse(pair[0], System.Globalization.NumberStyles.Integer));
                                highBound = ((Int64 )Int64.Parse(pair[1], System.Globalization.NumberStyles.Integer));
                            }
                            else
                            {
                                throw Unexpected(t, condition);
                            }
                        }
                        else
                        {
                            lowBound = highBound = ((Int64 )Int64.Parse(t, System.Globalization.NumberStyles.Integer));
                        }

                        if (x != tokens.Length)
                        {
                            throw Unexpected(tokens[x], condition);
                        }

                        newConstraint = new PluralRules.RangeConstraint(mod, within, lowBound,
                                                                        highBound);
                    }

                    if (andConstraint == null)
                    {
                        andConstraint = newConstraint;
                    }
                    else
                    {
                        andConstraint = new PluralRules.AndConstraint(andConstraint,
                                                                      newConstraint);
                    }
                }

                if (result == null)
                {
                    result = andConstraint;
                }
                else
                {
                    result = new PluralRules.OrConstraint(result, andConstraint);
                }
            }

            return(result);
        }