Home   Archive   Permalink

Recursive Parse

Please consider:
i: ["[1]" "[2]"]
rule: [thru "[" keep to "]" | rule]
parse i [collect [into rule]]
== [#"1"]
but would like to get [#"1" #"2"]
What is wrong?

posted by:   lib0       5-Dec-2018/9:46:35-8:00

I presume this is using Red's PARSE (from COLLECT usage). It seems one of your problems here is that you are not fully matching the string--you are going TO "]" but not going through it.
However, I can't quite see why you are using a recursive rule in the first place. It seems to me you could get to your result as follows:
     rule: [thru "[" keep to "]" skip] ; will match each string
     parse i [collect [some into rule]]

posted by:   Chris       6-Dec-2018/13:30:24-8:00

Another way to write it that would be recursive (I don't see this as beneficial vs. using SOME) would be:
     rule: [into [thru "[" keep to "]" skip] opt rule]
     parse i [collect rule]

posted by:   Chris       6-Dec-2018/14:13:18-8:00

Thanks Chris.
This was a minimal example, I'll try to see if recursive is necessary or not for the bigger picture.

posted by:   lib0       11-Dec-2018/6:44:13-8:00



Type the reverse of this captcha text: "e m i t"