Ejemplo n.º 1
0
        protected bool EvaluateForRange(string expression, ParseDelegate parse)
        {
            expression = expression.Trim();

            Regex regex = new Regex(@"(?<min>[^:]+):(?<max>.+)");
            Match match = regex.Match(expression);

            if (!match.Success)
            {
                return(false);
            }
            method = Method.RANGE;

            choices = new T[2];

            try {
                choices[0] = parse.Invoke(match.Groups["min"].Value);
            } catch (Exception e) {
                throw new Exception($"DynamicValue could not parse '{match.Groups["min"].Value}' in EvaluateForRange: {e}");
            }

            try {
                choices[0] = parse.Invoke(match.Groups["max"].Value);
            } catch (Exception e) {
                throw new Exception($"DynamicValue could not parse '{match.Groups["max"].Value}' in EvaluateForRange: {e}");
            }

            return(true);
        }
Ejemplo n.º 2
0
        protected bool EvaluateForChoice(string expression, ParseDelegate parse)
        {
            expression = expression.Trim();

            if (!Regex.IsMatch(expression, @"^\[[^\]]+\]$"))
            {
                return(false);
            }
            method = Method.CHOICE;

            Regex           regex   = new Regex(@"\s*([^,\[\]]+),*");
            MatchCollection matches = regex.Matches(expression);

            choices = new T[matches.Count];
            for (int i = 0; i < matches.Count; i++)
            {
                try {
                    choices[i] = parse.Invoke(matches[i].Groups[1].Value);
                } catch (Exception e) {
                    throw new Exception($"DynamicValue could not parse '{matches[i].Groups[1].Value}' in EvaluateForChoice: {e}");
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Execute parsing method checking research deep.
        /// </summary>
        private static bool Parse(ParseDelegate action, SyntacticState state, SyntacticItem[] args)
        {
            state.Deep++;

#if DEBUG
            Debug.WriteLine(String.Empty);
            Debug.WriteLine(state.GetOuterDebug());

            SyntacticItem debugItem = (SyntacticItem)action.Target;
            Debug.WriteLine("[{0}] ({1})", debugItem.Key, state.Deep);

            string debugMethod = action.Method.Name;
            debugMethod = debugMethod
                          .Split(
                new[] { "Parse", "Internal", "<", ">" },
                StringSplitOptions.RemoveEmptyEntries)
                          .First()
                          .ToUpperInvariant();

            Debug.Write(debugMethod);
            Debug.Write(" =");
            foreach (var arg in args.Where(arg => arg != null))
            {
                Debug.Write(" | ");
                Debug.Write(arg.Key);
            }

            Debug.WriteLine(String.Empty);
#endif

            if (state.Deep >= c_maxResearchDeep)
            {
                throw new InvalidOperationException(
                          String.Format("Maximum research deep {0} has been reached.", c_maxResearchDeep));
            }

            bool parsed = action.Invoke(state, args);

            state.Deep--;
            return(parsed);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Execute parsing method checking research deep.
        /// </summary>
        private static bool Parse(ParseDelegate action, SyntacticState state, SyntacticItem[] args)
        {
            state.Deep++;

            #if DEBUG
            Debug.WriteLine(String.Empty);
            Debug.WriteLine(state.GetOuterDebug());

            SyntacticItem debugItem = (SyntacticItem)action.Target;
            Debug.WriteLine("[{0}] ({1})", debugItem.Key, state.Deep);

            string debugMethod = action.Method.Name;
            debugMethod = debugMethod
                .Split(
                    new[] { "Parse", "Internal", "<", ">" },
                    StringSplitOptions.RemoveEmptyEntries)
                .First()
                .ToUpperInvariant();

            Debug.Write(debugMethod);
            Debug.Write(" =");
            foreach (var arg in args.Where(arg => arg != null))
            {
                Debug.Write(" | ");
                Debug.Write(arg.Key);
            }

            Debug.WriteLine(String.Empty);
            #endif

            if (state.Deep >= c_maxResearchDeep)
                throw new InvalidOperationException(
                    String.Format("Maximum research deep {0} has been reached.", c_maxResearchDeep));

            bool parsed = action.Invoke(state, args);

            state.Deep--;
            return parsed;
        }