srcparser.py (ae54856b) srcparser.py (7d9fa7c3)
1# *************************************************************
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance

--- 94 unchanged lines hidden (view full) ---

103
104 def expand (self):
105 self.pos = 0
106 while self.pos < len(self.tokens):
107 self.expandToken()
108
109 def expandToken (self):
110 token = self.tokens[self.pos]
1# *************************************************************
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance

--- 94 unchanged lines hidden (view full) ---

103
104 def expand (self):
105 self.pos = 0
106 while self.pos < len(self.tokens):
107 self.expandToken()
108
109 def expandToken (self):
110 token = self.tokens[self.pos]
111 if not self.defines.has_key(token):
111 if token not in self.defines:
112 self.pos += 1
113 return
114
115 macro = self.defines[token]
112 self.pos += 1
113 return
114
115 macro = self.defines[token]
116 nvars = len(macro.vars.keys())
116 nvars = len(list(macro.vars.keys()))
117 if nvars == 0:
118 # Simple expansion
119 self.tokens[self.pos:self.pos+1] = macro.tokens
120 return
121 else:
122 # Expansion with arguments.
123 values, lastPos = self.parseValues()
124 newtokens = []
125 for mtoken in macro.tokens:
117 if nvars == 0:
118 # Simple expansion
119 self.tokens[self.pos:self.pos+1] = macro.tokens
120 return
121 else:
122 # Expansion with arguments.
123 values, lastPos = self.parseValues()
124 newtokens = []
125 for mtoken in macro.tokens:
126 if macro.vars.has_key(mtoken):
126 if mtoken in macro.vars:
127 # variable
128 pos = macro.vars[mtoken]
129 valtokens = values[pos]
130 for valtoken in valtokens:
131 newtokens.append(valtoken)
132 else:
133 # not a variable
134 newtokens.append(mtoken)

--- 15 unchanged lines hidden (view full) ---

150 i = 1
151 scope = 0
152 value = []
153 while True:
154 try:
155 tk = self.tokens[self.pos+i]
156 except IndexError:
157 progress ("error parsing values (%d)\n"%i)
127 # variable
128 pos = macro.vars[mtoken]
129 valtokens = values[pos]
130 for valtoken in valtokens:
131 newtokens.append(valtoken)
132 else:
133 # not a variable
134 newtokens.append(mtoken)

--- 15 unchanged lines hidden (view full) ---

150 i = 1
151 scope = 0
152 value = []
153 while True:
154 try:
155 tk = self.tokens[self.pos+i]
156 except IndexError:
157 progress ("error parsing values (%d)\n"%i)
158 for j in xrange(0, i):
159 print self.tokens[self.pos+j],
160 print ''
158 for j in range(0, i):
159 print(self.tokens[self.pos+j], end=' ')
160 print('')
161 srclexer.dumpTokens(self.tokens)
162 srclexer.dumpTokens(self.newtokens)
161 srclexer.dumpTokens(self.tokens)
162 srclexer.dumpTokens(self.newtokens)
163 print "tokens expanded so far:"
163 print("tokens expanded so far:")
164 for tk in self.expandedTokens:
164 for tk in self.expandedTokens:
165 print "-"*20
166 print tk
165 print("-"*20)
166 print(tk)
167 srclexer.dumpTokens(self.defines[tk].tokens)
168 sys.exit(1)
169 if tk == '(':
170 value = []
171 scope += 1
172 elif tk == ',':
173 values.append(value)
174 value = []

--- 27 unchanged lines hidden (view full) ---

202 self.elementStack = [RootNode()]
203 self.stmtData = Statement()
204 self.tokenBuf = []
205 self.leftTokens = []
206
207 # Expand defined macros.
208 if self.debug:
209 progress ("-"*68+"\n")
167 srclexer.dumpTokens(self.defines[tk].tokens)
168 sys.exit(1)
169 if tk == '(':
170 value = []
171 scope += 1
172 elif tk == ',':
173 values.append(value)
174 value = []

--- 27 unchanged lines hidden (view full) ---

202 self.elementStack = [RootNode()]
203 self.stmtData = Statement()
204 self.tokenBuf = []
205 self.leftTokens = []
206
207 # Expand defined macros.
208 if self.debug:
209 progress ("-"*68+"\n")
210 for key in self.defines.keys():
210 for key in list(self.defines.keys()):
211 progress ("define: %s\n"%key)
212
213 self.expandMacro()
214 self.tokenSize = len(self.tokens)
215
216 def expandMacro (self):
217 macroExp = MacroExpander(self.tokens, self.defines)
218 macroExp.expand()

--- 90 unchanged lines hidden (view full) ---

309 self.leftTokens = []
310
311 return i
312
313 # close brace token '}'
314 def closeBrace (self, i):
315 if len(self.tokenBuf) > 0:
316 if self.debug:
211 progress ("define: %s\n"%key)
212
213 self.expandMacro()
214 self.tokenSize = len(self.tokens)
215
216 def expandMacro (self):
217 macroExp = MacroExpander(self.tokens, self.defines)
218 macroExp.expand()

--- 90 unchanged lines hidden (view full) ---

309 self.leftTokens = []
310
311 return i
312
313 # close brace token '}'
314 def closeBrace (self, i):
315 if len(self.tokenBuf) > 0:
316 if self.debug:
317 print self.tokenBuf
317 print(self.tokenBuf)
318 raise ParseError ('')
319 self.elementStack.pop()
320 return i
321
322 # semi colon token ';'
323 def semiColon (self, i):
324 stackSize = len(self.elementStack)
325 scope = stackSize - 1

--- 110 unchanged lines hidden ---
318 raise ParseError ('')
319 self.elementStack.pop()
320 return i
321
322 # semi colon token ';'
323 def semiColon (self, i):
324 stackSize = len(self.elementStack)
325 scope = stackSize - 1

--- 110 unchanged lines hidden ---