Skip to content

Commit

Permalink
Merge pull request #40 from sn6uv/Issue39
Browse files Browse the repository at this point in the history
add a note on precedence to docs
  • Loading branch information
alex committed Dec 26, 2014
2 parents 2877ed6 + 0d18a27 commit 700daa7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/users-guide/parsers.rst
Expand Up @@ -192,3 +192,18 @@ We can pass `ParserState` objects to the parser simply like this:
This will call every production rule and the error handler with the
`ParserState` instance as first argument.


Precedence on rules
-------------------

Sometimes it is useful to give a rule a manual precedence. For this pass the
`precedence` argument to `production`. For example, if we wanted to add an
implicit multiplication rule to the above language (so that e.g. `16 32` is
parsed the same as `16 * 32`) we use the following:

.. code:: python
@pg.production('expression : expression expression', precedence='MUL')
def implicit_multiplication(p):
return Mul(p[0], p[1])

0 comments on commit 700daa7

Please sign in to comment.