a
    dh                     @   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ejee eedddZdS )zY
    Module of utilities for transforming a lark.Tree into a custom Abstract Syntax Tree
    N)OptionalCallable)Transformerv_argsc                   @   s   e Zd ZdZdS )AstzOAbstract class

    Subclasses will be collected by `create_transformer()`
    N__name__
__module____qualname____doc__ r   r   W/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lark/ast_utils.pyr      s   r   c                   @   s   e Zd ZdZdS )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                   @   s   e Zd ZdZdS )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      s   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st|rt|tr|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   Zlarkr   r   r   r   r   r   
ModuleTyper&   r   r   r   r   <module>   s   