title: Parsing SQL Statement With Irony
body: <p>I am trying to create a method that converts a regular sql statement to c# objects, So i decided to use Irony to parse the sql statement then i return the statement as an Action that contains the type of the statement and the values of it depending on the type</p>
  
  <p>Here is my non completed code [ Because i got frustrated as i don't know what to do then ]</p>
  
  <pre><code>private List&lt;Action&gt; ParseStatement(string statement)
  {
      var parser = new Parser(new SqlGrammar());
      var parsed = parser.Parse(statement);
      var status = parsed.Status;
  
      while (parsed.Status == ParseTreeStatus.Parsing)
      {
          Task.Yield();
      }
  
      if (status == ParseTreeStatus.Error)
          throw new ArgumentException("The statement cannot be parsed.");
  
      ParseTreeNode parsedStmt = parsed.Root.ChildNodes[0];
  
      switch (parsedStmt.Term.Name)
      {
          case "insertStmt":
              var table = parsedStmt.ChildNodes.Find(x =&gt; x.Term.Name == "Id").ChildNodes[0].Token.ValueString;
              var valuesCount =
                  parsedStmt.ChildNodes.Find(x =&gt; x.Term.Name == "insertData").ChildNodes.Find(
                      x =&gt; x.Term.Name == "exprList").ChildNodes.Count;
              var values = parsedStmt.ChildNodes.Find(x =&gt; x.Term.Name == "insertData").ChildNodes.Find(
                      x =&gt; x.Term.Name == "exprList").ChildNodes;
              foreach (var value in values)
              {
                  string type = value.Token.Terminal.Name;
              }
              break;
      }
  
      return null;
  }
  
  private Type ParseType(string type)
  {
      switch (type)
      {
          case "number":
              return typeof (int);
          case "string":
              return typeof (string);
      }
  
      return null;
  }
  </code></pre>
  
  <p>So the Question Here is : How could i make use of Irony to convert a string SQL Statement to a c# objects ?</p>
  
  <p>Here is an example of what i want to achieve :</p>
  
  <blockquote>
    <p>INSERT INTO Persons VALUES (4,'Nilsen', 'Johan', 'Bakken 2',
    'Stavanger')</p>
  </blockquote>
  
  <p>And get it converted to </p>
  
  <pre><code>return new Action&lt;string type, string table, int val1, string val2, string val3, string val4, string val5&gt;;
  </code></pre>
  
  <p>Dynamically depending on what the method have read from the statement.</p>
  
  <p>I hope i have well explained my idea so you can help me guys, And if there is something unclear please tell me and i will try to explain it.</p>