diff options
author | Manu Phatak <bionikspoon@gmail.com> | 2016-01-04 19:04:22 -0600 |
---|---|---|
committer | Manu Phatak <bionikspoon@gmail.com> | 2016-01-04 19:04:22 -0600 |
commit | 5ab820632b54a330ceed4d0284e43221348a5b10 (patch) | |
tree | c6d1aff81dd05adcc02bb827fca3794dd605bce2 | |
parent | 5f6bd2a9377800522abc5a7c1027326e6d345594 (diff) | |
download | ply-5ab820632b54a330ceed4d0284e43221348a5b10.tar.gz |
Add an example to the docs.
-rw-r--r-- | doc/ply.html | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/doc/ply.html b/doc/ply.html index 808ed1d..dacde5c 100644 --- a/doc/ply.html +++ b/doc/ply.html @@ -3167,6 +3167,42 @@ in the same source file. </li> </p> +<p> +<li>Decorators of production rules have to update the wrapped function's line number. <tt>wrapper.co_firstlineno = func.__code__.co_firstlineno</tt>: + +<blockquote> +<pre> +from functools import wraps +from nodes import Collection + + +def strict(*types): + def decorate(func): + @wraps(func) + def wrapper(p): + func(p) + if not isinstance(p[0], types): + raise TypeError + + wrapper.co_firstlineno = func.__code__.co_firstlineno + return wrapper + + return decorate + +@strict(Collection) +def p_collection(p): + """ + collection : sequence + | map + """ + p[0] = p[1] +</pre> +</blockquote> + +</li> +</p> + + </ul> </p> |