U
uf;) @ s8 d dl mZ G dd deZG dd deZdZdZdS ) )Templatec @ s( e Zd Zd ddZd
ddZdd ZdS )ASTCodeGenerator
_c_ast.cfgc C s || _ dd | |D | _dS )zN Initialize the code generator from a configuration
file.
c S s g | ]\}}t ||qS )NodeCfg).0namecontentsr r C/opt/alt/python38/lib/python3.8/site-packages/pycparser/_ast_gen.py
s z-ASTCodeGenerator.__init__..N)cfg_filename
parse_cfgfilenode_cfg)selfr r r r
__init__ s zASTCodeGenerator.__init__Nc C sD t tj| jd}|t7 }| jD ]}|| d 7 }q || dS )z< Generates the code into file, an open file buffer.
)r z
N)r _PROLOGUE_COMMENT
substituter _PROLOGUE_CODEr generate_sourcewrite)r filesrcr r r r
generate s
zASTCodeGenerator.generatec
c s t |d}|D ]}| }|r|dr,q|d}|d}|d}|dk sb||ksb||krrtd||f |d| }||d | }|rd d
|dD ng } || fV qW 5 Q 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 | ]}| qS r )strip)r vr r r
r 6 s z2ASTCodeGenerator.parse_cfgfile..,)openr
startswithfindRuntimeErrorsplit)
r filenameflineZcolon_iZ
lbracket_iZ
rbracket_ir valZvallistr r r
r
% s
zASTCodeGenerator.parse_cfgfile)r )N)__name__
__module____qualname__r r r
r r r r
r s
r c @ s@ e Zd ZdZdd Zdd Zdd Zdd Zd
d Zdd
Z dS )r z Node configuration.
name: node name
contents: a list of contents - attributes and child nodes
See comment at the top of the configuration file for details.
c C s~ || _ g | _g | _g | _g | _|D ]V}|d}| j| |drT| j| q"|drl| j| q"| j| q"d S )N*z**)r all_entriesattrchild seq_childrstripappendendswith)r r r entryZclean_entryr r r
r B s
zNodeCfg.__init__c C s<