title: Parsec.Expr repeated Prefix with different priority
body: <p>The documentation for Parsec.Expr.buildExpressionParser says:</p>
  
  <blockquote>
    <p>Prefix and postfix operators of the same precedence can only occur once   (i.e. --2 is not allowed if - is prefix negate).</p>
  </blockquote>
  
  <p>However, I would like to parse such strings. </p>
  
  <p>Concretely, consider the following grammar:</p>
  
  <pre><code>sentence: 
      | identifier
      | "~" sentence
      | sentence &amp; sentence
      | "!" sentence
  </code></pre>
  
  <p>Where operator precedence is: <code>"~"</code> binds stronger than <code>"&amp;"</code> binds stronger than <code>"!"</code> </p>
  
  <p>For example, I would like the sentence </p>
  
  <pre><code>! ~a &amp; b
  </code></pre>
  
  <p>to be parsed as </p>
  
  <pre><code>! ( (~a) &amp; b )
  </code></pre>
  
  <p>And the sentence </p>
  
  <pre><code>~ ! a &amp; b 
  </code></pre>
  
  <p>as </p>
  
  <pre><code>~( ! ( a &amp; b) )
  </code></pre>
  
  <p>Parsec allows me to do this (and specify the operator precedence), however, I would like to be able to chain prefixes, e.g. <code>~ ~ ! ~ a</code>. 
  Parsec does not allow this. 
  I have found the solution <a href="https://stackoverflow.com/questions/10475337/parsec-expr-repeated-prefix-postfix-operator-not-supported">for chaining prefixes</a>, but this solution does not allow me to specify a different operator priority for the different prefix operators (either both "~" and "!" bind stronger than "&amp;", or none of them does)</p>
  
  <p>Does anyone have a solution for this? </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Partial solution that gets the operator bindings correct, but allows no chaining:
  <a href="http://lpaste.net/143362" rel="nofollow noreferrer">http://lpaste.net/143362</a></p>
  
  <p>Partial solution with chaining but that has a wrong binding for the "~" operator:
  <a href="http://lpaste.net/143364" rel="nofollow noreferrer">http://lpaste.net/143364</a></p>
  
  <p><strong>Edit:</strong> Some more clarifications related to the <a href="https://stackoverflow.com/questions/33214163/parsec-expr-repeated-prefix-with-different-priority/33244887#33244887">latest answer</a>. </p>
  
  <p>I actually want <code>&amp;</code> to be associative. Left or right does not matter. Left vs right associativity only matters between operators of the same precedence. 
  For your examples, it is all resolved by noting that <code>&amp;</code> binds stronger than <code>!</code> (<code>&amp;</code> has greater operator precedence) </p>
  
  <p>Hence, the expression you were worried about:</p>
  
  <p><code>a &amp; ! b &amp; c</code> should become:
  (first bind <code>&amp;</code> where possible)
  <code>a &amp; ! (b &amp; c)</code></p>
  
  <p>Similarly, <code>! a &amp; ! b &amp; c</code> should be parsed 
  (first bind &amp;)
  <code>! a &amp; ! (b &amp; c)</code>, thus <code>! a &amp; (! (b &amp; c))</code>, thus <code>! (a &amp; (! (b &amp; c)))</code></p>