为什么颜色代码在 rebol 中有效但在红色中无效

Why color-code does work in rebol but not in red

我已经用 parse 替换了 parse/all http://www.rebol.org/view-script.r?script=color-code.r

至于其余的我明白为什么它不起作用

* Syntax Error: invalid char! at {#"^^(1)" - #" "] parse text blk} * Where: do *** Stack: run load

color-coder: make object! [

    ; Set the color you want for each datatype:
    colors: [
         char!          0.120.40
         date!          0.120.150
         decimal!       0.120.150
         email!         0.120.40
         file!          0.120.40
         integer!       0.120.150
         issue!         0.120.40
         money!         0.120.150
         pair!          0.120.150
         string!        0.120.40
         tag!           0.120.40
         time!          0.120.150
         tuple!         0.120.150
         url!           0.120.40
         refinement!    160.120.40
         cmt            10.10.160
    ]

    out: none

    emit: func [data] [repend out data]

    to-color: func [tuple][
        result: copy "#"
        repeat n 3 [append result back back tail to-hex pick tuple n]
        result
    ]

    emit-color: func [value start stop /local color][
        either none? :value [color: select colors 'cmt][
            if path? :value [value: first :value]
            color: either word? :value [
                any [
                    all [value? :value any-function? get :value 140.0.0]
                    all [value? :value datatype? get :value 120.60.100]
                ]
            ][
                any [select colors type?/word :value]
            ]
        ]
        either color [ ; (Done this way so script can color itself.)
            emit ["-[" {-font color="} to-color color {"-} "]-"
                copy/part start stop "-[" "-/font-" "]-"]
        ][
            emit copy/part start stop
        ]
    ]

    set 'color-code func [
        "Return color source code as HTML."
        text [string!] "Source code text"
        /local str new value
    ][
        out: make string! 3 * length? text

        set [value text] load/next/header detab text
        emit copy/part head text text
        spc: charset [#"^(1)" - #" "] ; treat like space

        parse text blk-rule: [
            some [
                str:
                some spc new: (emit copy/part str new) |
                newline (emit newline)|
                #";" [thru newline | to end] new: 
                    (emit-color none str new) |
                [#"[" | #"("] (emit first str) blk-rule |
                [#"]" | #")"] (emit first str) break |
                skip (
                    set [value new] load/next str
                    emit-color :value str new
                ) :new
            ]
        ]

        foreach [from to] reduce [ ; (join avoids the pattern)
            "&" "&" "<" "<" ">" ">"
            join "-[" "-" "<" join "-" "]-" ">"
        ][
            replace/all out from to
        ]

        insert out {<html><body bgcolor="#ffffff"><pre>}
        append out {</pre></body></html>}
    ]
]

如错误消息所述,#"^(1)" 语法在 Red 中不正确。 char! 文档指出它需要是一个有效的十六进制数,这需要 2、4 或 6 个字符。因此,如果您只是将无效值替换为 #"^(01)",它将在红色中正常加载。