Example #1
0
        public void CreateRGGTransition(string from, string to, TransitionType transitionType, params object[] args)
        {
            RGGNode fromNode = GetNode(from);

            if (transitionType == TransitionType.PatternStart)
            {
                if (!_patternStartRGGNodes.ContainsKey(from))
                {
                    _patternStartRGGNodes.Add(from, fromNode);
                }
            }
            RGGTransition transition = new RGGTransition(fromNode, GetNode(to), transitionType, args);
        }
Example #2
0
        public RGGNode GetNode(string nodeName)
        {
            RGGNode returnNode;

            if (_rGGNodes.TryGetValue(nodeName, out returnNode))
            {
                return(returnNode);
            }
            else
            {
                returnNode = new RGGNode(nodeName);
                _rGGNodes.Add(returnNode.Name, returnNode);
                return(returnNode);
            }
        }
Example #3
0
        public RGGTransition(RGGNode from, RGGNode to, TransitionType transitionType, params object[] args)
        {
            From = from;
            From.AddTransition(this);
            To             = to;
            TransitionType = transitionType;
            switch (transitionType)
            {
            case TransitionType.PatternStart:
            case TransitionType.PatternEnd:
                break;

            case TransitionType.NonTerminalNonRecursive:
            case TransitionType.NonTerminalRecursive:
                if (args.Count() > 0 && args[0] is string)
                {
                    NonTerminal = args[0] as string;
                }
                else
                {
                    throw new Exception("NonTerminalNonRecursive/NonTerminalRecursive expect args of one string");
                }
                break;

            case TransitionType.Terminal:
                if (args.Count() > 0 && args[0] is TerminalPattern)
                {
                    Terminal = args[0] as TerminalPattern;
                }
                else
                {
                    throw new Exception("Terminal expect args of one TerminalPattern");
                }
                break;

            case TransitionType.GroupStart:
                if (args.Count() == 1 && args[0] is string)
                {
                    Internal = args[0] as string;
                }
                else
                {
                    throw new Exception("GroupStart expect args of one string");
                }
                break;

            case TransitionType.GroupEnd:
                if (args.Count() == 1 && args[0] is string)
                {
                    Internal = args[0] as string;
                }
                else
                {
                    throw new Exception("GroupEnd expect args of one string and one start Node name");
                }
                break;

            case TransitionType.Pop:
                if (args.Count() > 0)
                {
                    for (int counter = 0; counter < args.Count(); counter += 1)
                    {
                        if (args[counter] is string)
                        {
                            PopList.Add(args[counter] as string);
                        }
                        else
                        {
                            throw new Exception(string.Format("{0} value of args expected to be string: was {1}", counter, args[counter].GetType().Name));
                        }
                    }
                }
                break;

            case TransitionType.Push:
                if (args.Count() > 0)
                {
                    if (args[0] is TerminalPattern)
                    {
                        Terminal = args[0] as TerminalPattern;
                    }
                    else
                    {
                        throw new Exception(string.Format("First value of args expected to be char: was {0}", args[0]));
                    }
                    for (int counter = 1; counter < args.Count(); counter += 1)
                    {
                        if (args[counter] is string)
                        {
                            PushList.Add(args[counter] as string);
                        }
                        else
                        {
                            throw new Exception(string.Format("{0} value of args expected to be string: was {1}", counter, args[counter].GetType().Name));
                        }
                    }
                }
                else
                {
                    throw new Exception(string.Format("Push transition from node {0} to {1} missing arguments", From.Name, To.Name));
                }
                break;
            }
        }