为什么颜色代码在rebol中起作用,但在红色中起作用

时间:2018-05-22 10:22:23

标签: rebol red

我已经通过解析替换parse / all http://www.rebol.org/view-script.r?script=color-code.r

至于其余部分,我可以看出它为什么不起作用

  

*语法错误:char无效!在{#" ^^(1)" - #" "]解析文本blk}   * 在哪里:做   ***堆栈:运行负载

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 个答案:

答案 0 :(得分:2)

正如错误消息所示,红色中的#"^(1)"语法不正确。 char!文档表明它必须是有效的十六进制数字,需要2,4或6个字符。因此,如果您只是将#"^(01)"替换为无效值,则会以红色加载。