title: How to turn arithmetic Scala parer combinator result into AST
body: <p>I am trying to parse some arithmetic in Scala using Scala Parser combinator library. Although the following code parses fine, I am struggling to turning it into a useful AST.</p>
  <p><strong>Code for the parser:</strong></p>
  <pre class="lang-scala prettyprint-override"><code>  def expression: Parser[Any] = {
  
      def expr: Parser[Any] = term ~ rep(MINUS ~ term | PLUS ~ term)
  
      def factor: Parser[Any] = integer | LEFT_PAREN ~ expr ~ RIGHT_PAREN
  
      def term: Parser[Any] =
        factor ~ rep(MULTIPLICATION ~ factor | DIVISION ~ factor)
  
      expr
    }
  </code></pre>
  <p><strong>Expected AST</strong></p>
  <p>I would imagine the result would be something like this.</p>
  <p><strong>Input</strong></p>
  <pre><code>1 + 2 + (2 * 3)
  </code></pre>
  <p><strong>AST</strong></p>
  <pre><code>Expression(
    scala.List(
      Integer(1),
      Operator(&quot;+&quot;),
      Integer(2),
      Operator(&quot;+&quot;),
      Group(
        Integer(2)
        Operator(&quot;*&quot;),
        Integer(3),
      )
    )
  )
  </code></pre>
  <p>Currently this the output is like so:</p>
  <pre><code>Integer(
    1
  ) ~ List(
    
  ) ~ List(
    &quot;+&quot; ~ Integer(
      2
    ) ~ List(
      
    ),
    &quot;+&quot; ~ &quot;(&quot; ~ Integer(
      2
    ) ~ List(
      &quot;*&quot; ~ Integer(
        3
      )
    ) ~ List(
      
    ) ~ &quot;)&quot; ~ List(
      
    )
  )
  </code></pre>