]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/parso/python/prefix.py
2 from codecs
import BOM_UTF8
3 from typing
import Tuple
5 from parso
.python
.tokenize
import group
7 unicode_bom
= BOM_UTF8
.decode('utf-8')
11 def __init__(self
, leaf
, typ
, value
, spacing
='', start_pos
=None):
12 assert start_pos
is not None
16 self
.spacing
= spacing
17 self
.start_pos
: Tuple
[int, int] = start_pos
20 def end_pos(self
) -> Tuple
[int, int]:
21 if self
.value
.endswith('\n') or self
.value
.endswith('\r'):
22 return self
.start_pos
[0] + 1, 0
23 if self
.value
== unicode_bom
:
24 # The bom doesn't have a length at the start of a Python file.
26 return self
.start_pos
[0], self
.start_pos
[1] + len(self
.value
)
28 def create_spacing_part(self
):
29 column
= self
.start_pos
[1] - len(self
.spacing
)
31 self
.parent
, 'spacing', self
.spacing
,
32 start_pos
=(self
.start_pos
[0], column
)
36 return '%s(%s, %s, %s)' % (
37 self
.__class
__.__name
__,
43 def search_ancestor(self
, *node_types
):
45 while node
is not None:
46 if node
.type in node_types
:
52 _comment
= r
'#[^\n\r\f]*'
53 _backslash
= r
'\\\r?\n|\\\r'
54 _newline
= r
'\r?\n|\r'
61 _comment
, _backslash
, _newline
, _form_feed
, _only_spacing
, _bom
,
64 _regex
= re
.compile(group(_spacing
, capture
=True) + _regex
)
77 def split_prefix(leaf
, start_pos
):
78 line
, column
= start_pos
82 while start
!= len(leaf
.prefix
):
83 match
= _regex
.match(leaf
.prefix
, start
)
84 spacing
= match
.group(1)
85 value
= match
.group(2)
88 type_
= _types
[value
[0]]
90 leaf
, type_
, value
, spacing
,
91 start_pos
=(line
, column
+ start
- int(bom
) + len(spacing
))
97 if value
.endswith('\n') or value
.endswith('\r'):
104 leaf
, 'spacing', spacing
,
105 start_pos
=(line
, column
+ start
)