FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/extractor/lark/indenter.py at codeql-cli/v2.26.3 · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
998
Pull requests
462
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
python
/
extractor
/
lark
/
indenter.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (42 loc) · 1.68 KB
Breadcrumbs
codeql
/
python
/
extractor
/
lark
/
indenter.py
Copy path
File metadata and controls
55 lines (42 loc) · 1.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"Provides Indentation services for languages with indentation similar to Python"
from
.
lexer
import
Token
###{standalone
class
Indenter
:
def
__init__
(
self
):
self
.
paren_level
=
0
self
.
indent_level
=
[
0
]
def
handle_NL
(
self
,
token
):
if
self
.
paren_level
>
0
:
return
yield
token
indent_str
=
token
.
rsplit
(
'
\n
'
,
1
)[
1
]
# Tabs and spaces
indent
=
indent_str
.
count
(
' '
)
+
indent_str
.
count
(
'
\t
'
)
*
self
.
tab_len
if
indent
>
self
.
indent_level
[
-
1
]:
self
.
indent_level
.
append
(
indent
)
yield
Token
.
new_borrow_pos
(
self
.
INDENT_type
,
indent_str
,
token
)
else
:
while
indent
<
self
.
indent_level
[
-
1
]:
self
.
indent_level
.
pop
()
yield
Token
.
new_borrow_pos
(
self
.
DEDENT_type
,
indent_str
,
token
)
assert
indent
==
self
.
indent_level
[
-
1
],
'%s != %s'
%
(
indent
,
self
.
indent_level
[
-
1
])
def
process
(
self
,
stream
):
for
token
in
stream
:
if
token
.
type
==
self
.
NL_type
:
for
t
in
self
.
handle_NL
(
token
):
yield
t
else
:
yield
token
if
token
.
type
in
self
.
OPEN_PAREN_types
:
self
.
paren_level
+=
1
elif
token
.
type
in
self
.
CLOSE_PAREN_types
:
self
.
paren_level
-=
1
assert
self
.
paren_level
>=
0
while
len
(
self
.
indent_level
)
>
1
:
self
.
indent_level
.
pop
()
yield
Token
(
self
.
DEDENT_type
,
''
)
assert
self
.
indent_level
==
[
0
],
self
.
indent_level
# XXX Hack for ContextualLexer. Maybe there's a more elegant solution?
@
property
def
always_accept
(
self
):
return
(
self
.
NL_type
,)
###}
Back
|
FazBrowse Home
|
New Git URL