B
    b6                 @   s   d Z ddlZddlZddlmZ ddlZddlZddl	Zddl
mZ ddlmZ ddlmZ ddlmZmZ ee e Zejdd	Zejd
krdddgZnddgZedddZdee dddZddddZee dddZdS )a%  Tool-specific initialization for lex.

This tool should support multiple lex implementations,
but is in actuality biased towards GNU Flex.

There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.
    N)Optional)MINGW_DEFAULT_PATHS)CYGWIN_DEFAULT_PATHS)CHOCO_DEFAULT_PATH)CLVar	to_Stringz$LEXCOMz
$LEXCOMSTRwin32ZflexZlexZwin_flex)returnc             C   s   t jt|d \}}|dkr*|d g} ddg}|jd| |d}xP|d D ]D}x>|D ]6}t|}	|d|	 |krV||	d  }
| |
 qVW qLW |jd	| |d}|r| | |j	|
|d
 |jd| |d}|r| | |j	|
|d | |fS )z9Adds extra files generated by lex program to target list.r   z.lmz.mz--header-file=z--tables-file=z	$LEXFLAGS)targetsourceNz$LEX_HEADER_FILE)LEX_HEADER_FILEz$LEX_TABLES_FILE)LEX_TABLES_FILE)ospathsplitextr   Z
subst_listlenstripappendZsubstZReplaceZFile)r
   r   envZ
sourceBaseZ	sourceExtZfile_gen_optionsZlexflagsZoptionZfileGenOptionl	file_nameZlexheaderfileZlextablesfile r   -lib/python3.7/site-packages/SCons/Tool/lex.py
lexEmitter8   s(    



r   Fc             C   s@   x(t D ] }tjj| |t|d}|r|S qW tjtjjd dS )aD  
    Returns the path to the lex tool, searching several possible names.

    Only called in the Windows case, so the `default_path` argument to
    :func:`find_program_path` can be Windows-specific.

    Args:
        env: current construction environment
        append_paths: if set, add the path to the tool to PATH
    )Zdefault_pathsZadd_pathz@lex tool requested, but lex or flex binary not found in ENV PATHN)BINSSConsToolZfind_program_pathDEFAULT_PATHSZWarningswarnZSConsWarning)r   append_pathsprogZbin_pathr   r   r   get_lex_pathb   s    
r!   c             C   s   t j| \}}|dt |dt |dt |dt |dt |dt |dt |dt tjdkrt	| dd}| j
| ttdddd	 tjdkr| j
tdd
 d| d< nd| d< d| d< d| d< dS )zBAdd Builders and construction variables for lex to an Environment.z.lz.lexz.lmz.llr   T)r    )ZLEXZLEXFLAGSr   r   )Z	LEXUNISTDzI$LEX $LEXUNISTD $LEXFLAGS $_LEX_HEADER $_LEX_TABLES -t $SOURCES > $TARGETZLEXCOMz>$LEX $LEXFLAGS $_LEX_HEADER $_LEX_TABLES -t $SOURCES > $TARGETz>${LEX_HEADER_FILE and "--header-file=" + str(LEX_HEADER_FILE)}Z_LEX_HEADERz>${LEX_TABLES_FILE and "--tables-file=" + str(LEX_TABLES_FILE)}Z_LEX_TABLESN)r   r   ZcreateCFileBuildersZ
add_action	LexActionZadd_emitterr   sysplatformr!   Z
SetDefaultDetectr   r   )r   Zc_fileZcxx_file_r   r   r   generate}   s,    


r(   c             C   s    t jdkrt| S | tS d S )Nr   )r$   r%   r!   r&   r   )r   r   r   r   exists   s    
r)   )F)__doc__os.pathr   r$   typingr   ZSCons.Actionr   Z
SCons.ToolZSCons.WarningsZSCons.Platform.mingwr   ZSCons.Platform.cygwinr   ZSCons.Platform.win32r   Z
SCons.Utilr   r   r   ZActionr#   r%   r   tupler   strr!   r(   r)   r   r   r   r   <module>    s&   
*(