FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/extractor/lark/common.py at codeql-cli/v2.25.1 · 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
460
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
/
common.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
87 lines (65 loc) · 2.17 KB
Breadcrumbs
codeql
/
python
/
extractor
/
lark
/
common.py
Copy path
File metadata and controls
87 lines (65 loc) · 2.17 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import
re
import
sys
from
.
utils
import
get_regexp_width
Py36
=
(
sys
.
version_info
[:
2
]
>=
(
3
,
6
))
###{standalone
###}
class
LexerConf
:
def
__init__
(
self
,
tokens
,
ignore
=
(),
postlex
=
None
,
callbacks
=
None
):
self
.
tokens
=
tokens
self
.
ignore
=
ignore
self
.
postlex
=
postlex
self
.
callbacks
=
callbacks
or
{}
class
ParserConf
:
def
__init__
(
self
,
rules
,
callback
,
start
):
self
.
rules
=
rules
self
.
callback
=
callback
self
.
start
=
start
class
Pattern
(
object
):
def
__init__
(
self
,
value
,
flags
=
()):
self
.
value
=
value
self
.
flags
=
frozenset
(
flags
)
def
__repr__
(
self
):
return
repr
(
self
.
to_regexp
())
# Pattern Hashing assumes all subclasses have a different priority!
def
__hash__
(
self
):
return
hash
((
type
(
self
),
self
.
value
,
self
.
flags
))
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
value
==
other
.
value
and
self
.
flags
==
other
.
flags
def
to_regexp
(
self
):
raise
NotImplementedError
()
if
Py36
:
# Python 3.6 changed syntax for flags in regular expression
def
_get_flags
(
self
,
value
):
for
f
in
self
.
flags
:
value
=
(
'(?%s:%s)'
%
(
f
,
value
))
return
value
else
:
def
_get_flags
(
self
,
value
):
for
f
in
self
.
flags
:
value
=
(
'(?%s)'
%
f
)
+
value
return
value
class
PatternStr
(
Pattern
):
def
to_regexp
(
self
):
return
self
.
_get_flags
(
re
.
escape
(
self
.
value
))
@
property
def
min_width
(
self
):
return
len
(
self
.
value
)
max_width
=
min_width
class
PatternRE
(
Pattern
):
def
to_regexp
(
self
):
return
self
.
_get_flags
(
self
.
value
)
@
property
def
min_width
(
self
):
return
get_regexp_width
(
self
.
to_regexp
())[
0
]
@
property
def
max_width
(
self
):
return
get_regexp_width
(
self
.
to_regexp
())[
1
]
class
TokenDef
(
object
):
def
__init__
(
self
,
name
,
pattern
,
priority
=
1
):
assert
isinstance
(
pattern
,
Pattern
),
pattern
self
.
name
=
name
self
.
pattern
=
pattern
self
.
priority
=
priority
def
__repr__
(
self
):
return
'%s(%r, %r)'
%
(
type
(
self
).
__name__
,
self
.
name
,
self
.
pattern
)
Back
|
FazBrowse Home
|
New Git URL