Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
57488183
Commit
57488183
authored
Feb 12, 2001
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add special methods for compiling macros.
parent
6e6f40bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
2 deletions
+35
-2
lib/python/TAL/TALGenerator.py
lib/python/TAL/TALGenerator.py
+35
-2
No files found.
lib/python/TAL/TALGenerator.py
View file @
57488183
...
...
@@ -103,8 +103,10 @@ class TALGenerator:
expressionCompiler
=
DummyCompiler
()
self
.
expressionCompiler
=
expressionCompiler
self
.
program
=
[]
self
.
macros
=
{}
self
.
stack
=
[]
self
.
macros
=
{}
self
.
slots
=
{}
self
.
slotStack
=
[]
def
compileExpression
(
self
,
expr
):
return
self
.
expressionCompiler
.
compile
(
expr
)
...
...
@@ -118,6 +120,15 @@ class TALGenerator:
self
.
program
=
self
.
stack
.
pop
()
return
program
def
pushSlots
(
self
):
self
.
slotStack
.
append
(
self
.
slots
)
self
.
slots
=
{}
def
popSlots
(
self
):
slots
=
self
.
slots
self
.
slots
=
self
.
slotStack
.
pop
()
return
slots
def
emit
(
self
,
*
instruction
):
self
.
program
.
append
(
instruction
)
...
...
@@ -173,7 +184,29 @@ class TALGenerator:
else
:
assert
key
==
"structure"
self
.
emit
(
"insertStructure"
,
cexpr
,
attrDict
,
program
)
def
emitDefineMacro
(
self
,
macroName
):
program
=
self
.
popProgram
()
if
self
.
macros
.
has_key
(
macroName
):
raise
METALError
(
"duplicate macro definition: %s"
%
macroName
)
self
.
macros
[
macroName
]
=
program
self
.
emit
(
"defineMacro"
,
macroName
,
program
)
def
emitUseMacro
(
self
,
expr
):
cexpr
=
self
.
compileExpression
(
expr
)
program
=
self
.
popProgram
()
self
.
emit
(
"useMacro"
,
cexpr
,
self
.
popSlots
(),
program
)
def
emitDefineSlot
(
self
,
slotName
):
program
=
self
.
popProgram
()
self
.
emit
(
"defineSlot"
,
slotName
,
program
)
def
emitFillSlot
(
self
,
slotName
):
program
=
self
.
popProgram
()
if
self
.
slots
.
has_key
(
slotName
):
raise
METALError
(
"duplicate slot definition: %s"
%
slotName
)
self
.
slots
[
slotName
]
=
program
self
.
emit
(
"fillSlot"
,
slotName
,
program
)
def
test
():
t
=
TALGenerator
()
...
...
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