[REBOL] Re: parse rule for converting hex to decimal
From: semseddinm:bircom at: 24-Feb-2010 11:28
Hi,
It is strange but if I put a trace on just before the
parse/all line script gives an error, otherwise it prints just first value.
trace on
parse/all text [some [opt #"," hex-num]]
Match: (print hex-to-dec hex-digits)
Input: ,$20,$33,$0102222
** Script Error: Trace: "Invalid argument:" (string)
Trace: :arg1 (get-word)
Invalid argument: scheme: console
r: copy [] parse/all {$FA,$20,$33,$0102} [some
["$" copy h to "," "," (append r to-integer debase/base h 16)]
]
probe r
runs well, but the last value is missing.
{$FA,$20,$33,$0102,} works.
Anyway, I got the idea :) thanks for all the replies.
> Hi Semseddin,
>
> SM> is there anyone already write a parse rule to convert hexadecimal to
> SM> decimal? here is my situation,
>
> Others have responded, so I'll just add this version for consderation.
> Feel free to post any questions about the naming conventions or
> structure.
>
> -- Gregg
>
> text: {$FA,$20,$33,$0102}
>
> hex-digit=: charset "0123456798ABCDEF"
>
> =hex-digits: none
> hex-digits=: [copy =hex-digits some hex-digit=]
>
> =hex-num: none
> hex-num=: [#"$" hex-digits= actions/hex-num=]
>
> actions: [
> hex-num= (print hex-to-dec =hex-digits)
> ]
>
> hex-to-dec: func [hex-digits [string!]] [
> to integer! debase/base hex-digits 16
> ]
>
> parse/all text [some [opt #"," hex-num=]]
>
--
=DDyi =E7al=FD=FEmalar,
=DEemseddin Moldibi