midi - How to break out of a subrule once a certain part of the rule is met? -
midi - How to break out of a subrule once a certain part of the rule is met? -
currently parsing midi messages firmata protocol in rebol 3, , came across situation haven't seen before.
basically, have generic rule re-create bytes between framing bytes. rule eating framing bytes. have reduced code following:
data: #{ f06c00010101040e7f000101010308040e7f00010101040e7f0001010103 08040e7f000101010308040e7f00010101040e7f00010101040e7f0001010103 08040e7f000101010308040e7f000101010308040e7f00010101040e7f000101 01040e7f00010101020a7f00010101020a7f00010101020a7f00010101020a7f 00010101020a06017f00010101020a06017ff7 } sysex-start: #{f0} sysex-end: #{f7} capability-query: #{6b} capability-response: #{6c} capability-end: #{7f} received-rule: [ sysex-start capability-response-rule sysex-end ] capability-response-rule: [ capability-response [ capability-end | [copy pin 1 skip] ] ] parse info received-rule
the issue some [copy pin 1 skip]
gobbling sysex-end
binary.
is there way can restructure rule (without moving sysex-end
subrule)?
is there parse keyword help in case of breaking out of subrule?
(note: i'm aware i'm not interpreting info according spec.)
you'll need break loop when hits sysex-end 1 way or another.
you either match sysex-end each time around loop , break when hits, or match against not sysex-end.
the first alternative brings sysex-end subrule, seems straightforward. if recast problem this:
problem-rule: [ (matched-bytes: none) re-create matched-bytes [skip] ]
then first solution using not keyword might be:
alternative-1: [ (matched-bytes: none) re-create matched-bytes [ not sysex-end skip ] ]
the sec alternative not bring sysex-end subrule. create bitset! match except sysex-end (247 corresponds hex f7):
not-sysex-end: bits: create bitset! [0 - 246 248 - 255] alternative-2: [ (matched-bytes: none) re-create matched-bytes [not-sysex-end] ]
i'm not familiar plenty rebol 3 bitsets know if there improve way specify this.
the sec alternative here improve because meets requirement , perform much faster first alternative.
midi rebol rebol3 firmata
Comments
Post a Comment