As part of messing with the parser for PEP 671, I've come across what looks like a convention, but I'm not sure of the details. Most AST nodes start with a capital letter: Expr, Name, BoolOp, etc. Some don't: keyword, arg, withitem. Is it true that the ones that don't start with a capital are the more "internal" ones, like how a With statement has a collection of withitems, but you'd never see a withitem on its own? Specifically: I'm creating a new type of AST node for an argument default (either an early-evaluated default value, or a late-evaluated default expression); should that be Default or default? If my interpretation is correct, it should be "default". Thanks to everyone who worked on the PEG parser, by the way. It's a vast improvement over the old one. ChrisA
This is the convention according to my expertise:
PascalCase: subtype of a token type, cannot be used in a `rule_name[type]:` definition in grammar lower_snake_case: a token type PascalCase nodes are those used in the functions `_PyAST_*` (or one of the expression contexts), while lower_snake_case nodes are used in the `*_ty` ones. For example, the `arg` node: kwds[arg_ty]: '**' a=param_no_default { a } And the `FunctionDef` node: | 'def' n=NAME '(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block { _PyAST_FunctionDef(n->v.Name.id, (params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) }
Hey, as public mailing list mistakes go, that one's pretty mild. //arry/ On 10/28/21 6:35 PM, Jeremiah Vivian wrote:
Sorry for the two replies, I didn't think the first one would be sent. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/DNZMANF4... Code of Conduct: http://python.org/psf/codeofconduct/
participants (3)
-
Chris Angelico
-
Jeremiah Vivian
-
Larry Hastings