You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suggest to add an option for user to exclude classes from being handled by transformer produced by ast_utils.create_transformer not only by underscoring class name, but with custom predicate.
Here in lark/ast_utils.py we have hardcoded condition for exclusion.
Why
It seems to me that its quite unpleasant to do such things as we may wish to use such underscored classes as normal in our program, so why we has to make their name ugly in some way.
after calling to create_transformer. Other way is converting this like LarkAST to MyOwnAST after parsing looks like overengineering. But it seems to me that the solution of this problem is nearly trivial.
Proposal
My proposal is
Add another parameter predicate excluded to create_transformer. Then the signature would be
I left not name.startswith('_') to ensure that the statement "Classes starting with an underscore (_) will be skipped." remains true in general. But maybe it can be removed, so it needs to be discussed.
Suggestion
I suggest to add an option for user to exclude classes from being handled by transformer produced by ast_utils.create_transformer not only by underscoring class name, but with custom predicate.
Here in
lark/ast_utils.py
we have hardcoded condition for exclusion.Why
It seems to me that its quite unpleasant to do such things as we may wish to use such underscored classes as normal in our program, so why we has to make their name ugly in some way.
I faced with this fact during the development of such AST hierarchy:
https://github.com/vityaman-edu/sleepy/pull/8/files#diff-62348556570d26da9f0e70903e81ee752f97a3ea6cf48bbfe9c138f080a8d329R15
There I don't really want to have names like
_Expression
, so my only option is to do something likeafter calling to
create_transformer
. Other way is converting this likeLarkAST
toMyOwnAST
after parsing looks like overengineering. But it seems to me that the solution of this problem is nearly trivial.Proposal
My proposal is
excluded
tocreate_transformer
. Then the signature would beThen add it to that condition.
I left
not name.startswith('_')
to ensure that the statement "Classes starting with an underscore (_
) will be skipped." remains true in general. But maybe it can be removed, so it needs to be discussed.Alternatives
@ignored
annotaion.Ignored
tag interface like AsList or WithMeta.User effect
Actions
ast_utils.py:create_transformer
, update docstring.I can make an MR and solve this issue myself if you let me.
Discuss
The text was updated successfully, but these errors were encountered: