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
af3e11d0
Commit
af3e11d0
authored
Feb 17, 2001
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More modifications to bring the script output in line with the real thing.
parent
78182d27
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
4 deletions
+34
-4
Mac/scripts/unweave.py
Mac/scripts/unweave.py
+34
-4
No files found.
Mac/scripts/unweave.py
View file @
af3e11d0
...
...
@@ -10,9 +10,10 @@ import macostools
BEGINDEFINITION
=
re
.
compile
(
"^<<(?P<name>.*)>>=
\
s*
"
)
USEDEFINITION=re.compile("
^
(
?
P
<
pre
>
.
*
)
<<
(
?
P
<
name
>
.
*
)
>>
(
?
P
<
post
>
[
^=
].
*
)
")
ENDDEFINITION=re.compile("
^@
")
GREMLINS=re.compile("
[
\
xa0
\
xca
]
")
DEFAULT_CONFIG="""
config
= [
filepatterns
= [
("
^
.
*
\
.
cp
$
", "
:
unweave
-
src
"),
("
^
.
*
\
.
h
$
", "
:
unweave
-
include
"),
]
...
...
@@ -38,6 +39,13 @@ class Processor:
self.gencomments = config["
gencomments
"]
else:
self.gencomments = 0
if config.has_key("
filepatterns
"):
self.filepatterns = config["
filepatterns
"]
else:
self.filepatterns = []
self.filepattern_relist = []
for pat, dummy in self.filepatterns:
self.filepattern_relist.append(re.compile(pat))
def _readline(self):
"""Read a line. Allow for pushback"""
...
...
@@ -100,9 +108,16 @@ class Processor:
savedcomment = savedcomment + [(lineno, '//
\
n
')] + defline
else:
savedcomment = defline
savedcomment = self._
extendlines
(savedcomment)
savedcomment = self._
processcomment
(savedcomment)
value = savedcomment + value
savedcomment = []
isfilepattern = 0
for rexp in self.filepattern_relist:
if rexp.search(name):
isfilepattern = 1
break
if 0 and not isfilepattern:
value = self._addspace(value)
self._define(name, value)
else:
if self.gencomments:
...
...
@@ -110,17 +125,25 @@ class Processor:
if savedcomment or line.strip():
savedcomment.append((lineno, '// '+line))
def _
extendlines
(self, comment):
def _
processcomment
(self, comment):
# This routine mimicks some artefact of Matthias' code.
rv = []
for lineno, line in comment:
line = line[:-1]
line = GREMLINS.subn(' ', line)[0]
if len(line) < 75:
line = line + (75-len(line))*' '
line = line + '
\
n
'
rv.append((lineno, line))
return rv
def _addspace(self, value, howmany):
# Yet another routine to mimick yet another artefact
rv = value[0:1]
for lineno, line in value[1:]:
rv.append((lineno, (' '*howmany)+line))
return rv
def resolve(self):
"""Resolve all references"""
for name in self.items.keys():
...
...
@@ -141,15 +164,22 @@ class Processor:
# No rest for the wicked: we have work to do.
self.resolving[name] = 1
result = []
lastlineincomplete = 0
for lineno, line in self.items[name]:
mo = USEDEFINITION.search(line)
if mo:
# We replace the complete line. Is this correct?
macro = mo.group('name')
replacement = self._resolve_one(macro)
if lastlineincomplete:
replacement = self._addspace(replacement, lastlineincomplete)
result = result + replacement
else:
result.append((lineno, line))
if line[-1] == '
\
n
':
lastlineincomplete = 0
else:
lastlineincomplete = len(line)
self.items[name] = result
self.resolved[name] = 1
del self.resolving[name]
...
...
@@ -194,7 +224,7 @@ def process(file, config):
pr = Processor(file, config)
pr.read()
pr.resolve()
for pattern, folder in config['
config
']:
for pattern, folder in config['
filepatterns
']:
pr.save(folder, pattern)
def readconfig():
...
...
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