コード例 #1
0
ファイル: home.py プロジェクト: invigo/silica
def run():
  primitives()
  metacommands()
  modes()
  scales()
  instruments()
  
  ## test macros
  sg.new_macro('P', 'play')
  sg.new_macro('R', 'rest')
  sg.new_macro('HAT', 'p rp p lp p')
  sg.new_macro('STAIRS3', 'p rp p rp p rp')
  sg.new_macro('HATCMD', 'begingroup p rp p lp p endgroup')
  return True
コード例 #2
0
    def define_macro(self, string):
        # = is syntactic sugar for >> begingroup ... endgroup
        splitter = '>>'
        if '=' in string:
            splitter = '='
        vals = string.split(splitter, 1)
        signature = vals[0].strip()
        if len(vals) == 2:
            body = vals[1].strip()

        if len(body) == 0:
            ex = SilicaSyntaxError(
                'Syntax error in macro definition: macro has no body.')
            return SilicaEvent('exception', exception=ex)

        vals = signature.split('(', 1)
        name = vals[0].strip().upper()

        if not self.valid_name(name):
            ex = SilicaNameError('The name %s is invalid in this context.' %
                                 name)
            return SilicaEvent('exception', exception=ex)

        args = None
        if len(vals) == 2:
            arglist = vals[1].strip()
            if len(arglist) > 0:
                if arglist[-1] != ')':
                    ex = SilicaSyntaxError(
                        'Syntax error in macro definition: unbounded arglist.')
                    return SilicaEvent('exception', exception=ex)
                else:
                    arglist = arglist[:-1]
                    arglist = arglist.split(',')
                    args = [a.strip() for a in arglist]

        if splitter == '=':
            body = 'begingroup ' + body + ' endgroup'
        sg.new_macro(name, body, args)
        return SilicaEvent('macro_def', message='Macro %s defined.' % name)
コード例 #3
0
ファイル: parser.py プロジェクト: gatesphere/silica
  def define_macro(self, string):
    # = is syntactic sugar for >> begingroup ... endgroup
    splitter = '>>'
    if '=' in string:
      splitter = '='
    vals = string.split(splitter, 1)
    signature = vals[0].strip()
    if len(vals) == 2:
      body = vals[1].strip()

    if len(body) == 0:
      ex = SilicaSyntaxError('Syntax error in macro definition: macro has no body.')
      return SilicaEvent('exception', exception=ex)

    vals = signature.split('(',1)
    name = vals[0].strip().upper()
    
    if not self.valid_name(name):
      ex = SilicaNameError('The name %s is invalid in this context.' % name)
      return SilicaEvent('exception', exception=ex)
    
    args = None
    if len(vals) == 2:
      arglist = vals[1].strip()
      if len(arglist) > 0:
        if arglist[-1] != ')':
            ex = SilicaSyntaxError('Syntax error in macro definition: unbounded arglist.')
            return SilicaEvent('exception', exception=ex)
        else:
          arglist = arglist[:-1]
          arglist = arglist.split(',')
          args = [a.strip() for a in arglist]
    
    if splitter == '=':
      body = 'begingroup ' + body + ' endgroup'
    sg.new_macro(name, body, args)
    return SilicaEvent('macro_def', message='Macro %s defined.' % name)