Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
3adf8d1d
Kaydet (Commit)
3adf8d1d
authored
Nis 23, 2002
tarafından
Jack Jansen
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Converted to use re in stead of regex and regsub (finally:-).
üst
5ca53747
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
54 deletions
+65
-54
scantools.py
Tools/bgen/bgen/scantools.py
+65
-54
No files found.
Tools/bgen/bgen/scantools.py
Dosyayı görüntüle @
3adf8d1d
...
@@ -14,8 +14,7 @@ The defaults are (currently) tuned to scanning Apple Macintosh header files,
...
@@ -14,8 +14,7 @@ The defaults are (currently) tuned to scanning Apple Macintosh header files,
although most Mac specific details are contained in header-specific subclasses.
although most Mac specific details are contained in header-specific subclasses.
"""
"""
import
regex
import
re
import
regsub
import
string
import
string
import
sys
import
sys
import
os
import
os
...
@@ -33,7 +32,7 @@ Error = "scantools.Error"
...
@@ -33,7 +32,7 @@ Error = "scantools.Error"
class
Scanner
:
class
Scanner
:
# Set to 1 in subclass to debug your scanner patterns.
# Set to 1 in subclass to debug your scanner patterns.
debug
=
0
debug
=
0
def
__init__
(
self
,
input
=
None
,
output
=
None
,
defsoutput
=
None
):
def
__init__
(
self
,
input
=
None
,
output
=
None
,
defsoutput
=
None
):
self
.
initsilent
()
self
.
initsilent
()
...
@@ -240,27 +239,27 @@ if missing: raise "Missing Types"
...
@@ -240,27 +239,27 @@ if missing: raise "Missing Types"
self
.
includepath
=
[
':'
,
INCLUDEDIR
]
self
.
includepath
=
[
':'
,
INCLUDEDIR
]
def
initpatterns
(
self
):
def
initpatterns
(
self
):
self
.
head_pat
=
"^EXTERN_API[^_]"
self
.
head_pat
=
r
"^EXTERN_API[^_]"
self
.
tail_pat
=
"[;={}]"
self
.
tail_pat
=
r
"[;={}]"
self
.
type_pat
=
"EXTERN_API"
+
\
self
.
type_pat
=
r
"EXTERN_API"
+
\
"[
\t\n
]*
([
\t\n
]*"
+
\
r"[ \t\n]*\
([ \t\n]*"
+
\
"
\
(<type>[a-zA-Z0-9_*
\t
]*[a-zA-Z0-9_*]
\
)"
+
\
r"(?P<type>[a-zA-Z0-9_* \t]*[a-zA-Z0-9_*]
)"
+
\
"[
\t\n
]*
)[
\t\n
]*"
r"[ \t\n]*\
)[ \t\n]*"
self
.
name_pat
=
"
\
(<name>[a-zA-Z0-9_]+
\
)[
\t\n
]*"
self
.
name_pat
=
r"(?P<name>[a-zA-Z0-9_]+
)[ \t\n]*"
self
.
args_pat
=
"(
\
(<args>
\
([^(;=)]+
\
|([^(;=)]*)
\
)*
\
)
)"
self
.
args_pat
=
r"\((?P<args>([^\(;=\)]+|\([^\(;=\)]*\))*)\
)"
self
.
whole_pat
=
self
.
type_pat
+
self
.
name_pat
+
self
.
args_pat
self
.
whole_pat
=
self
.
type_pat
+
self
.
name_pat
+
self
.
args_pat
self
.
sym_pat
=
"^[
\t
]*
\
(<name>[a-zA-Z0-9_]+
\
)[
\t
]*="
+
\
self
.
sym_pat
=
r"^[ \t]*(?P<name>[a-zA-Z0-9_]+
)[ \t]*="
+
\
"[
\t
]*
\
(<defn>[-0-9_a-zA-Z'
\"
(][^
\t\n
,;}]*
\
),?"
r"[ \t]*(?P<defn>[-0-9_a-zA-Z'\"\(][^\t\n,;}]*
),?"
self
.
asplit_pat
=
"^
\
(<type>.*[^a-zA-Z0-9_]
\
)
\
(<name>[a-zA-Z0-9_]+
\
)
\
(<array>
\
[
\
]
\
)?$"
self
.
asplit_pat
=
r"^(?P<type>.*[^a-zA-Z0-9_])(?P<name>[a-zA-Z0-9_]+)(?P<array>\[\]
)?$"
self
.
comment1_pat
=
"
\
(<rest>.*
\
)//.*"
self
.
comment1_pat
=
r"(?P<rest>.*
)//.*"
# note that the next pattern only removes comments that are wholly within one line
# note that the next pattern only removes comments that are wholly within one line
self
.
comment2_pat
=
"
\
(<rest1>.*
\
)/
\
*.*
\
*/
\
(<rest2>.*
\
)"
self
.
comment2_pat
=
r"(?P<rest1>.*)/\*.*\*/(?P<rest2>.*
)"
def
compilepatterns
(
self
):
def
compilepatterns
(
self
):
for
name
in
dir
(
self
):
for
name
in
dir
(
self
):
if
name
[
-
4
:]
==
"_pat"
:
if
name
[
-
4
:]
==
"_pat"
:
pat
=
getattr
(
self
,
name
)
pat
=
getattr
(
self
,
name
)
prog
=
re
gex
.
symcomp
(
pat
)
prog
=
re
.
compile
(
pat
)
setattr
(
self
,
name
[:
-
4
],
prog
)
setattr
(
self
,
name
[:
-
4
],
prog
)
def
initosspecifics
(
self
):
def
initosspecifics
(
self
):
...
@@ -404,20 +403,26 @@ if missing: raise "Missing Types"
...
@@ -404,20 +403,26 @@ if missing: raise "Missing Types"
except
EOFError
:
break
except
EOFError
:
break
if
self
.
debug
:
if
self
.
debug
:
self
.
report
(
"LINE:
%
s"
%
`line`
)
self
.
report
(
"LINE:
%
s"
%
`line`
)
if
self
.
comment1
.
match
(
line
)
>=
0
:
match
=
self
.
comment1
.
match
(
line
)
line
=
self
.
comment1
.
group
(
'rest'
)
if
match
:
line
=
match
.
group
(
'rest'
)
if
self
.
debug
:
if
self
.
debug
:
self
.
report
(
"
\t
after comment1:
%
s"
%
`line`
)
self
.
report
(
"
\t
after comment1:
%
s"
%
`line`
)
while
self
.
comment2
.
match
(
line
)
>=
0
:
match
=
self
.
comment2
.
match
(
line
)
line
=
self
.
comment2
.
group
(
'rest1'
)
+
self
.
comment2
.
group
(
'rest2'
)
while
match
:
line
=
match
.
group
(
'rest1'
)
+
match
.
group
(
'rest2'
)
if
self
.
debug
:
if
self
.
debug
:
self
.
report
(
"
\t
after comment2:
%
s"
%
`line`
)
self
.
report
(
"
\t
after comment2:
%
s"
%
`line`
)
if
self
.
defsfile
and
self
.
sym
.
match
(
line
)
>=
0
:
match
=
self
.
comment2
.
match
(
line
)
if
self
.
debug
:
if
self
.
defsfile
:
self
.
report
(
"
\t
matches sym."
)
match
=
self
.
sym
.
match
(
line
)
self
.
dosymdef
()
if
match
:
continue
if
self
.
debug
:
if
self
.
head
.
match
(
line
)
>=
0
:
self
.
report
(
"
\t
matches sym."
)
self
.
dosymdef
(
match
)
continue
match
=
self
.
head
.
match
(
line
)
if
match
:
if
self
.
debug
:
if
self
.
debug
:
self
.
report
(
"
\t
matches head."
)
self
.
report
(
"
\t
matches head."
)
self
.
dofuncspec
()
self
.
dofuncspec
()
...
@@ -426,8 +431,8 @@ if missing: raise "Missing Types"
...
@@ -426,8 +431,8 @@ if missing: raise "Missing Types"
self
.
error
(
"Uncaught EOF error"
)
self
.
error
(
"Uncaught EOF error"
)
self
.
reportusedtypes
()
self
.
reportusedtypes
()
def
dosymdef
(
self
):
def
dosymdef
(
self
,
match
):
name
,
defn
=
self
.
sym
.
group
(
'name'
,
'defn'
)
name
,
defn
=
match
.
group
(
'name'
,
'defn'
)
if
self
.
debug
:
if
self
.
debug
:
self
.
report
(
"
\t
sym: name=
%
s, defn=
%
s"
%
(
`name`
,
`defn`
))
self
.
report
(
"
\t
sym: name=
%
s, defn=
%
s"
%
(
`name`
,
`defn`
))
if
not
name
in
self
.
blacklistnames
:
if
not
name
in
self
.
blacklistnames
:
...
@@ -438,35 +443,39 @@ if missing: raise "Missing Types"
...
@@ -438,35 +443,39 @@ if missing: raise "Missing Types"
def
dofuncspec
(
self
):
def
dofuncspec
(
self
):
raw
=
self
.
line
raw
=
self
.
line
while
self
.
tail
.
search
(
raw
)
<
0
:
while
not
self
.
tail
.
search
(
raw
)
:
line
=
self
.
getline
()
line
=
self
.
getline
()
if
self
.
debug
:
if
self
.
debug
:
self
.
report
(
"* CONTINUATION LINE:
%
s"
%
`line`
)
self
.
report
(
"* CONTINUATION LINE:
%
s"
%
`line`
)
if
self
.
comment1
.
match
(
line
)
>=
0
:
match
=
self
.
comment1
.
match
(
line
)
line
=
self
.
comment1
.
group
(
'rest'
)
if
match
:
line
=
match
.
group
(
'rest'
)
if
self
.
debug
:
if
self
.
debug
:
self
.
report
(
"
\t
after comment1:
%
s"
%
`line`
)
self
.
report
(
"
\t
after comment1:
%
s"
%
`line`
)
while
self
.
comment2
.
match
(
line
)
>=
0
:
match
=
self
.
comment2
.
match
(
line
)
line
=
self
.
comment2
.
group
(
'rest1'
)
+
self
.
comment2
.
group
(
'rest2'
)
while
match
:
line
=
match
.
group
(
'rest1'
)
+
match
.
group
(
'rest2'
)
if
self
.
debug
:
if
self
.
debug
:
self
.
report
(
"
\t
after comment1:
%
s"
%
`line`
)
self
.
report
(
"
\t
after comment1:
%
s"
%
`line`
)
match
=
self
.
comment2
.
match
(
line
)
raw
=
raw
+
line
raw
=
raw
+
line
if
self
.
debug
:
if
self
.
debug
:
self
.
report
(
"* WHOLE LINE:
%
s"
%
`raw`
)
self
.
report
(
"* WHOLE LINE:
%
s"
%
`raw`
)
self
.
processrawspec
(
raw
)
self
.
processrawspec
(
raw
)
def
processrawspec
(
self
,
raw
):
def
processrawspec
(
self
,
raw
):
if
self
.
whole
.
search
(
raw
)
<
0
:
match
=
self
.
whole
.
search
(
raw
)
if
not
match
:
self
.
report
(
"Bad raw spec:
%
s"
,
`raw`
)
self
.
report
(
"Bad raw spec:
%
s"
,
`raw`
)
if
self
.
debug
:
if
self
.
debug
:
if
self
.
type
.
search
(
raw
)
<
0
:
if
not
self
.
type
.
search
(
raw
)
:
self
.
report
(
"(Type already doesn't match)"
)
self
.
report
(
"(Type already doesn't match)"
)
else
:
else
:
self
.
report
(
"(
Type matched:
%
s)"
%
`self.type.group('type')`
)
self
.
report
(
"(
but type matched)"
)
return
return
type
,
name
,
args
=
self
.
whole
.
group
(
'type'
,
'name'
,
'args'
)
type
,
name
,
args
=
match
.
group
(
'type'
,
'name'
,
'args'
)
type
=
re
gsub
.
g
sub
(
"
\
*"
,
" ptr"
,
type
)
type
=
re
.
sub
(
"
\
*"
,
" ptr"
,
type
)
type
=
re
gsub
.
g
sub
(
"[
\t
]+"
,
"_"
,
type
)
type
=
re
.
sub
(
"[
\t
]+"
,
"_"
,
type
)
if
name
in
self
.
alreadydone
:
if
name
in
self
.
alreadydone
:
self
.
report
(
"Name has already been defined:
%
s"
,
`name`
)
self
.
report
(
"Name has already been defined:
%
s"
,
`name`
)
return
return
...
@@ -500,16 +509,18 @@ if missing: raise "Missing Types"
...
@@ -500,16 +509,18 @@ if missing: raise "Missing Types"
def
extractarg
(
self
,
part
):
def
extractarg
(
self
,
part
):
mode
=
"InMode"
mode
=
"InMode"
if
self
.
asplit
.
match
(
part
)
<
0
:
part
=
part
.
strip
()
match
=
self
.
asplit
.
match
(
part
)
if
not
match
:
self
.
error
(
"Indecipherable argument:
%
s"
,
`part`
)
self
.
error
(
"Indecipherable argument:
%
s"
,
`part`
)
return
(
"unknown"
,
part
,
mode
)
return
(
"unknown"
,
part
,
mode
)
type
,
name
,
array
=
self
.
asplit
.
group
(
'type'
,
'name'
,
'array'
)
type
,
name
,
array
=
match
.
group
(
'type'
,
'name'
,
'array'
)
if
array
:
if
array
:
# array matches an optional [] after the argument name
# array matches an optional [] after the argument name
type
=
type
+
" ptr "
type
=
type
+
" ptr "
type
=
re
gsub
.
g
sub
(
"
\
*"
,
" ptr "
,
type
)
type
=
re
.
sub
(
"
\
*"
,
" ptr "
,
type
)
type
=
string
.
strip
(
type
)
type
=
string
.
strip
(
type
)
type
=
re
gsub
.
g
sub
(
"[
\t
]+"
,
"_"
,
type
)
type
=
re
.
sub
(
"[
\t
]+"
,
"_"
,
type
)
return
self
.
modifyarg
(
type
,
name
,
mode
)
return
self
.
modifyarg
(
type
,
name
,
mode
)
def
modifyarg
(
self
,
type
,
name
,
mode
):
def
modifyarg
(
self
,
type
,
name
,
mode
):
...
@@ -610,23 +621,23 @@ class Scanner_PreUH3(Scanner):
...
@@ -610,23 +621,23 @@ class Scanner_PreUH3(Scanner):
def
initpatterns
(
self
):
def
initpatterns
(
self
):
Scanner
.
initpatterns
(
self
)
Scanner
.
initpatterns
(
self
)
self
.
head_pat
=
"^extern pascal[
\t
]+"
# XXX Mac specific!
self
.
head_pat
=
"^extern pascal[
\t
]+"
# XXX Mac specific!
self
.
type_pat
=
"pascal[
\t\n
]+
\
(<type>[a-zA-Z0-9_
\t
]*[a-zA-Z0-9_]
\
)[
\t\n
]+"
self
.
type_pat
=
"pascal[
\t\n
]+
(?P<type>[a-zA-Z0-9_
\t
]*[a-zA-Z0-9_]
)[
\t\n
]+"
self
.
whole_pat
=
self
.
type_pat
+
self
.
name_pat
+
self
.
args_pat
self
.
whole_pat
=
self
.
type_pat
+
self
.
name_pat
+
self
.
args_pat
self
.
sym_pat
=
"^[
\t
]*
\
(<name>[a-zA-Z0-9_]+
\
)[
\t
]*="
+
\
self
.
sym_pat
=
"^[
\t
]*
(?P<name>[a-zA-Z0-9_]+
)[
\t
]*="
+
\
"[
\t
]*
\
(<defn>[-0-9'
\"
][^
\t\n
,;}]*
\
),?"
"[
\t
]*
(?P<defn>[-0-9'
\"
][^
\t\n
,;}]*
),?"
class
Scanner_OSX
(
Scanner
):
class
Scanner_OSX
(
Scanner
):
"""Scanner for modern (post UH3.3) Universal Headers """
"""Scanner for modern (post UH3.3) Universal Headers """
def
initpatterns
(
self
):
def
initpatterns
(
self
):
Scanner
.
initpatterns
(
self
)
Scanner
.
initpatterns
(
self
)
self
.
head_pat
=
"^EXTERN_API
\
(_C
\
)?"
self
.
head_pat
=
"^EXTERN_API
(_C
)?"
self
.
type_pat
=
"EXTERN_API
\
(_C
\
)?"
+
\
self
.
type_pat
=
"EXTERN_API
(_C
)?"
+
\
"[
\t\n
]*([
\t\n
]*"
+
\
"[
\t\n
]*
\
([
\t\n
]*"
+
\
"
\
(<type>[a-zA-Z0-9_*
\t
]*[a-zA-Z0-9_*]
\
)"
+
\
"
(?P<type>[a-zA-Z0-9_*
\t
]*[a-zA-Z0-9_*]
)"
+
\
"[
\t\n
]*)[
\t\n
]*"
"[
\t\n
]*
\
)[
\t\n
]*"
self
.
whole_pat
=
self
.
type_pat
+
self
.
name_pat
+
self
.
args_pat
self
.
whole_pat
=
self
.
type_pat
+
self
.
name_pat
+
self
.
args_pat
self
.
sym_pat
=
"^[
\t
]*
\
(<name>[a-zA-Z0-9_]+
\
)[
\t
]*="
+
\
self
.
sym_pat
=
"^[
\t
]*
(?P<name>[a-zA-Z0-9_]+
)[
\t
]*="
+
\
"[
\t
]*
\
(<defn>[-0-9_a-zA-Z'
\"
(][^
\t\n
,;}]*
\
),?"
"[
\t
]*
(?P<defn>[-0-9_a-zA-Z'
\"
\
(][^
\t\n
,;}]*
),?"
def
test
():
def
test
():
input
=
"D:Development:THINK C:Mac #includes:Apple #includes:AppleEvents.h"
input
=
"D:Development:THINK C:Mac #includes:Apple #includes:AppleEvents.h"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment