It is not complete, it doesn't care about comments in strings, but you got the idea.
szeng
Can anybody help me to replace all of "on-init" in the parttern of "space on-init non-word" with "abcd" in a string?
I've tried
space: charset [#" " #"^-"] word: charset [#"a" - #"z" #"A" - #"Z" #"-"] non-word: complement word on-init-rule: [ space mark: "on-init" non-word ( remove/part mark 7 ;remove on-init insert mark "abcd" ) ]
parse/all inp: {abcasdfasdf on-init a on-init b } [ any [ thru on-init-rule ] ]
it failed with:
** Script error: PARSE - invalid rule or usage of rule: make bitset! #{0040000080} ** Where: parse do either either either -apply- ** Near: parse/all inp: {abcasdfasdf on-init a on-init b } [ any ...
>> q
DocKimbel
Here is a working version:
space: charset [#" " #"^-"] word: charset [#"a" - #"z" #"A" - #"Z" #"-"] non-word: complement word on-init-rule: [ space mark: "on-init" non-word ( remove/part mark 7 ;remove on-init mark: insert mark "abcd" ) :mark ]
parse/all inp: {abcasdfasdf on-init a on-init b } [some [on-init-rule | skip]]
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.
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.
GiuseppeC
I need to parse the following string "5.1+2+1" to split the single numeric values (REBOL2 here) I use the following code:
data: "5.1+2+1" parse data [some [copy percentuale some cs (print ["Percentuale" percentuale]) to ["+" | none] skip] to end]
and I get an error :
** Script Error: Invalid argument: + | none ** Near: parse data [some [copy percentuale some cs (print ["Percentuale" percentuale]) to ["+" | none] skip] to end]
While this works:
data: "5.1+2+1" parse data [some [copy percentuale some cs (print ["Percentuale" percentuale]) to "+" | none skip] to end]
Percentuale 5.1 Percentuale 2 Percentuale 1
Seems <to [ "+" | none]> is not allowed but <to "+" | none> is !
Also, if I use END in palce of NONE :
data: "5.1+2+1" parse data [some [copy percentuale some cs (print ["Percentuale" percentuale]) to "+" | END skip] ]