MCPcopy
hub / github.com/rocky/python-uncompyle6 / nonterminal

Method nonterminal

uncompyle6/parser.py:241–274  ·  view source on GitHub ↗
(self, nt, args)

Source from the content-addressed store, hash-verified

239 return args_pos, args_kw
240
241 def nonterminal(self, nt, args):
242 n = len(args)
243
244 # # Use this to find lots of singleton rule
245 # if n == 1 and nt not in self.singleton:
246 # print("XXX", nt)
247
248 if nt in self.collect and n > 1:
249 #
250 # Collect iterated thingies together. That is rather than
251 # stmts -> stmts stmt -> stmts stmt -> ...
252 # stmms -> stmt stmt ...
253 #
254 if not hasattr(args[0], "append"):
255 # Was in self.optional_nt as a single item, but we find we have
256 # more than one now...
257 rv = GenericASTBuilder.nonterminal(self, nt, [args[0]])
258 else:
259 rv = args[0]
260 pass
261 # In a list-like entity where the first item goes to epsilon,
262 # drop that and save the 2nd item as the first one
263 if len(rv) == 0 and nt not in self.keep_epsilon:
264 rv = args[1]
265 else:
266 rv.append(args[1])
267 elif n == 1 and args[0] in self.singleton:
268 rv = GenericASTBuilder.nonterminal(self, nt, args[0])
269 del args[0] # save memory
270 elif n == 1 and nt in self.optional_nt:
271 rv = args[0]
272 else:
273 rv = GenericASTBuilder.nonterminal(self, nt, args)
274 return rv
275
276 def __ambiguity(self, children):
277 # only for debugging! to be removed hG/2000-10-15

Callers

nothing calls this directly

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected