AltME: Parse

Messages

szeng
Thanks Doc, I'''' give it a try
Yes, it works. Thanks!
DocKimbel
You're welcome.

Endo
parse/all #{010203} [thru #{03} (print ".")] ;works on R3 and Red but fails on R2, any workaround for this?
Arnold
There is no refinement all. Leave that out and the output is like the output for R3 with all refinement.
Rebolek
Arnold, there is /all refinement in R2.
sqlab
@Endo
parse/all  to-string #{010203}  compose [thru (to-string #{03})  ([(print ".")]) ]
Endo
So is the only workaround parsing binary! is converting to string!?
Although this one works, it looks parsing with binary! works but TO / THRU doesn't.
R2> parse/all #{010203} [#{010203}]
== true
Arnold
Sorry I only use a Red version from before the libRed changes.  that is why I got the message
red>> parse/all #{010203} [thru #{03} (print ".")]
*** Script Error: parse has no refinement called all
*** Where: parse
Endo
Sure, there is no /all in Red, it is default. I meant the difference of TO with binary!.
DocKimbel
Using a char! or string! as matching target works on R2:
parse/all #{010203} [thru #"^(03)" (print ".")]
parse/all #{010203} [thru "^(03)" (print ".")]
Gabriele
You can also use AS-STRING instead of TO-STRING so that there is no conversion really going on.
>> bin: #{010203}
== #{010203}
>> str: as-string bin
== "^A^B^C"
>> append str "A"
== {^A^B^CA}
>> bin
== #{01020341}

Endo
Thank you all, using char/string or as-string looks good solutions.

Last message posted 54 weeks ago.