_C=False
_B=True
_A=None
from abc import abstractmethod,abstractproperty
from typing import List,Optional,Tuple,Union
from parso.utils import split_lines
def search_ancestor(node,*B):
	'\n    Recursively looks at the parents of a node and returns the first found node\n    that matches ``node_types``. Returns ``None`` if no matching node is found.\n\n    This function is deprecated, use :meth:`NodeOrLeaf.search_ancestor` instead.\n\n    :param node: The ancestors of this node will be checked.\n    :param node_types: type names that are searched for.\n    ';A=node.parent
	while A is not _A:
		if A.type in B:return A
		A=A.parent
class NodeOrLeaf:
	'\n    The base class for nodes and leaves.\n    ';__slots__='parent',;type:str;'\n    The type is a string that typically matches the types of the grammar file.\n    ';parent:'Optional[BaseNode]';'\n    The parent :class:`BaseNode` of this node or leaf.\n    None if this is the root node.\n    '
	def get_root_node(B):
		"\n        Returns the root node of a parser tree. The returned node doesn't have\n        a parent node like all the other nodes/leaves.\n        ";A=B
		while A.parent is not _A:A=A.parent
		return A
	def get_next_sibling(A):
		"\n        Returns the node immediately following this node in this parent's\n        children list. If this node does not have a next sibling, it is None\n        ";B=A.parent
		if B is _A:return
		for(C,D)in enumerate(B.children):
			if D is A:
				try:return A.parent.children[C+1]
				except IndexError:return
	def get_previous_sibling(A):
		"\n        Returns the node immediately preceding this node in this parent's\n        children list. If this node does not have a previous sibling, it is\n        None.\n        ";B=A.parent
		if B is _A:return
		for(C,D)in enumerate(B.children):
			if D is A:
				if C==0:return
				return A.parent.children[C-1]
	def get_previous_leaf(B):
		'\n        Returns the previous leaf in the parser tree.\n        Returns `None` if this is the first element in the parser tree.\n        '
		if B.parent is _A:return
		A=B
		while _B:
			C=A.parent.children;D=C.index(A)
			if D==0:
				A=A.parent
				if A.parent is _A:return
			else:A=C[D-1];break
		while _B:
			try:A=A.children[-1]
			except AttributeError:return A
	def get_next_leaf(C):
		'\n        Returns the next leaf in the parser tree.\n        Returns None if this is the last element in the parser tree.\n        '
		if C.parent is _A:return
		A=C
		while _B:
			B=A.parent.children;D=B.index(A)
			if D==len(B)-1:
				A=A.parent
				if A.parent is _A:return
			else:A=B[D+1];break
		while _B:
			try:A=A.children[0]
			except AttributeError:return A
	@abstractproperty
	def start_pos(self):'\n        Returns the starting position of the prefix as a tuple, e.g. `(3, 4)`.\n\n        :return tuple of int: (line, column)\n        '
	@abstractproperty
	def end_pos(self):'\n        Returns the end position of the prefix as a tuple, e.g. `(3, 4)`.\n\n        :return tuple of int: (line, column)\n        '
	@abstractmethod
	def get_start_pos_of_prefix(self):'\n        Returns the start_pos of the prefix. This means basically it returns\n        the end_pos of the last prefix. The `get_start_pos_of_prefix()` of the\n        prefix `+` in `2 + 1` would be `(1, 1)`, while the start_pos is\n        `(1, 2)`.\n\n        :return tuple of int: (line, column)\n        '
	@abstractmethod
	def get_first_leaf(self):'\n        Returns the first leaf of a node or itself if this is a leaf.\n        '
	@abstractmethod
	def get_last_leaf(self):'\n        Returns the last leaf of a node or itself if this is a leaf.\n        '
	@abstractmethod
	def get_code(self,include_prefix=_B):'\n        Returns the code that was the input for the parser for this node.\n\n        :param include_prefix: Removes the prefix (whitespace and comments) of\n            e.g. a statement.\n        '
	def search_ancestor(B,*C):
		'\n        Recursively looks at the parents of this node or leaf and returns the\n        first found node that matches ``node_types``. Returns ``None`` if no\n        matching node is found.\n\n        :param node_types: type names that are searched for.\n        ';A=B.parent
		while A is not _A:
			if A.type in C:return A
			A=A.parent
	def dump(B,*,indent=4):
		'\n        Returns a formatted dump of the parser tree rooted at this node or leaf. This is\n        mainly useful for debugging purposes.\n\n        The ``indent`` parameter is interpreted in a similar way as :py:func:`ast.dump`.\n        If ``indent`` is a non-negative integer or string, then the tree will be\n        pretty-printed with that indent level. An indent level of 0, negative, or ``""``\n        will only insert newlines. ``None`` selects the single line representation.\n        Using a positive integer indent indents that many spaces per level. If\n        ``indent`` is a string (such as ``"\\t"``), that string is used to indent each\n        level.\n\n        :param indent: Indentation style as described above. The default indentation is\n            4 spaces, which yields a pretty-printed dump.\n\n        >>> import parso\n        >>> print(parso.parse("lambda x, y: x + y").dump())\n        Module([\n            Lambda([\n                Keyword(\'lambda\', (1, 0)),\n                Param([\n                    Name(\'x\', (1, 7), prefix=\' \'),\n                    Operator(\',\', (1, 8)),\n                ]),\n                Param([\n                    Name(\'y\', (1, 10), prefix=\' \'),\n                ]),\n                Operator(\':\', (1, 11)),\n                PythonNode(\'arith_expr\', [\n                    Name(\'x\', (1, 13), prefix=\' \'),\n                    Operator(\'+\', (1, 15), prefix=\' \'),\n                    Name(\'y\', (1, 17), prefix=\' \'),\n                ]),\n            ]),\n            EndMarker(\'\', (1, 18)),\n        ])\n        ';A=indent
		if A is _A:C=_C;E=''
		elif isinstance(A,int):C=_B;E=' '*A
		elif isinstance(A,str):C=_B;E=A
		else:raise TypeError(f"expect 'indent' to be int, str or None, got {A!r}")
		def F(node,indent='',top_level=_B):
			D=indent;A=node;B='';G=type(A).__name__
			if isinstance(A,Leaf):
				B+=f"{D}{G}("
				if isinstance(A,ErrorLeaf):B+=f"{A.token_type!r}, "
				elif isinstance(A,TypedLeaf):B+=f"{A.type!r}, "
				B+=f"{A.value!r}, {A.start_pos!r}"
				if A.prefix:B+=f", prefix={A.prefix!r}"
				B+=')'
			elif isinstance(A,BaseNode):
				B+=f"{D}{G}("
				if isinstance(A,Node):B+=f"{A.type!r}, "
				B+='['
				if C:B+='\n'
				for H in A.children:B+=F(H,indent=D+E,top_level=_C)
				B+=f"{D}])"
			else:raise TypeError(f"unsupported node encountered: {A!r}")
			if not top_level:
				if C:B+=',\n'
				else:B+=', '
			return B
		return F(B)
class Leaf(NodeOrLeaf):
	'\n    Leafs are basically tokens with a better API. Leafs exactly know where they\n    were defined and what text preceeds them.\n    ';__slots__='value','line','column','prefix';prefix:str
	def __init__(A,value,start_pos,prefix=''):A.value=value;'\n        :py:func:`str` The value of the current token.\n        ';A.start_pos=start_pos;A.prefix=prefix;'\n        :py:func:`str` Typically a mixture of whitespace and comments. Stuff\n        that is syntactically irrelevant for the syntax tree.\n        ';A.parent=_A;'\n        The parent :class:`BaseNode` of this leaf.\n        '
	@property
	def start_pos(self):return self.line,self.column
	@start_pos.setter
	def start_pos(self,value):A=value;self.line=A[0];self.column=A[1]
	def get_start_pos_of_prefix(A):
		B=A.get_previous_leaf()
		if B is _A:C=split_lines(A.prefix);return A.line-len(C)+1,0
		return B.end_pos
	def get_first_leaf(A):return A
	def get_last_leaf(A):return A
	def get_code(A,include_prefix=_B):
		if include_prefix:return A.prefix+A.value
		else:return A.value
	@property
	def end_pos(self):
		A=self;B=split_lines(A.value);C=A.line+len(B)-1
		if A.line==C:D=A.column+len(B[-1])
		else:D=len(B[-1])
		return C,D
	def __repr__(A):
		B=A.value
		if not B:B=A.type
		return'<%s: %s>'%(type(A).__name__,B)
class TypedLeaf(Leaf):
	__slots__='type',
	def __init__(A,type,value,start_pos,prefix=''):super().__init__(value,start_pos,prefix);A.type=type
class BaseNode(NodeOrLeaf):
	'\n    The super class for all nodes.\n    A node has children, a type and possibly a parent node.\n    ';__slots__='children',
	def __init__(A,children):
		B=children;A.children=B;'\n        A list of :class:`NodeOrLeaf` child nodes.\n        ';A.parent=_A;'\n        The parent :class:`BaseNode` of this node.\n        None if this is the root node.\n        '
		for C in B:C.parent=A
	@property
	def start_pos(self):return self.children[0].start_pos
	def get_start_pos_of_prefix(A):return A.children[0].get_start_pos_of_prefix()
	@property
	def end_pos(self):return self.children[-1].end_pos
	def _get_code_for_children(C,children,include_prefix):
		A=children
		if include_prefix:return''.join(A.get_code()for A in A)
		else:B=A[0].get_code(include_prefix=_C);return B+''.join(A.get_code()for A in A[1:])
	def get_code(A,include_prefix=_B):return A._get_code_for_children(A.children,include_prefix)
	def get_leaf_for_position(B,position,include_prefixes=_C):
		'\n        Get the :py:class:`parso.tree.Leaf` at ``position``\n\n        :param tuple position: A position tuple, row, column. Rows start from 1\n        :param bool include_prefixes: If ``False``, ``None`` will be returned if ``position`` falls\n            on whitespace or comments before a leaf\n        :return: :py:class:`parso.tree.Leaf` at ``position``, or ``None``\n        ';H=include_prefixes;C=position
		def E(lower,upper):
			F=upper;D=lower
			if D==F:
				A=B.children[D]
				if not H and C<A.start_pos:return
				try:return A.get_leaf_for_position(C,H)
				except AttributeError:return A
			G=int((D+F)/2);A=B.children[G]
			if C<=A.end_pos:return E(D,G)
			else:return E(G+1,F)
		if not(1,0)<=C<=B.children[-1].end_pos:raise ValueError('Please provide a position that exists within this node.')
		return E(0,len(B.children)-1)
	def get_first_leaf(A):return A.children[0].get_first_leaf()
	def get_last_leaf(A):return A.children[-1].get_last_leaf()
	def __repr__(A):B=A.get_code().replace('\n',' ').replace('\r',' ').strip();return'<%s: %s@%s,%s>'%(type(A).__name__,B,A.start_pos[0],A.start_pos[1])
class Node(BaseNode):
	'Concrete implementation for interior nodes.';__slots__='type',
	def __init__(A,type,children):super().__init__(children);A.type=type
	def __repr__(A):return'%s(%s, %r)'%(A.__class__.__name__,A.type,A.children)
class ErrorNode(BaseNode):"\n    A node that contains valid nodes/leaves that we're follow by a token that\n    was invalid. This basically means that the leaf after this node is where\n    Python would mark a syntax error.\n    ";__slots__=();type='error_node'
class ErrorLeaf(Leaf):
	'\n    A leaf that is either completely invalid in a language (like `$` in Python)\n    or is invalid at that position. Like the star in `1 +* 1`.\n    ';__slots__='token_type',;type='error_leaf'
	def __init__(A,token_type,value,start_pos,prefix=''):super().__init__(value,start_pos,prefix);A.token_type=token_type
	def __repr__(A):return'<%s: %s:%s, %s>'%(type(A).__name__,A.token_type,repr(A.value),A.start_pos)