Skip to content

Commit

Permalink
add warning about actions mutating things (python#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbolz authored Nov 19, 2021
1 parent 9d880b6 commit ed2af43
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions parser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ If the action is omitted, a default action is generated:
This default behaviour is primarily made for very simple situations and for
debugging purposes.

.. warning::

It's important that the actions don't mutate any AST nodes that are passed
into them via variables referring to other rules. The reason for mutation
being not allowed is that the AST nodes are cached by memoization and could
potentially be reused in a different context, where the mutation would be
invalid. If an action needs to change an AST node, it should instead make a
new copy of the node and change that.

The full meta-grammar for the grammars supported by the PEG generator is:

::
Expand Down

0 comments on commit ed2af43

Please sign in to comment.