Discussion forum for David Beazley

SLY - Multiple arguments


Hello I would like to know how to implement non-static arguments!
An example:

Static statement /
@_(‘PRINT “(” STRING “)”’)
def statement(self, p):
return (‘print_stmt’, STRING)

returns -> (‘print_stmt’, “Hello”)

And I would like it to return -> (‘print_stmt’, ‘Hello’, ‘world’, ‘a’, ‘123’) if print(arg1, arg2, arg*) is called!

Thank you, Roberto!


If you want to collect multiple things, you need to write parsing rules for it. For example:

@_('PRINT "(" things ")"')
def statement(self, p):
      return ('print_stmt', *p.things)

@_('things COMMA thing')
def things(self, p):
      return p.things

def things(self, p):
     return [ p.thing ]