관리-도구
편집 파일: _ast_gen.cpython-36.pyc
3 g�wU�! � @ sh d dl Z d dlmZ G dd� de�ZG dd� de�ZdZdZed krdd dl Z ed �Z e jedd�� dS ) � N)�Templatec @ s( e Zd Zd dd�Zd dd�Zdd� ZdS )�ASTCodeGenerator� _c_ast.cfgc C s || _ dd� | j|�D �| _dS )zN Initialize the code generator from a configuration file. c S s g | ]\}}t ||��qS � )�NodeCfg)�.0�name�contentsr r �/usr/lib/python3.6/_ast_gen.py� <listcomp> s z-ASTCodeGenerator.__init__.<locals>.<listcomp>N)�cfg_filename� parse_cfgfile�node_cfg)�selfr r r r �__init__ s zASTCodeGenerator.__init__Nc C sH t t�j| jd�}|t7 }x| jD ]}||j� d 7 }q"W |j|� dS )z< Generates the code into file, an open file buffer. )r z N)r �_PROLOGUE_COMMENTZ substituter �_PROLOGUE_CODEr �generate_source�write)r �file�srcr r r r �generate s zASTCodeGenerator.generatec c s� t |d���}x�|D ]�}|j� }| s|jd�r0q|jd�}|jd�}|jd�}|dk sf||ksf||krvtd||f ��|d|� }||d |� }|r�d d � |jd�D �ng } || fV qW W dQ R X dS )ze Parse the configuration file and yield pairs of (name, contents) for each node. �r�#�:�[�]� zInvalid line in %s: %s Nc S s g | ]}|j � �qS r )�strip)r �vr r r r 7 s z2ASTCodeGenerator.parse_cfgfile.<locals>.<listcomp>�,)�openr � startswith�find�RuntimeError�split) r �filename�f�lineZcolon_iZ lbracket_iZ rbracket_ir �valZvallistr r r r &