On Tue, 11 Nov 2003, Jerome Etienne wrote:
i need to do regular expression parsing in puredata under linux. i looked to externals available on the internet but failed to find one. did i miss it ? should i write it myself using the regexp of glibc ?
1. Install GridFlow
2. Put this code in ~/.gridflow_startup:
class FRegexp < FObject def initialize(pattern) _1_symbol pattern end def _1_symbol(pattern) @pattern = Regexp.new pattern.to_s end def _0_symbol(s) m = @pattern.match s.to_s if m then send_out 0, :list, *m.to_a.shift.map {|x| x.intern } else send_out 1 end end install "regexp", 2, 2 end
3. Try it: it takes one mandatory argument, the pattern, in ruby syntax (akin to perl's), which can be configured by inlet 1 too. Then when you send a symbol in inlet 0, a bang will be emitted on outlet 1 if the symbol does not match, and else, a list of matched sections will be emitted on outlet 0, depending on the parentheses.
4. Caveats: it should support GridFlow's strings in addition to symbols; and also you can't specify any backslash codes because Pd is paranoid about them (and about the lovely curlies too {}). I can take care of these if anyone cares.
________________________________________________________________ Mathieu Bouchard http://artengine.ca/matju