Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/prompt_toolkit/contrib/regular_languages/__pycache__/compiler.cpython-39.pyc
Ðазад
a d�h�U � @ s d Z ddlmZ ddlZddlmZmZmZmZm Z m Z mZ ddlmZ ddlmZmZmZmZmZmZmZmZmZ g d�Zd Zeeeegef f ZG d d� d�ZG dd � d �Ze d�ZG dd� d�ZG dd� d�Zdddddd�dd�Z dddddd�dd�Z!dS )a� Compiler for a regular grammar. Example usage:: # Create and compile grammar. p = compile('add \s+ (?P<var1>[^\s]+) \s+ (?P<var2>[^\s]+)') # Match input string. m = p.match('add 23 432') # Get variables. m.variables().get('var1') # Returns "23" m.variables().get('var2') # Returns "432" Partial matches are possible:: # Create and compile grammar. p = compile(''' # Operators with two arguments. ((?P<operator1>[^\s]+) \s+ (?P<var1>[^\s]+) \s+ (?P<var2>[^\s]+)) | # Operators with only one arguments. ((?P<operator2>[^\s]+) \s+ (?P<var1>[^\s]+)) ''') # Match partial input string. m = p.match_prefix('add 23') # Get variables. (Notice that both operator1 and operator2 contain the # value "add".) This is because our input is incomplete, and we don't know # yet in which rule of the regex we we'll end up. It could also be that # `operator1` and `operator2` have a different autocompleter and we want to # call all possible autocompleters that would result in valid input.) m.variables().get('var1') # Returns "23" m.variables().get('operator1') # Returns "add" m.variables().get('operator2') # Returns "add" � )�annotationsN)�Callable�Dict�Iterable�Iterator�Pattern�TypeVar�overload)�Match� ) �AnyNode� Lookahead�Node�NodeSequence�Regex�Repeat�Variable�parse_regex�tokenize_regex)�compiler � VariablesZinvalid_trailingc @ s� e Zd ZdZdddddd�dd�Zd d d d �dd�Zd d d d �d d�Zeddd d�dd��Zedddd�dd��Z d dd�dd�Z d dd�dd�ZdS )�_CompiledGrammaraI Compiles a grammar. This will take the parse tree of a regular expression and compile the grammar. :param root_node: :class~`.regex_parser.Node` instance. :param escape_funcs: `dict` mapping variable names to escape callables. :param unescape_funcs: `dict` mapping variable names to unescape callables. Nr �EscapeFuncDict | None�None�� root_node�escape_funcs�unescape_funcs�returnc s� |�_ |pi �_|pi �_i �_dg� ddd�� �fdd�}d��||�� d��_t��||���_t j �t ��j���_�fd d ��jD ��_ �fdd ��jD ��_d S )Nr r �str��noder c s. d� d � �}| j �j|<