From: Marcus A. <and...@us...> - 2012-04-13 12:13:04
|
Update of /cvsroot/nmedit/patchauthor In directory vz-cvs-3.sog:/tmp/cvs-serv7420 Modified Files: modular.protocol modular.py protocol.py Log Message: Code generating parser. Index: protocol.py =================================================================== RCS file: /cvsroot/nmedit/patchauthor/protocol.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** protocol.py 11 Apr 2012 13:04:59 -0000 1.5 --- protocol.py 13 Apr 2012 12:13:00 -0000 1.6 *************** *** 25,28 **** --- 25,34 ---- = remaining:r white* (number|name) ':' number:n -> (r + n) | white* (number|name) ':' number:n -> (n) + action + = '@' (anything:x ?(x != ';') -> (x))*:c -> (''.join(c)) + params + = (((':':a name:b -> (a+b)) | number):p white* -> (str(p)))*:ps -> (' '.join(ps)) + args + = (name:t white* -> (t))*:ts -> (' '.join(ts)) """ *************** *** 36,77 **** -> ([s[0] + " value({}):c ?(c == {})".format(n ,c), s[1], "{}+{}".format(s[2], n)]) | sequence:s white* name:v ':' number:n '*' number:m '/' number:t ! -> ([s[0] + " string({} {} {}):{}".format(n, m, t, v), s[1] + "'{0}':{0}, ".format(v), "{}+{}*len({})".format(s[2], n, v)]) | sequence:s white* name:v ':' number:n ! -> ([s[0] + " value({}):{}".format(n, v), s[1] + "'{0}':{0}, ".format(v), "{}+{}".format(s[2], n)]) | sequence:s white* name:v ':' name:p '*' (name | number):m ! -> ([s[0] + " mapply('{}' {}):{}".format(p, m, v), s[1] + "'{0}':{0}[0], ".format(v), "{}+{}[1]".format(s[2], v)]) ! | sequence:s white* name:v ':' name:p '(' name:t ')' ! -> ([s[0] + " {}({}):{}".format(p, t, v), s[1] + "'{0}':{0}, ".format(v), "{}+{}['consumed']".format(s[2], v)]) | sequence:s white* name:v ':' name:p ! -> ([s[0] + " {}:{}".format(p, v), s[1] + "'{0}':{0}, ".format(v), "{}+{}['consumed']".format(s[2], v)]) | white* number:c ':' number:n ! -> (["value({}):c ?(c == {})".format(n ,c), "", str(n)]) | white* name:v ':' number:n '*' number:m '/' number:t ! -> (["string({} {} {}):{}".format(n, m, t, v), "'{0}':{0}, ".format(v), "{}*len({})".format(n, v)]) | white* name:v ':' number:n ! -> (["value({}):{}".format(n, v), "'{0}':{0}, ".format(v), str(n)]) | white* name:v ':' name:p '*' (name | number):m ! -> (["mapply('{}' {}):{}".format(p, m, v), "'{0}':{0}[0], ".format(v), v + "[1]"]) ! | white* name:v ':' name:p '(' name:t ')' ! -> (["{}({}):{}".format(p, t, v), "'{0}':{0}, ".format(v), v + "['consumed']"]) | white* name:v ':' name:p ! -> (["{}({}):{}".format(p, v), "'{0}':{0}, ".format(v), v + "['consumed']"]) message ! = white* name:i '%' number:m sequence:s white* ';' ! -> (["{1} = {0} value(({4}-({3})%{4})%{4}) -> ({{{2}'message':'{1}', 'consumed':{3}+({4}-({3})%{4})%{4}}})".format(s[0], i, s[1], s[2], m), i]) ! | white* name:i '(' ((':':a name:b -> (a+b)):p | number:p) ')' '%' number:m sequence:s white* ';' ! -> (["{1} {4} = {0} value(({5}-({3})%{5})%{5}) -> ({{{2}'message':'{1}', 'consumed':{3}+({5}-({3})%{5})%{5}}})".format(s[0], i, s[1], s[2], p, m), '{}({})'.format(i, p)]) ! | white* name:i '(' number:p ')' sequence:s white* ';' ! -> (["{1} {4} = {0} -> ({{{2}'message':'{1}', 'consumed':{3}}})".format(s[0], i, s[1], s[2], p), '{}({})'.format(i, p)]) ! | white* name:i sequence:s white* ';' ! -> (["{1} = {0} -> ({{{2}'message':'{1}', 'consumed':{3}}})".format(s[0], i, s[1], s[2]), i]) ! | white* '-' name:i '%' number:m sequence:s white* ';' ! -> (["{1} = {0} value(({4}-({3})%{4})%{4}) -> ({{{2}'message':'{1}', 'consumed':{3}+({4}-({3})%{4})%{4}}})".format(s[0], i, s[1], s[2], m), ' ']) ! | white* '-' name:i '(' ((':':a name:b -> (a+b)):p | number:p) ')' '%' number:m sequence:s white* ';' ! -> (["{1} {4} = {0} value(({5}-({3})%{5})%{5}) -> ({{{2}'message':'{1}', 'consumed':{3}+({5}-({3})%{5})%{5}}})".format(s[0], i, s[1], s[2], p, m), ' ']) ! | white* '-' name:i '(' number:p ')' sequence:s white* ';' ! -> (["{1} {4} = {0} -> ({{{2}'message':'{1}', 'consumed':{3}}})".format(s[0], i, s[1], s[2], p), ' ']) ! | white* '-' name:i sequence:s white* ';' ! -> (["{1} = {0} -> ({{{2}'message':'{1}', 'consumed':{3}}})".format(s[0], i, s[1], s[2]), ' ']) protocol = protocol:ms message:m (white* end)? --- 42,79 ---- -> ([s[0] + " value({}):c ?(c == {})".format(n ,c), s[1], "{}+{}".format(s[2], n)]) | sequence:s white* name:v ':' number:n '*' number:m '/' number:t ! -> ([s[0] + " string({} {} {}):{}".format(n, m, t, v), s[1], "{}+{}*len({})".format(s[2], n, v)]) | sequence:s white* name:v ':' number:n ! -> ([s[0] + " value({}):{}".format(n, v), s[1], "{}+{}".format(s[2], n)]) | sequence:s white* name:v ':' name:p '*' (name | number):m ! -> ([s[0] + " mapply('{}' {}):{}".format(p, m, v), s[1], "{}+{}[1]".format(s[2], v)]) ! | sequence:s white* name:v ':' name:p '(' args:t ')' ! -> ([s[0] + " {}({}):{}".format(p, t, v), "{}+{}['actions']".format(s[1], v), "{}+{}['consumed']".format(s[2], v)]) | sequence:s white* name:v ':' name:p ! -> ([s[0] + " {}:{}".format(p, v), s[1], "{}+{}['consumed']".format(s[2], v)]) | white* number:c ':' number:n ! -> (["value({}):c ?(c == {})".format(n ,c), "[]", str(n)]) | white* name:v ':' number:n '*' number:m '/' number:t ! -> (["string({} {} {}):{}".format(n, m, t, v), "[]", "{}*len({})".format(n, v)]) | white* name:v ':' number:n ! -> (["value({}):{}".format(n, v), "[]", str(n)]) | white* name:v ':' name:p '*' (name | number):m ! -> (["mapply('{}' {}):{}".format(p, m, v), "[]", v + "[1]"]) ! | white* name:v ':' name:p '(' args:t ')' ! -> (["{}({}):{}".format(p, t, v), v + "['actions']", v + "['consumed']"]) | white* name:v ':' name:p ! -> (["{}({}):{}".format(p, v), "[]", v + "['consumed']"]) message ! = white* (name:i | '-' name:i -> (' ')):j '%' number:m sequence:s white* action:c ';' ! -> (["{1} = {0} value(({5}-({4})%{5})%{5}) -> ({{'consumed':{4}+({5}-({4})%{5})%{5}, 'actions':{2}+{3}}})".format(s[0], i, s[1], c, s[2], m), j]) ! | white* name:i '(' params:p ')' '%' number:m sequence:s white* action:c ';' ! -> (["{1} {6} = {0} value(({5}-({4})%{5})%{5}) -> ({{'consumed':{4}+({5}-({4})%{5})%{5}, 'actions':{2}+{3}}})".format(s[0], i, s[1], c, s[2], m, p), '{}({})'.format(i, p)]) ! | white* name:i '(' params:p ')' sequence:s white* action:c ';' ! -> (["{1} {5} = {0} -> ({{'consumed':{4}, 'actions':{2}+{3}}})".format(s[0], i, s[1], c, s[2], p), '{}({})'.format(i, p)]) ! | white* (name:i | '-' name:i -> (' ')):j sequence:s white* action:c ';' ! -> (["{1} = {0} -> ({{'consumed':{4}, 'actions':{2}+{3}}})".format(s[0], i, s[1], c, s[2]), j]) ! | white* '-' name:i '(' params:p ')' '%' number:m sequence:s white* action:c ';' ! -> (["{1} {6} = {0} value(({5}-({4})%{5})%{5}) -> ({{'consumed':{4}+({5}-({4})%{5})%{5}, 'actions':{2}+{3}}})".format(s[0], i, s[1], c, s[2], m, p), ' ']) ! | white* '-' name:i '(' params:p ')' sequence:s white* action:c ';' ! -> (["{1} {5} = {0} -> ({{'consumed':{4}, 'actions':{2}+{3}}})".format(s[0], i, s[1], c, s[2], p), ' ']) protocol = protocol:ms message:m (white* end)? *************** *** 165,169 **** generatorgrammar = 0 ! def __init__(self, parserfilename, generatorfilename): global parsercommongrammar protocolparser = OMeta.makeGrammar(parserbuildergrammar, {}) --- 167,171 ---- generatorgrammar = 0 ! def __init__(self, parserfilename, parsercontext, generatorfilename): global parsercommongrammar protocolparser = OMeta.makeGrammar(parserbuildergrammar, {}) *************** *** 171,175 **** print grammar parsergrammar = parsercommongrammar + ''.join(grammar[0]) ! self.parser = OMeta.makeGrammar(parsergrammar, {}) global generatorcommongrammar --- 173,177 ---- print grammar parsergrammar = parsercommongrammar + ''.join(grammar[0]) ! self.parser = OMeta.makeGrammar(parsergrammar, parsercontext) global generatorcommongrammar Index: modular.protocol =================================================================== RCS file: /cvsroot/nmedit/patchauthor/modular.protocol,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** modular.protocol 11 Apr 2012 13:04:59 -0000 1.5 --- modular.protocol 13 Apr 2012 12:13:00 -0000 1.6 *************** *** 12,16 **** l19:5 l18:2 checksum:7 ! ; IAmNM --- 12,16 ---- l19:5 l18:2 checksum:7 ! @[{'exec': LightsTemplate.format(pid, startIndex, l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, l17, l18, l19)}]; [...1116 lines suppressed...] -Paramtype(114) fade:7 ! @[]; -Paramtype(115) velocitySensitivity:7 leftGain:6 breakpoint:7 rightGain:6 ! @[]; -Paramtype(117) ringmodDepthMod:7 ringmodDepth:7 ! @[]; -Paramtype(118) quantBits:4 sampleRate:7 sampleRateMod:7 quantOff:1 samplingOff:1 ! @[]; -Paramtype(127) amplify:1 ! @[]; Index: modular.py =================================================================== RCS file: /cvsroot/nmedit/patchauthor/modular.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** modular.py 11 Apr 2012 13:04:59 -0000 1.4 --- modular.py 13 Apr 2012 12:13:00 -0000 1.5 *************** *** 5,60 **** import patch ! modularprotocol = protocol.Protocol("modular.protocol", "host.protocol") ! ! def pm(msg): ! print ! print msg ! ! def ACK36(msg): ! tx({'message':'GetPatchPart', ! 'slot':msg['slot'], ! 'pid':msg['pid'], ! 'code': [0x20, 0x28], ! 'checksum':0}) ! nextSection = { ! 33: [[0x4b, 0x01]], ! 74: [[0x53, 0x01], [0x4b, 0x00]], ! 82: [[0x4c, 0x01], [0x53, 0x00]], ! 77: [[0x66], [0x4c, 0x00]], ! 101: [[0x63]], ! 98: [[0x61]], ! 96: [[0x4e, 0x01]], ! 91: [[0x68], [0x4e, 0x00]], ! } ! ! def Patch(msg): ! part = patch.section(msg['pid'], msg['paddedpart']['part']) ! section = 0 ! if 'section' in part: ! section = part['section'] ! if msg['paddedpart']['partid'] in nextSection: ! tx({'message':'GetPatchPart', ! 'slot':msg['slot'], ! 'pid':msg['pid'], ! 'code': nextSection[msg['paddedpart']['partid']][section], ! 'checksum':0}) ! ! messagehandler = { ! 'IAmNM': pm, ! 'IAmPC': pm, ! 'Error': pm, ! 'ACK36': ACK36, ! 'Patch': Patch ! } def rx(bitstream): message = modularprotocol.parse(bitstream) print message ! if 'message' in message[0]: ! if message[0]['message'] in messagehandler: ! messagehandler[message[0]['message']](message[0]) ! else: ! print message sx = sysex.SysEx('HDSP', rx) --- 5,29 ---- import patch ! parsercontext = { ! 'LightsTemplate': ! "print 'Lights({} {}) {}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}'", ! 'ConnectedTemplate': ! "print 'Modular {} model {} v{}.{} connected.'", ! 'GetPatchPartTemplate': ! "{{'message':'GetPatchPart', 'slot':{}, 'pid':{}, 'code':{}, 'checksum':0}}" ! } ! modularprotocol = protocol.Protocol("modular.protocol", parsercontext, "host.protocol") def rx(bitstream): message = modularprotocol.parse(bitstream) print message ! for action in message[0]['actions']: ! if 'exec' in action: ! exec action['exec'] ! if 'tx' in action: ! tx(eval(action['tx'])) ! else: ! print action sx = sysex.SysEx('HDSP', rx) |