Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cc6ac29e
Commit
cc6ac29e
authored
Apr 12, 2002
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Added support for inherent pointer types (typedefs of arrays)
- Added a debug class variable to enable parser debugging.
parent
b32b5501
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
Tools/bgen/bgen/scantools.py
Tools/bgen/bgen/scantools.py
+34
-0
No files found.
Tools/bgen/bgen/scantools.py
View file @
cc6ac29e
...
@@ -32,6 +32,9 @@ Error = "scantools.Error"
...
@@ -32,6 +32,9 @@ Error = "scantools.Error"
class
Scanner
:
class
Scanner
:
# Set to 1 in subclass to debug your scanner patterns.
debug
=
0
def
__init__
(
self
,
input
=
None
,
output
=
None
,
defsoutput
=
None
):
def
__init__
(
self
,
input
=
None
,
output
=
None
,
defsoutput
=
None
):
self
.
initsilent
()
self
.
initsilent
()
self
.
initblacklists
()
self
.
initblacklists
()
...
@@ -119,6 +122,7 @@ if missing: raise "Missing Types"
...
@@ -119,6 +122,7 @@ if missing: raise "Missing Types"
def
initrepairinstructions
(
self
):
def
initrepairinstructions
(
self
):
self
.
repairinstructions
=
self
.
makerepairinstructions
()
self
.
repairinstructions
=
self
.
makerepairinstructions
()
self
.
inherentpointertypes
=
self
.
makeinherentpointertypes
()
def
makerepairinstructions
(
self
):
def
makerepairinstructions
(
self
):
"""Parse the repair file into repair instructions.
"""Parse the repair file into repair instructions.
...
@@ -210,6 +214,9 @@ if missing: raise "Missing Types"
...
@@ -210,6 +214,9 @@ if missing: raise "Missing Types"
replacements
.
append
(
replacement
)
replacements
.
append
(
replacement
)
list
.
append
((
fpat
,
patterns
,
replacements
))
list
.
append
((
fpat
,
patterns
,
replacements
))
return
list
return
list
def
makeinherentpointertypes
(
self
):
return
[]
def
openrepairfile
(
self
,
filename
=
"REPAIR"
):
def
openrepairfile
(
self
,
filename
=
"REPAIR"
):
try
:
try
:
...
@@ -395,14 +402,24 @@ if missing: raise "Missing Types"
...
@@ -395,14 +402,24 @@ if missing: raise "Missing Types"
while 1:
while 1:
try: line = self.getline()
try: line = self.getline()
except EOFError: break
except EOFError: break
if self.debug:
self.report("LINE: %s" % `line`)
if self.comment1.match(line) >= 0:
if self.comment1.match(line) >= 0:
line = self.comment1.group('
rest
')
line = self.comment1.group('
rest
')
if self.debug:
self.report("
\
t
after comment1: %s" % `line`)
while self.comment2.match(line) >= 0:
while self.comment2.match(line) >= 0:
line = self.comment2.group('
rest1
')+self.comment2.group('
rest2
')
line = self.comment2.group('
rest1
')+self.comment2.group('
rest2
')
if self.debug:
self.report("
\
t
after comment2: %s" % `line`)
if self.defsfile and self.sym.match(line) >= 0:
if self.defsfile and self.sym.match(line) >= 0:
if self.debug:
self.report("
\
t
matches sym.")
self.dosymdef()
self.dosymdef()
continue
continue
if self.head.match(line) >= 0:
if self.head.match(line) >= 0:
if self.debug:
self.report("
\
t
matches head.")
self.dofuncspec()
self.dofuncspec()
continue
continue
except EOFError:
except EOFError:
...
@@ -411,6 +428,8 @@ if missing: raise "Missing Types"
...
@@ -411,6 +428,8 @@ if missing: raise "Missing Types"
def dosymdef(self):
def dosymdef(self):
name, defn = self.sym.group('
name
', '
defn
')
name, defn = self.sym.group('
name
', '
defn
')
if self.debug:
self.report("
\
t
sym: name=%s, defn=%s" % (`name`, `defn`))
if not name in self.blacklistnames:
if not name in self.blacklistnames:
self.defsfile.write("%s = %s
\
n
" % (name, defn))
self.defsfile.write("%s = %s
\
n
" % (name, defn))
else:
else:
...
@@ -421,16 +440,29 @@ if missing: raise "Missing Types"
...
@@ -421,16 +440,29 @@ if missing: raise "Missing Types"
raw = self.line
raw = self.line
while self.tail.search(raw) < 0:
while self.tail.search(raw) < 0:
line = self.getline()
line = self.getline()
if self.debug:
self.report("* CONTINUATION LINE: %s" % `line`)
if self.comment1.match(line) >= 0:
if self.comment1.match(line) >= 0:
line = self.comment1.group('
rest
')
line = self.comment1.group('
rest
')
if self.debug:
self.report("
\
t
after comment1: %s" % `line`)
while self.comment2.match(line) >= 0:
while self.comment2.match(line) >= 0:
line = self.comment2.group('
rest1
')+self.comment2.group('
rest2
')
line = self.comment2.group('
rest1
')+self.comment2.group('
rest2
')
if self.debug:
self.report("
\
t
after comment1: %s" % `line`)
raw = raw + line
raw = raw + line
if self.debug:
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:
if self.whole.search(raw) < 0:
self.report("Bad raw spec: %s", `raw`)
self.report("Bad raw spec: %s", `raw`)
if self.debug:
if self.type.search(raw) < 0:
self.report("(Type already doesn'
t
match
)
")
else:
self.report("
(
Type
matched
:
%
s
)
" % `self.type.group('type')`)
return
return
type, name, args = self.whole.group('type', 'name', 'args')
type, name, args = self.whole.group('type', 'name', 'args')
type = regsub.gsub("
\
*
", "
ptr
", type)
type = regsub.gsub("
\
*
", "
ptr
", type)
...
@@ -486,6 +518,8 @@ if missing: raise "Missing Types"
...
@@ -486,6 +518,8 @@ if missing: raise "Missing Types"
elif type[-4:] == "
_ptr
":
elif type[-4:] == "
_ptr
":
type = type[:-4]
type = type[:-4]
mode = "
OutMode
"
mode = "
OutMode
"
elif type in self.inherentpointertypes:
mode = "
OutMode
"
if type[-4:] == "
_far
":
if type[-4:] == "
_far
":
type = type[:-4]
type = type[:-4]
return type, name, mode
return type, name, mode
...
...
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