It would be very useful to implement the search and processing of fragments of transformable code using parsers
For example, using lark-parser, we could make a transformation like this:
# specifying a fragment grammar with lark syntax (EBNF-like)
# such a grammar could be intended for a fragment like:
# 5 $ 10
grammar = """
new_operation: NUMBER '$' NUMBER
%import common.SIGNED_NUMBER -> NUMBER
"""
@detect(grammar)
def transform(parsed_tree, detected_source, full_source, **kwargs):
# parsed_tree will be like:
#
# new_operation:
# .... 5
# .... 10
return do_smth_with_tree(parsed_tree)
It would be very useful to implement the search and processing of fragments of transformable code using parsers
For example, using lark-parser, we could make a transformation like this: