Skip to content

Using parsers for transforming #28

@grigandal625

Description

@grigandal625

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions