
    gi                         d dl Z d dlZd dlZd dlmZ d dlmZ  ed          Z G d d          Ze
 e            Z	de
fdZdd
ZdS )    N)import_module)TransformToSymPyExprlarkc                   &    e Zd ZdZddZdefdZdS )	LarkLaTeXParseraF  Class for converting input `\mathrm{\LaTeX}` strings into SymPy Expressions.
    It holds all the necessary internal data for doing so, and exposes hooks for
    customizing its behavior.

    Parameters
    ==========

    print_debug_output : bool, optional

        If set to ``True``, prints debug output to the logger. Defaults to ``False``.

    transform : bool, optional

        If set to ``True``, the class runs the Transformer class on the parse tree
        generated by running ``Lark.parse`` on the input string. Defaults to ``True``.

        Setting it to ``False`` can help with debugging the `\mathrm{\LaTeX}` grammar.

    grammar_file : str, optional

        The path to the grammar file that the parser should use. If set to ``None``,
        it uses the default grammar, which is in ``grammar/latex.lark``, relative to
        the ``sympy/parsing/latex/lark/`` directory.

    transformer : str, optional

        The name of the Transformer class to use. If set to ``None``, it uses the
        default transformer class, which is :py:func:`TransformToSymPyExpr`.

    FTNc                 x   t           j                            t           j                            t                    d          }|\t          t           j                            |d          d          5 }|                                }d d d            n# 1 swxY w Y   n=t          |d          5 }|                                }d d d            n# 1 swxY w Y   t                              ||ddddd	d	d
	  	        | _	        || _
        || _        |t                      | _        d S  |            | _        d S )Nzgrammar/z
latex.larkzutf-8)encodingearleylatex_stringautoexplicitFT)source_pathparserstartlexer	ambiguitypropagate_positionsmaybe_placeholderskeep_all_tokens)ospathjoindirname__file__openread_larkLarkr   print_debug_outputtransform_exprr   transformer)selfr   	transformgrammar_filer!   grammar_dir_pathflatex_grammars           a/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/parsing/latex/lark/latex_parser.py__init__zLarkLaTeXParser.__init__*   s   7<<(A(A:NNbgll#3\BBWUUU )YZ !) ) ) ) ) ) ) ) ) ) ) ) ) ) ) lW555 ) !) ) ) ) ) ) ) ) ) ) ) ) ) ) ) jj(   %$  ! 	" 	" #5'355D*{}}Ds$   4BBB2CCCsc                    | j         r)t          j                            t          j                   | j                            |          }| j        srt          j        	                    d|           t          j        	                    |           t          j        	                    |
                                           |S | j         rQt          j        	                    d|           t          j        	                    |
                                           | j                            |          }| j         r t          j        	                    d|           |S )Nzexpression = %szSymPy expression = %s)r   r   loggersetLevelloggingDEBUGr   parser    debugprettyr!   r#   )r"   r*   
parse_treesympy_expressions       r(   doparsezLarkLaTeXParser.doparseG   s%   " 	1L!!'-000[&&q))
" 	L0!444Lz***Lz0022333" 	4L0!444Lz0022333+55jAA" 	JL68HIII    )FTNN)__name__
__module____qualname____doc__r)   strr5    r6   r(   r   r      sM         <- - - -:             r6   r   r*   c                 b    t           t          d          t                              |           S )z
    Experimental LaTeX parser using Lark.

    This function is still under development and its API may change with the
    next releases of SymPy.
    NzLark is probably not installed)r   ImportError_lark_latex_parserr5   )r*   s    r(   parse_latex_larkr@   f   s,     }:;;;%%a(((r6   Tc                    t          | t          j                  r| j        S t	          | j                  }|                    d          }|rt          j        dd|          }|dk    }|r|dz   n|d}| p}|r|t	          |          dz   z  }|r.|dd	                    fd	| j
        D                       z   z  }n*|d
	                    fd| j
        D                       z  }|r|dz  }|S )N
expressionz^expressionE_ambig    (
c                 >    g | ]}d z  t          |          z   S ) _pretty_print_lark_trees.0i
new_indent	show_exprs     r(   
<listcomp>z,_pretty_print_lark_trees.<locals>.<listcomp>   sF      $B  $B  $BnoC*$47OPQS]_h7i7i$i  $B  $B  $Br6   ,c                 2    g | ]}t          |          S r<   rK   rM   s     r(   rR   z,_pretty_print_lark_trees.<locals>.<listcomp>   s'    fffST4Q
INNfffr6   ))
isinstancer   Tokenvaluer;   data
startswithresubr   children)	treeindentrQ   rY   is_expris_ambigoutput	show_noderP   s	     `     @r(   rL   rL   r   sZ   $$$ zty>>Dool++G 1vnc400 H aZ


F(yI "#d))c/! h$  $B  $B  $B  $B  $Bsw  tA  $B  $B  $B  C  C  C  	C#((fffffX\Xefffggg #Mr6   )r   T)r   r.   r[   sympy.externalr   $sympy.parsing.latex.lark.transformerr   r   r   r?   r;   r@   rL   r<   r6   r(   <module>rf      s    				  				 ( ( ( ( ( ( E E E E E EfT  T  T  T  T  T  T  T n 	(**	) 	) 	) 	) 	)           r6   