REBOL Programming/to-typeset

From Wikibooks, open books for an open world
< REBOL Programming
Jump to: navigation, search

USAGE:[edit]

TO-TYPESET value 

DESCRIPTION:[edit]

Converts to typeset! value.

TO-TYPESET is a function value.

ARGUMENTS[edit]

  • value -- (Type: any)

(SPECIAL ATTRIBUTES)[edit]

  • catch

SOURCE CODE[edit]

to-typeset: func [
    "Converts to typeset! value." [catch] value /local 
    anytype 
    anyblock 
    anyfunction 
    anystring 
    anyword 
    series 
    number
][
    anytype: [
        none! logic! integer! decimal! money! char! pair! tuple! time! date! 
        string! binary! file! email! url! tag! issue! bitset! image! block! 
        paren! path! set-path! lit-path! datatype! word! set-word! get-word! 
        lit-word! refinement! native! action! routine! op! function! object! 
        error! port! event! struct! library! hash! list! symbol! unset!
    ] 
    anyblock: [
        block! paren! path! set-path! lit-path! hash! list!
    ] 
    anyfunction: [
        native! action! routine! op! function!
    ] 
    anystring: [
        string! binary! file! email! url! tag! issue!
    ] 
    anyword: [
        word! set-word! get-word! lit-word! refinement!
    ] 
    series: [
        string! binary! file! email! url! tag! issue! image! 
        block! paren! path! set-path! lit-path! hash! list!
    ] 
    number: [integer! decimal!] 
    switch/default either datatype? :value [to-word value] [:value] [
        any-type! [reduce anytype] 
        any-block! [reduce anyblock] 
        any-function! [reduce anyfunction] 
        any-string! [reduce anystring] 
        any-word! [reduce anyword] 
        series! [reduce series] 
        number! [reduce number]
    ] [
        switch/default type?/word :value [
            datatype! [reduce [value]] 
            block! [
                parse value: copy value [any [
                        datatype! | value: word! (
                            change value throw-on-error [to-datatype first value]
                        ) | value: block! (
                            value: change/part value to-typeset first value 1
                        ) :value | 
                        value: skip (
                            throw-error 'script 'invalid-arg reduce [first value]
                        )
                    ]] 
                head value
            ]
        ] [throw-error 'script 'invalid-arg reduce [:value]]
    ]
]