Hi,
Here is how you can parse Pd patches into rows of atoms in three languages using regular expressions:
/*** Javascript ***/
var lines_re = new RegExp("(#((.|\r|\n)*?)[^\\\\])\r{0,1}\n{0,1};\r{0,1}\n", "gi");
for (pdline = lines_re.exec(patchtext)) {
var atoms = pdline[1].split(/ |\r\n?|\n/);
}
### Python ###
lines_re = re.compile("(#(.*?)[^\\\])\r{0,1}\n{0,1};\r{0,1}\n", re.MULTILINE | re.DOTALL)
split_re = re.compile(" |\r\n?|\n", re.MULTILINE)
for found in lines_re.finditer(patch):
line = found.group(1)
atoms = split_re.split(line)
/*** Java ***/
private static final String line_re = "(#((.|\r|\n)*?)[^\\\\])\r{0,1}\n{0,1};\r{0,1}\n";
private static final String token_re = " |\r\n?|\n";
Pattern pattern = Pattern.compile(line_re, Pattern.MULTILINE); Pattern token_pattern = Pattern.compile(token_re, Pattern.MULTILINE); Matcher matcher = pattern.matcher(patchtext); ArrayList<String[]> atomlines = new ArrayList<String[]>(); while (matcher.find()) { String[] s = token_pattern.split(matcher.group(1)); atomlines.add(token_pattern.split(matcher.group(1))); }
Also here is a regular expression for matching dollar args:
/(?:\\{0,1}\$)(\d+)/g;
Hopefully this is useful to someone else.
Cheers,
Chris.
Hopefully this is useful to someone else.
It will be :)
Thanks, Pedro
On Mon, Nov 29, 2010 at 4:46 AM, Chris McCormick chris@mccormick.cx wrote:
Hi,
Here is how you can parse Pd patches into rows of atoms in three languages using regular expressions:
/*** Javascript ***/
var lines_re = new
RegExp("(#((.|\r|\n)*?)[^\\])\r{0,1}\n{0,1};\r{0,1}\n", "gi"); for (pdline = lines_re.exec(patchtext)) { var atoms = pdline[1].split(/ |\r\n?|\n/); }
### Python ###
lines_re = re.compile("(#(.*?)[^\\\])\r{0,1}\n{0,1};\r{0,1}\n",
re.MULTILINE | re.DOTALL) split_re = re.compile(" |\r\n?|\n", re.MULTILINE) for found in lines_re.finditer(patch): line = found.group(1) atoms = split_re.split(line)
/*** Java ***/
private static final String line_re =
"(#((.|\r|\n)*?)[^\\])\r{0,1}\n{0,1};\r{0,1}\n"; private static final String token_re = " |\r\n?|\n";
Pattern pattern = Pattern.compile(line_re, Pattern.MULTILINE); Pattern token_pattern = Pattern.compile(token_re,
Pattern.MULTILINE); Matcher matcher = pattern.matcher(patchtext); ArrayList<String[]> atomlines = new ArrayList<String[]>(); while (matcher.find()) { String[] s = token_pattern.split(matcher.group(1)); atomlines.add(token_pattern.split(matcher.group(1))); }
Also here is a regular expression for matching dollar args:
/(?:\\{0,1}\$)(\d+)/g;
Hopefully this is useful to someone else.
Cheers,
Chris.
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Sounds very useful, and would be great to have on the wiki, anywhere
in the docs/developer section, for example.
.hc
On Nov 28, 2010, at 11:46 PM, Chris McCormick wrote:
Hi,
Here is how you can parse Pd patches into rows of atoms in three
languages using regular expressions:/*** Javascript ***/
var lines_re = new RegExp("(#((.|\r|\n)*?)[^\\])\r{0,1}\n{0,1}; \r{0,1}\n", "gi"); for (pdline = lines_re.exec(patchtext)) { var atoms = pdline[1].split(/ |\r\n?|\n/); }
### Python ###
lines_re = re.compile("(#(.*?)[^\])\r{0,1}\n{0,1};\r{0,1}\n",
re.MULTILINE | re.DOTALL) split_re = re.compile(" |\r\n?|\n", re.MULTILINE) for found in lines_re.finditer(patch): line = found.group(1) atoms = split_re.split(line)/*** Java ***/
private static final String line_re = "(#((.|\r|\n)*?)[^\\]) \r{0,1}\n{0,1};\r{0,1}\n"; private static final String token_re = " |\r\n?|\n";
Pattern pattern = Pattern.compile(line_re, Pattern.MULTILINE); Pattern token_pattern = Pattern.compile(token_re, Pattern.MULTILINE); Matcher matcher = pattern.matcher(patchtext); ArrayList<String[]> atomlines = new ArrayList<String[]>(); while (matcher.find()) { String[] s = token_pattern.split(matcher.group(1)); atomlines.add(token_pattern.split(matcher.group(1))); }
Also here is a regular expression for matching dollar args:
/(?:\{0,1}$)(\d+)/g;
Hopefully this is useful to someone else.
Cheers,
Chris.
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Programs should be written for people to read, and only incidentally
for machines to execute.
Hi Hans,
Excellent, I will put it in there. Sorry to be dense, but could you provide me with a link to the page in this wiki you speak of? Or is that the Plone thing?
Cheers,
chris.
On Mon, Nov 29, 2010 at 10:31:32PM -0500, Hans-Christoph Steiner wrote:
Sounds very useful, and would be great to have on the wiki, anywhere in the docs/developer section, for example.
.hc
On Nov 28, 2010, at 11:46 PM, Chris McCormick wrote:
Hi,
Here is how you can parse Pd patches into rows of atoms in three
languages using regular expressions:/*** Javascript ***/
var lines_re = new RegExp("(#((.|\r|\n)*?)[^\\])\r{0,1}\n{0,1}; \r{0,1}\n", "gi"); for (pdline = lines_re.exec(patchtext)) { var atoms = pdline[1].split(/ |\r\n?|\n/); }
### Python ###
lines_re = re.compile("(#(.*?)[^\])\r{0,1}\n{0,1};\r{0,1}\n",
re.MULTILINE | re.DOTALL) split_re = re.compile(" |\r\n?|\n", re.MULTILINE) for found in lines_re.finditer(patch): line = found.group(1) atoms = split_re.split(line)/*** Java ***/
private static final String line_re = "(#((.|\r|\n)*?)[^\\]) \r{0,1}\n{0,1};\r{0,1}\n"; private static final String token_re = " |\r\n?|\n";
Pattern pattern = Pattern.compile(line_re, Pattern.MULTILINE); Pattern token_pattern = Pattern.compile(token_re, Pattern.MULTILINE); Matcher matcher = pattern.matcher(patchtext); ArrayList<String[]> atomlines = new ArrayList<String[]>(); while (matcher.find()) { String[] s = token_pattern.split(matcher.group(1)); atomlines.add(token_pattern.split(matcher.group(1))); }
Also here is a regular expression for matching dollar args:
/(?:\{0,1}$)(\d+)/g;
Hopefully this is useful to someone else.
Cheers,
Chris.
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Programs should be written for people to read, and only incidentally for machines to execute.
- from Structure and Interpretation of Computer Programs
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Sorry, I mean most of puredata info is a wiki, including the /docs/
section. You could just add a wiki page to the root, for example:
.hc
On Nov 30, 2010, at 2:21 AM, Chris McCormick wrote:
Hi Hans,
Excellent, I will put it in there. Sorry to be dense, but could you
provide me with a link to the page in this wiki you speak of? Or is that the
Plone thing?Cheers,
chris.
On Mon, Nov 29, 2010 at 10:31:32PM -0500, Hans-Christoph Steiner
wrote:Sounds very useful, and would be great to have on the wiki,
anywhere in the docs/developer section, for example..hc
On Nov 28, 2010, at 11:46 PM, Chris McCormick wrote:
Hi,
Here is how you can parse Pd patches into rows of atoms in three languages using regular expressions:
/*** Javascript ***/
var lines_re = new RegExp("(#((.|\r|\n)*?)[^\\])\r{0,1}\n{0,1}; \r{0,1}\n", "gi"); for (pdline = lines_re.exec(patchtext)) { var atoms = pdline[1].split(/ |\r\n?|\n/); }
### Python ###
lines_re = re.compile("(#(.*?)[^\])\r{0,1}\n{0,1};\r{0,1}\n", re.MULTILINE | re.DOTALL) split_re = re.compile(" |\r\n?|\n", re.MULTILINE) for found in lines_re.finditer(patch): line = found.group(1) atoms = split_re.split(line)
/*** Java ***/
private static final String line_re = "(#((.|\r|\n)*?)[^\\]) \r{0,1}\n{0,1};\r{0,1}\n"; private static final String token_re = " |\r\n?|\n";
Pattern pattern = Pattern.compile(line_re, Pattern.MULTILINE); Pattern token_pattern = Pattern.compile(token_re,
Pattern.MULTILINE); Matcher matcher = pattern.matcher(patchtext); ArrayList<String[]> atomlines = new ArrayList<String[]>(); while (matcher.find()) { String[] s = token_pattern.split(matcher.group(1)); atomlines.add(token_pattern.split(matcher.group(1))); }Also here is a regular expression for matching dollar args:
/(?:\{0,1}$)(\d+)/g;
Hopefully this is useful to someone else.
Cheers,
Chris.
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Programs should be written for people to read, and only
incidentally for machines to execute.
- from Structure and Interpretation of Computer Programs
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Looking at things from a more basic level, you can come up with a more
direct solution... It may sound small in theory, but it in practice,
it can change entire economies. - Amy Smith
On Tue, Nov 30, 2010 at 12:45:34PM -0500, Hans-Christoph Steiner wrote:
Sorry, I mean most of puredata info is a wiki, including the /docs/
section. You could just add a wiki page to the root, for example:
Hi Hans,
http://puredata.info/docs/developer/ParsingPatchesInVariousLanguages
I linked it into the developer section, hopefully in the right place. Feel free to move it or whatever.
Cheers,
Chris.
On Dec 3, 2010, at 12:46 AM, Chris McCormick wrote:
On Tue, Nov 30, 2010 at 12:45:34PM -0500, Hans-Christoph Steiner
wrote:Sorry, I mean most of puredata info is a wiki, including the /docs/ section. You could just add a wiki page to the root, for example:
Hi Hans,
http://puredata.info/docs/developer/ParsingPatchesInVariousLanguages
I linked it into the developer section, hopefully in the right
place. Feel free to move it or whatever.
Works for me, I just quickly converted it to MoinMoin syntax like the
rest of the docs in that section.
.hc
The arc of history bends towards justice. - Dr. Martin Luther
King, Jr.