def bygroups(*args):
 def callback(lexer, match, ctx=None):
  for (i, action) in enumerate(args):
   if (action is None):
    continue
   elif (type(action) is _TokenType):
    data = match.group((i + 1))
    if data:
     (yield (match.start((i + 1)), action, data))
   else:
    if ctx:
     ctx.pos = match.start((i + 1))
    for item in action(lexer, _PseudoMatch(match.start((i + 1)), match.group((i + 1))), ctx):
     if item:
      (yield item)
  if ctx:
   ctx.pos = match.end()
 return callback

def bygroups ( * args ) : def callback ( lexer , match , ctx = None ) : for ( i , action ) in enumerate ( args ) : if ( action is None ) : continue elif ( type ( action ) is _TokenType ) : data = match . group ( ( i + 1 ) ) if data : ( yield ( match . start ( ( i + 1 ) ) , action , data ) ) else : if ctx : ctx . pos = match . start ( ( i + 1 ) ) for item in action ( lexer , _PseudoMatch ( match . start ( ( i + 1 ) ) , match . group ( ( i + 1 ) ) ) , ctx ) : if item : ( yield item ) if ctx : ctx . pos = match . end ( ) return callback
callback that yields multiple actions for each group in the match .