title: Parsing parameters and removing the last comma
body: <p>Sorry for the bad title, not sure how else to write it. Anyhow, I'm using ANTLR to produce a parse tree. I'm attempting to parse function parameters, and it's sort of working but there are a few things I'd like to change, which I'm not exactly sure how to.</p>
  
  <p>So here's my current setup:</p>
  
  <pre><code>function
      :   FUNCTION WORD LPAREN functionParams RPAREN ARROW WORD LBRACE RBRACE
      ;
  
  functionParams
      :   (AMP WORD COMMA)*
      ;
  
  // these could be wrong, I wrote these in by hand
  AMP: '&amp;';
  WORD: [a-zA-Z_]+;
  COMMA: ',';
  LPAREN: '(';
  RPAREN: ')';
  </code></pre>
  
  <p>Now this is great, it works. But when I input say</p>
  
  <pre><code>fn test(&amp;x, &amp;y, &amp;z) -&gt; int { }
  </code></pre>
  
  <p>It gives me an error, and an outcome I would prefer to change. The error being that it expects a comma after every parameter, so <code>&amp;z</code> would become <code>&amp;z,</code> which is not what I want.</p>
  
  <p>Secondly, the tree it produces (gui) is like this:</p>
  
  <p><img src="https://i.stack.imgur.com/IwAMt.png" alt="wow"></p>
  
  <p>However, I would like the function parameters to be parsed to the tree like so (remove the commas for easier interpretation, and give each parameter it's own node).</p>
  
  <pre><code>    PARAMS
     /      \
  &amp;x          &amp;y
  </code></pre>