//public override object VisitBracket_atom(smilesParser.Bracket_atomContext context)
        //{
        //    string symbol = string.Empty;
        //    Chirality ch = Chirality.UNSPECIFIED;
        //    int isotope = 0;
        //    int hCount = 0;
        //    int charge = 0;
        //    int atomClass = 0;
        //    foreach (IParseTree tree in context.children)
        //    {
        //        if (typeof(smilesParser.SymbolContext).IsAssignableFrom(tree.GetType()))
        //        {
        //            symbol = (string)VisitSymbol((smilesParser.SymbolContext)tree);
        //        }
        //        if (typeof(smilesParser.ChiralContext).IsAssignableFrom(tree.GetType()))
        //        {
        //            ch = (Chirality)VisitChiral((smilesParser.ChiralContext)tree);
        //        }
        //        if (typeof(smilesParser.IsotopeContext).IsAssignableFrom(tree.GetType()))
        //        {
        //            isotope = (int)VisitIsotope((smilesParser.IsotopeContext)tree);
        //        }
        //        if (typeof(smilesParser.HcountContext).IsAssignableFrom(tree.GetType()))
        //        {
        //            hCount = (int)VisitHcount((smilesParser.HcountContext)tree);
        //        }
        //        if (typeof(smilesParser.ChargeContext).IsAssignableFrom(tree.GetType()))
        //        {
        //            charge = (int)VisitCharge((smilesParser.ChargeContext)tree);
        //        }
        //        if (typeof(smilesParser.AtomclassContext).IsAssignableFrom(tree.GetType()))
        //        {
        //            atomClass = (int)VisitAtomclass((smilesParser.AtomclassContext)tree);
        //        }
        //    }
        //    return new Atom(symbol, AtomType.NONE, isotope, ch, hCount, charge, atomClass);
        //}

        public override object VisitBranch([NotNull] smilesParser.BranchContext context)
        {
            if (context.ChildCount == 3)
            {
                if (typeof(smilesParser.ChainContext).IsAssignableFrom(context.GetChild(1).GetType()))
                {
                    return(VisitChain((smilesParser.ChainContext)context.GetChild(1)));
                }
                return(VisitBranch((smilesParser.BranchContext)context.GetChild(1)));
            }
            if (typeof(smilesParser.BondContext).IsAssignableFrom(context.GetChild(1).GetType()))
            {
                if (context.GetChild(1).GetText() == "\\")
                {
                    if (string.IsNullOrEmpty(cisTrans))
                    {
                        cisTrans = "/";
                    }
                    else
                    {
                        if (context.GetText() == cisTrans)
                        {
                            if (((doubleBonds.Count - 1) % 2) == 0)
                            {
                                foreach (Bond b in doubleBonds)
                                {
                                    b.Stereo = BondStereo.cis;
                                }
                            }
                        }
                        else
                        {
                            if (((doubleBonds.Count - 1) % 2) == 0)
                            {
                                foreach (Bond b in doubleBonds)
                                {
                                    b.Stereo = BondStereo.trans;
                                }
                            }
                        }
                        cisTrans = string.Empty;
                        doubleBonds.Clear();
                    }
                }
                else if (context.GetChild(1).GetText() == "/")
                {
                    if (string.IsNullOrEmpty(cisTrans))
                    {
                        cisTrans = "\\";
                    }
                    else
                    {
                        if (context.GetText() == cisTrans)
                        {
                            if (((doubleBonds.Count - 1) % 2) == 0)
                            {
                                foreach (Bond b in doubleBonds)
                                {
                                    b.Stereo = BondStereo.cis;
                                }
                            }
                        }
                        else
                        {
                            if (((doubleBonds.Count - 1) % 2) == 0)
                            {
                                foreach (Bond b in doubleBonds)
                                {
                                    b.Stereo = BondStereo.trans;
                                }
                            }
                        }
                        cisTrans = string.Empty;
                        doubleBonds.Clear();
                    }
                }
                else
                {
                    nextBond = (BondType)VisitBond((smilesParser.BondContext)context.GetChild(1));
                }
                return(VisitChain((smilesParser.ChainContext)context.GetChild(2)));
            }
            nextBond = (BondType)VisitDot((smilesParser.DotContext)context.GetChild(1));
            return(VisitChain((smilesParser.ChainContext)context.GetChild(2)));
        }
示例#2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="smilesParser.branch"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitBranch([NotNull] smilesParser.BranchContext context)
 {
     return(VisitChildren(context));
 }
示例#3
0
 /// <summary>
 /// Enter a parse tree produced by <see cref="smilesParser.branch"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void EnterBranch([NotNull] smilesParser.BranchContext context)
 {
 }