예제 #1
0
        /// <summary>
        /// numeric :
        ///     PLUS_SIGN? UNSIGNED_INTEGER
        ///     | APPROXIMATE_NUM_LIT
        ///     ;
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static int ToInteger(this PlSqlParser.NumericContext context)
        {
            string value = null;

            var unsigned_integer = context.UNSIGNED_INTEGER();

            if (unsigned_integer != null)
            {
                value = unsigned_integer.GetText();
            }
            else
            {
                var approximate_num_lit = context.APPROXIMATE_NUM_LIT();
                value = approximate_num_lit.GetText();
            }

            try
            {
                return(int.Parse(value));
            }
            catch (Exception e)
            {
                throw;
            }
        }
예제 #2
0
        public static int?Integer(PlSqlParser.NumericContext context)
        {
            if (context == null)
            {
                return(null);
            }

            var text = context.GetText();
            int value;

            if (!Int32.TryParse(text, out value))
            {
                throw new ParseCanceledException(String.Format("Numeric '{0}' is not an integer.", text));
            }

            return(value);
        }
예제 #3
0
        /// <summary>
        /// UNSIGNED_INTEGER | APPROXIMATE_NUM_LIT
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override object VisitNumeric([NotNull] PlSqlParser.NumericContext context)
        {
            var unsigned = context.UNSIGNED_INTEGER();

            if (unsigned != null)
            {
                return(GetUnsignedInteger(unsigned));
            }

            else
            {
                // FLOAT_FRAGMENT ('E' ('+'|'-')? (FLOAT_FRAGMENT | [0-9]+))? ('D' | 'F')?;

                var litt = context.APPROXIMATE_NUM_LIT().GetText();
                Stop();
            }

            return(base.VisitNumeric(context));
        }
예제 #4
0
        public static int?PositiveInteger(PlSqlParser.NumericContext context)
        {
            if (context == null)
            {
                return(null);
            }

            var text = context.GetText();

            if (!Int32.TryParse(text, out var value))
            {
                throw new ParseCanceledException($"Numeric '{text}' is not an integer.");
            }
            if (value < 0)
            {
                throw new ParseCanceledException($"Integer '{text}' is not positive.");
            }

            return(value);
        }