public object VisitLinkCreation(KpLinguaParser.LinkCreationContext context)
 {
     return(LinkRule.LinkCreate(new InstanceIdentifier(context.typeReference().Accept(this) as string)));
 }
        private Rule readRule(XPathNavigator nav)
        {
            ConsumerRule rule = null;

            XPathNavigator rhsNav = nav.SelectSingleNode("rhs");

            if (rhsNav != null)
            {
                Multiset          m = readMultiset(rhsNav);
                XPathNodeIterator div;
                if (m.IsEmpty())
                {
                    //then we can have structure changing rules
                    div = rhsNav.SelectChildren("instance", String.Empty);
                    if (div.Count > 0)
                    {
                        DivisionRule r = new DivisionRule();
                        while (div.MoveNext())
                        {
                            string            mtype = div.Current.GetAttribute("mtype", String.Empty);
                            InstanceBlueprint ib    = null;
                            if (String.IsNullOrEmpty(mtype))
                            {
                                ib = new InstanceBlueprint(currentType);
                            }
                            else
                            {
                                ib = new InstanceBlueprint(kp[mtype]);
                            }
                            readMultiset(div.Current, ib.Multiset);
                            r.Rhs.Add(ib);
                        }
                        rule = r;
                    }
                    else
                    {
                        XPathNavigator v;
                        v = rhsNav.SelectSingleNode("linkCreate");
                        if (v == null)
                        {
                            v = rhsNav.SelectSingleNode("linkDestroy");
                            if (v == null)
                            {
                                v = rhsNav.SelectSingleNode("dissolve");
                                if (v != null)
                                {
                                    rule = new DissolutionRule();
                                }
                            }
                            else
                            {
                                rule = LinkRule.LinkDestroy(readInstanceIdentifier(v));
                            }
                        }
                        else
                        {
                            rule = LinkRule.LinkCreate(readInstanceIdentifier(v));
                        }
                    }
                }

                if (rule == null)
                {
                    div = rhsNav.SelectChildren("target", String.Empty);
                    if (div.Count > 0)
                    {
                        RewriteCommunicationRule rcr = new RewriteCommunicationRule();
                        rcr.Rhs.Add(m);
                        while (div.MoveNext())
                        {
                            TargetedMultiset tm  = readTargetedMultiset(div.Current);
                            TargetedMultiset otm = null;
                            rcr.TargetRhs.TryGetValue(tm.Target, out otm);
                            if (otm == null)
                            {
                                rcr.TargetRhs.Add(tm.Target, tm);
                            }
                            else
                            {
                                otm.Multiset.Add(tm.Multiset);
                            }
                        }
                        rule = rcr;
                    }
                    else if (m != null)
                    {
                        rule = new RewritingRule();
                        (rule as RewritingRule).Rhs.Add(m);
                    }
                }
            }

            if (rule == null)
            {
                rule = new ConsumerRule();
            }
            readPItem(nav, rule);
            rule.Guard = readGuard(nav.SelectSingleNode("guard"));
            readMultiset(nav.SelectSingleNode("lhs"), rule.Lhs);

            return(rule);
        }