o
    V۷iE                  	   @   s   d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	 G dd dZ
G dd dZG d	d
 d
Zdd Zde	fdejdee dedefddZdS )zr
    Module of utilities for transforming a lark.Tree into a custom Abstract Syntax Tree (AST defined in classes)
    N)OptionalCallable)Transformerv_argsc                   @      e Zd ZdZdS )AstzOAbstract class

    Subclasses will be collected by `create_transformer()`
    N__name__
__module____qualname____doc__ r   r   D/home/ubuntu/vllm_env/lib/python3.10/site-packages/lark/ast_utils.pyr          r   c                   @   r   )AsListzzAbstract class

    Subclasses will be instantiated with the parse results as a single list, instead of as arguments.
    Nr   r   r   r   r   r      s    r   c                   @   r   )WithMetaz}Abstract class

    Subclasses will be instantiated with the Meta instance of the tree. (see ``v_args`` for more detail)
    Nr   r   r   r   r   r      r   r   c                 C   s   t dd|  S )Nz(?<!^)(?=[A-Z])_)resublower)namer   r   r   camel_to_snake   s   r   
ast_moduletransformerdecorator_factoryreturnc                 C   sx   |pt  }t| D ]/\}}|ds9t|r9t|tr9|t|t t|td}||	|}t
|t|| q
|S )a  Collects `Ast` subclasses from the given module, and creates a Lark transformer that builds the AST.

    For each class, we create a corresponding rule in the transformer, with a matching name.
    CamelCase names will be converted into snake_case. Example: "CodeBlock" -> "code_block".

    Classes starting with an underscore (`_`) will be skipped.

    Parameters:
        ast_module: A Python module containing all the subclasses of ``ast_utils.Ast``
        transformer (Optional[Transformer]): An initial transformer. Its attributes may be overwritten.
        decorator_factory (Callable): An optional callable accepting two booleans, inline, and meta,
            and returning a decorator for the methods of ``transformer``. (default: ``v_args``).
    r   )inlinemeta)r   inspect
getmembers
startswithisclass
issubclassr   r   r   __get__setattrr   )r   r   r   tr   objwrapperr   r   r   create_transformer"   s   

r(   )r   r   r   typestypingr   r   larkr   r   r   r   r   r   
ModuleTyper(   r   r   r   r   <module>   s$    
