@@ -20,13 +20,13 @@ class TrampolinedGrammarInterpreter(object):
20
20
An interpreter for OMeta grammars that processes input
21
21
incrementally.
22
22
"""
23
- def __init__ (self , grammar , ruleName , callback = None , globals = None ):
23
+ def __init__ (self , grammar , rule , callback = None , globals = None ):
24
24
self .grammar = grammar
25
25
self .position = 0
26
26
self .callback = callback
27
27
self .globals = globals or {}
28
28
self .rules = decomposeGrammar (grammar )
29
- self .next = self .apply ( ruleName , None , () )
29
+ self .next = self .setNext ( rule )
30
30
self ._localsStack = []
31
31
self .currentResult = None
32
32
self .input = InputStream ([], 0 )
@@ -68,6 +68,12 @@ def end(self):
68
68
self .callback (* x )
69
69
70
70
71
+ def setNext (self , rule ):
72
+ if not isinstance (rule , tuple ):
73
+ rule = (rule , )
74
+ return self .apply (rule [0 ], None , rule [1 :])
75
+
76
+
71
77
## Implementation note: each method, instead of being a function
72
78
## returning a value, is a generator that will yield '_feed_me' an
73
79
## arbitrary number of times, then finally yield the value of the
@@ -148,10 +154,15 @@ def apply(self, ruleName, codeName, args):
148
154
Invoke a rule, optionally with arguments.
149
155
"""
150
156
argvals = []
151
- for a in args :
152
- for x in self ._eval (a ):
153
- if x is _feed_me : yield x
154
- argvals .append (x [0 ])
157
+ # we tell whether a rule is a manually set one by the codeName
158
+ # if it's None, then we think it's set by setNext
159
+ if codeName is None :
160
+ argvals = args
161
+ else :
162
+ for a in args :
163
+ for x in self ._eval (a ):
164
+ if x is _feed_me : yield x
165
+ argvals .append (x [0 ])
155
166
_locals = {}
156
167
self ._localsStack .append (_locals )
157
168
try :
0 commit comments