Exemplo n.º 1
0
        private Equation Parse(string equation)
        {
            Logger.DebugLine($"Parsing: {equation}");

            //H2 + O2 -> H2O
            var sLeft  = equation.GetUntilOrEmpty("->").Trim();
            var sRight = equation.GetFromOrEmpty("->").Trim();

            var left  = ParseEquationSide(sLeft);
            var right = ParseEquationSide(sRight);

            //Logger.Debug("Parsed LeftSide: ");
            //Logger.Dump(left);
            //Logger.Debug("Parsed RightSide: ");
            //Logger.Dump(right);

            var eq = new Equation();

            eq.LeftSide  = left;
            eq.RightSide = right;

            /*eq.LeftSide = new EquationSide()
             * {
             *  Molecules = new List<Molecule>()
             *  {
             *      new Molecule()
             *      {
             *          Coefficient = 1,
             *          Elements = new List<Element>()
             *          {
             *              new Element()
             *              {
             *                  Name = "H",
             *                  Quantity = 2
             *              }
             *          }
             *      },
             *      new Molecule()
             *      {
             *          Coefficient = 1,
             *          Elements = new List<Element>()
             *          {
             *              new Element()
             *              {
             *                  Name = "O",
             *                  Quantity = 2
             *              }
             *          }
             *      }
             *  }
             * };
             *
             * eq.RightSide = new EquationSide()
             * {
             *  Molecules = new List<Molecule>()
             *  {
             *      new Molecule()
             *      {
             *          Coefficient = 1,
             *          Elements = new List<Element>()
             *          {
             *              new Element()
             *              {
             *                  Name = "H",
             *                  Quantity = 2
             *              },
             *              new Element()
             *              {
             *                  Name = "O",
             *                  Quantity = 1
             *              }
             *          }
             *      }
             *  }
             * };*/

            if (eq.ToString() != equation)
            {
                Logger.DebugLine("Errore nel parsing... stringhe non congruenti");
            }

            Logger.DebugLine("Parsing corretto");

            return(eq);
        }