Example #1
0
        public override Pred CodeToPred(LNode expr, ref string errorMsg)
        {
            bool     isInt = false;
            PGIntSet set;

            if (expr.IsIdNamed(_underscore))
            {
                set = PGIntSet.AllExceptEOF;
            }
            else if (expr.IsIdNamed(_EOF))
            {
                set = PGIntSet.EOF;
            }
            else if (expr.Calls(S.DotDot, 2))
            {
                int?from = ConstValue(expr.Args[0], ref isInt);
                int?to   = ConstValue(expr.Args[1], ref isInt);
                if (from == null || to == null)
                {
                    errorMsg = "Expected int32 or character literal on each side of «..»";
                    return(null);
                }
                set = PGIntSet.WithRanges(from.Value, to.Value);
            }
            else if (expr.Value is string)
            {
                return(Pred.Seq((string)expr.Value));
            }
            else
            {
                int?num = ConstValue(expr, ref isInt);
                if (num == null)
                {
                    errorMsg = "Unrecognized expression. Expected int32 or character literal instead of: " + expr.ToString();                     // warning
                    return(null);
                }
                set = PGIntSet.With(num.Value);
            }
            set.IsCharSet = !isInt;
            return(new TerminalPred(expr, set, true));
        }