B ( @ s| d Z ddlmZ ddlmZmZ ddlmZmZ eZ eZ ejZeZ dZdZdZG dd d eZdddZd d Zdd Zd S )z0Utility functions used by the btm_matcher module )pytree)grammartoken)pattern_symbolspython_symbolsc @ s: e Zd ZdZd ddZdd Zdd Zd d Zdd ZdS )MinNodezThis class serves as an intermediate representation of the pattern tree during the conversion to sets of leaf-to-root subpatternsNc C s. || _ || _g | _d| _d | _g | _g | _d S )NF)typenamechildrenleafparentalternativesgroup)selfr r r 6/opt/alt/python37/lib64/python3.7/lib2to3/btm_utils.py__init__ s zMinNode.__init__c C s t | jd t | j S )N )strr r )r r r r __repr__ s zMinNode.__repr__c C s | }g }x|r|j tkr`|j| t|jt|jkrTt|jg}g |_|j}q n|j}d}P |j tkr|j | t|j t|jkrt |j }g |_ |j}q n|j}d}P |j tjkr|j r||j n||j |j}q W |S )zInternal method. Returns a characteristic path of the pattern tree. This method must be run for all leaves until the linear subpatterns are merged into a singleN)r TYPE_ALTERNATIVESr appendlenr tupler TYPE_GROUPr get_characteristic_subpatterntoken_labelsNAMEr )r nodesubpr r r leaf_to_root! s8 zMinNode.leaf_to_rootc C s&