[pypy-svn] r14816 - pypy/dist/pypy/interpreter/pyparser

ludal at codespeak.net ludal at codespeak.net
Wed Jul 20 14:49:42 CEST 2005


Author: ludal
Date: Wed Jul 20 14:49:41 2005
New Revision: 14816

Modified:
   pypy/dist/pypy/interpreter/pyparser/astbuilder.py
Log:
 comment on naming conventions


Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py	Wed Jul 20 14:49:41 2005
@@ -22,8 +22,29 @@
         return True
     return False
 
-## building functions
-
+## building functions helpers
+## --------------------------
+##
+## Naming convention:
+## to provide a function handler for a grammar rule name yyy
+## you should provide a build_yyy( builder, nb ) function
+## where builder is the AstBuilder instance used to build the
+## ast tree and nb is the number of items this rule is reducing
+##
+## Example:
+## for example if the rule
+##    term <- var ( '+' expr )*
+## matches
+##    x + (2*y) + z
+## build_term will be called with nb == 2
+## and get_atoms( builder, nb ) should return a list
+## of 5 objects : Var TokenObject('+') Expr('2*y') TokenObject('+') Expr('z')
+## where Var and Expr are AST subtrees and Token is a not yet
+## reduced token
+##
+## AST_RULES is kept as a dictionnary to be rpython compliant this is the
+## main reason why build_* functions are not methods of the AstBuilder class
+##
 def get_atoms( builder, nb ):
     L = []
     i = nb



More information about the Pypy-commit mailing list