| |
- PdParser
- exceptions.Exception(exceptions.BaseException)
-
- PdParserException
class PdParser |
|
Parse Pd files using user defined filters.
>>> p = PdParser("patches/parser-test.pd")
>>> def found(canvasStack, type, action, bits):
... print "canvasStack:", canvasStack, "type:", type, "action:", action, "arguments:", bits
...
>>> p.add_filter_method(found, canvas="REFERENCE", type="#X", action="text")
>>> p.add_filter_method(found, canvas="semicolon-test", type="#X", action="msg")
>>> p.add_filter_method(found, object="osc~")
>>> p.parse()
canvasStack: ['patches/parser-test.pd', 'REFERENCE'] type: #X action: text arguments: 135 336 Tags: tag_one \, tag_two
canvasStack: ['patches/parser-test.pd', 'REFERENCE'] type: #X action: text arguments: 115 301 Description: Some kind of verbose description here.
<BLANKLINE>
canvasStack: ['patches/parser-test.pd', 'REFERENCE'] type: #X action: text arguments: 114 121 Name: thing
canvasStack: ['patches/parser-test.pd', 'REFERENCE'] type: #X action: text arguments: 114 174 Argument 0: first argument (required)
canvasStack: ['patches/parser-test.pd', 'REFERENCE'] type: #X action: text arguments: 114 194 Argument 1: second argument (optional)
canvasStack: ['patches/parser-test.pd', 'REFERENCE'] type: #X action: text arguments: 114 214 Inlet 0: my first inlet is blah
canvasStack: ['patches/parser-test.pd', 'REFERENCE'] type: #X action: text arguments: 114 234 Inlet 1: msg1 <msg1arg>: what this message does. msg2
<msg2arg>: what this other message does \, default 0 which is the default
<BLANKLINE>
canvasStack: ['patches/parser-test.pd', 'REFERENCE'] type: #X action: text arguments: 114 278 Outlet 0: what comes out the second outlet.
canvasStack: ['patches/parser-test.pd', 'REFERENCE'] type: #X action: text arguments: 113 141 Summary: what this thing does is blah blah blah
canvasStack: ['patches/parser-test.pd'] type: #X action: obj arguments: 471 83 osc~ 220
canvasStack: ['patches/parser-test.pd', 'semicolon-test'] type: #X action: msg arguments: 10 18 this is a message box \, with comments \, and also \;
semicolons! yes it is. it's like this: yo. test \; test \; test \;
<BLANKLINE>
canvasStack: ['patches/parser-test.pd'] type: #X action: obj arguments: 633 213 osc~ 440
49 |
|
Methods defined here:
- __init__(self, filename)
- >>> p = PdParser("patches/parser-test.pd")
- add_filter_method(self, method, **kwargs)
- The method will be called on each filter which matches for each line-element of the Pd file.
The method can be passed the following variables:
The current canvas stack (an array), where the last element is the current canvas.
The type, such as "#X", "#N", etc.
The action, such as "canvas", "obj", "msg", "txt"
The first argument (such as the actual object passed) like "osc~"
The remaining arguments, as a string.
>>> def found(canvasStack, type, action, bits):
... print "canvasStack:", canvasStack, "type:", type, "action:", action, "arguments:", bits
...
For example:
canvas = "REFERENCE" will fire the method on each line inside that canvas.
type = "#X" will fire the method on each line which has a type of #X.
action = "obj" will fire on each line which has an 'action' of "obj.
object = "osc~" will fire on each line which has a first argument of 'obj~'
You can chain multiple of these in the filter.
For example, to find all comments in the subpatch called "REFERENCE":
>>> p = PdParser("patches/parser-test.pd")
>>> p.add_filter_method(found, canvas="REFERENCE", type="#X", action="text")
- parse(self)
- Trigger the actual parse.
>>> p = PdParser("patches/parser-test.pd")
>>> print p.parse(), "elements found"
49 elements found
|
|