B
    d                 @   s   d Z ddlmZmZmZmZmZm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 ddlmZ dd	lmZ dd
lmZ ddlmZmZ erddlmZ G dd de	jjZG dd de	jjjeZdee ef dddZ!dS )z$A Base class for additional parsers.    )TYPE_CHECKINGAnyDictListTypeUnionN)nodes)states)
StringList)	Transform)SmartQuotes)Config)BuildEnvironment)append_epilogprepend_prolog)Sphinxc               @   s2   e Zd ZU dZeed< eed< dddddZdS )	Parsera;  
    A base class of source parsers.  The additional parsers should inherit this class instead
    of ``docutils.parsers.Parser``.  Compared with ``docutils.parsers.Parser``, this class
    improves accessibility to Sphinx APIs.

    The subclasses can access sphinx core runtime objects (app, config and env).
    configenvr   N)appreturnc             C   s   || _ |j| _|j| _dS )zset_application will be called from Sphinx to set app and other instance variables

        :param sphinx.application.Sphinx app: Sphinx application object
        N)Z_appr   r   )selfr    r   [/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sphinx/parsers.pyset_application$   s    zParser.set_application)__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r   r   r      s   
r   c                   sZ   e Zd ZdZeee  d fddZee	e
f ejddddZe
dd	d
dZ  ZS )	RSTParserzA reST parser for Sphinx.)r   c                s   t   }|t |S )z
        Sphinx's reST parser replaces a transform class for smart-quotes by its own

        refs: sphinx.io.SphinxStandaloneReader
        )superget_transformsremover   )r   Z
transforms)	__class__r   r   r"   1   s    

zRSTParser.get_transformsN)inputstringdocumentr   c             C   s   |  || tj| j| j|jjd| _t|t	rTt
jj||jjdd}t||j}n|}| | | jj||| jd |   dS )z(Parse text and generate a document tree.)state_classesinitial_statedebugT)	tab_widthZconvert_whitespace)inlinerN)Zsetup_parser	   ZRSTStateMachiner'   r(   reporterZ
debug_flagZstatemachine
isinstancestrdocutilsZstring2linessettingsr*   r
   Zcurrent_sourcedecoraterunr+   Zfinish_parse)r   r%   r&   linesZ
inputlinesr   r   r   parse;   s    

zRSTParser.parse)contentr   c             C   s    t || jj t|| jj dS )z'Preprocess reST content before parsing.N)r   r   Z
rst_prologr   Z
rst_epilog)r   r5   r   r   r   r1   Q   s    zRSTParser.decorate)r   r   r   r   r   r   r   r"   r   r.   r
   r   r&   r4   r1   __classcell__r   r   )r$   r   r    .   s   
r    r   )r   r   c             C   s   |  t ddddS )NbuiltinT)versionZparallel_read_safeZparallel_write_safe)Zadd_source_parserr    )r   r   r   r   setupW   s    
r9   )"r   typingr   r   r   r   r   r   Zdocutils.parsersr/   Zdocutils.parsers.rstr   r	   Zdocutils.statemachiner
   Zdocutils.transformsr   Zdocutils.transforms.universalr   Zsphinx.configr   Zsphinx.environmentr   Zsphinx.util.rstr   r   Zsphinx.applicationr   parsersr   rstr    r.   r9   r   r   r   r   <module>   s     )