]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/yapf/pytree/continuation_splicer.py
1 # Copyright 2015 Google Inc. All Rights Reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Insert "continuation" nodes into lib2to3 tree.
16 The "backslash-newline" continuation marker is shoved into the node's prefix.
17 Pull them out and make it into nodes of their own.
19 SpliceContinuations(): the main function exported by this module.
22 from yapf_third_party
._ylib
2to
3 import pytree
24 from yapf
.yapflib
import format_token
27 def SpliceContinuations(tree
):
28 """Given a pytree, splice the continuation marker into nodes.
31 tree: (pytree.Node) The tree to work on. The tree is modified by this
36 """Inserts a continuation marker into the node."""
37 if isinstance(node
, pytree
.Leaf
):
38 if node
.prefix
.lstrip().startswith('\\\n'):
39 new_lineno
= node
.lineno
- node
.prefix
.count('\n')
41 type=format_token
.CONTINUATION
,
43 context
=('', (new_lineno
, 0)))
46 for index
, child
in enumerate(node
.children
[:]):
47 continuation_node
= RecSplicer(child
)
49 node
.children
.insert(index
+ num_inserted
, continuation_node
)