Skip to content

Commit 3f45b9f

Browse files
committed
FEAT: updated prebol (Rebol Preprocessor) to be a real module working with current Rebol
1 parent 1db28af commit 3f45b9f

File tree

2 files changed

+32
-61
lines changed

2 files changed

+32
-61
lines changed

make/rebol3.nest

+3
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ include-mezz-colors: [mezz-lib-files: %mezz/mezz-colors.reb ]
459459
include-prot-whois: [mezz-prot-files: %mezz/prot-whois.reb ]
460460
include-prot-mysql: [mezz-prot-files: %mezz/prot-mysql.reb ]
461461

462+
include-prebol: [mezz-lib-files: %modules/prebol.reb ]
462463

463464
include-https: [
464465
mezz-lib-files: [
@@ -512,6 +513,8 @@ include-rebol-bulk: [
512513
:include-mezz-date
513514
:include-mezz-colors
514515

516+
:include-prebol
517+
515518
:include-prot-whois
516519
:include-prot-mysql
517520

src/modules/prebol.reb

+29-61
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
REBOL [
2-
Title: "Prebol - Official REBOL Preprocessor"
3-
Version: 1.1.3
2+
Name: prebol
3+
Type: module
4+
Exports: [process-source]
5+
Title: "Prebol - Official REBOL Preprocessor"
6+
Version: 1.1.4
47
Author: ["Carl Sassenrath" "Holger Kruse" "Oldes"]
58
Purpose: {
69
The official REBOL preprocessor. Combines multiple
@@ -49,63 +52,35 @@ REBOL [
4952
"Added #include-block command"
5053
"Includes are described in the result code using comment"
5154
]
52-
]
53-
Example: [
54-
"With requester" [
55-
set [in-file out-file] system/script/args
56-
57-
if view? [
58-
if none? in-file [
59-
in-file: request-file/title "Input file?" "Open"
60-
if none? in-file [quit]
61-
in-file: in-file/1
62-
]
63-
if none? out-file [
64-
out-file: request-file/title/save "Output file?" "Save"
65-
if none? out-file [quit]
66-
out-file: out-file/1
67-
]
68-
]
69-
70-
if not all [
71-
msg: "Missing input file name argument"
72-
in-file
73-
msg: "Input file not found"
74-
exists? in-file
75-
msg: "Missing output file name argument"
76-
out-file
77-
msg: "Input file is not a REBOL file"
78-
script? in-file
79-
msg: ["Cannot load REBOL input file" mold clean-path in-file]
80-
not error? try [data: load/all in-file]
81-
][
82-
error msg
83-
]
84-
85-
size: process-source data size? in-file
86-
save out-file head data
87-
print ["Processed:" size "bytes"]
55+
5-Mar-2021 "Oldes" [
56+
"Updated for use with current Rebol version"
8857
]
8958
]
9059
]
9160

9261
system/options/binary-base: 64 ; output data in base-64
9362

94-
;vn
95-
;error: func [msg] [print msg halt]
96-
error: func [[catch] msg] [throw make error! reform msg]
63+
error: func [msg] [
64+
if block? msg [msg: reform msg]
65+
sys/log/error 'prebol msg
66+
halt
67+
]
9768

98-
process-source-comment?: true ;adds comments before included content
69+
include-source-comment?: true ;adds comments before included content
9970
process-source: func [
10071
; Process REBOL source code block. Modifies the block. Returns size.
10172
blk [any-block!] "Block of source to process"
10273
size [integer!] "Starting size"
74+
/only "Don't use recursive processing"
10375
/local file data expr cmd else tmp path include-cmds header do-expr
10476
][
10577
do-expr: func [expr /local result] [
10678
; Evaluate expression and make sure it returns a result.
107-
if unset? set/any 'result do expr [
108-
print ["***" cmd "must return a value or none:" mold expr]
79+
set/any 'result try [do :expr]
80+
if function? :result [set/any 'result try [do :result]]
81+
case [
82+
unset? :result [ error [mold cmd "must return a value or none:" mold expr] ]
83+
error? :result [ error result ]
10984
]
11085
:result
11186
]
@@ -120,7 +95,7 @@ process-source: func [
12095
]
12196
header: make header data/2
12297
remove/part data 2
123-
if process-source-comment? [
98+
if include-source-comment? [
12499
insert data compose [
125100
comment (rejoin [{
126101
#### Include: } mold file {
@@ -150,11 +125,9 @@ comment (rejoin [{---- end of include } mold file { ----}])
150125
set/any 'data do file ;file is not a file but a block to evaluate!!!
151126
head insert/only copy [] data ; return it
152127
]
153-
154128
]
155129

156130
while [not tail? blk][
157-
158131
; Source pragmas begin with # (they are of the ISSUE datatype)
159132
; and are followed by a filename, a block, or a paren.
160133
either issue? blk/1 [
@@ -168,22 +141,19 @@ comment (rejoin [{---- end of include } mold file { ----}])
168141

169142
; Expression such as #include (join %file num: num + 1)
170143
if paren? :file [
171-
file: do-expr reduce [file] ; for older REBOL compatibility
144+
file: do-expr to block! :file
172145
]
173146

174147
; Include requires a file argument:
175-
if not file? file [error ["***Invalid" cmd "file expression:" mold file]]
148+
if not file? file [error ["Invalid" mold cmd "file expression:" mold file]]
176149

177150
; File must exist:
178-
if not exists? file [error ["***" cmd "file not found:" mold file]]
151+
if not exists? file [error [mold cmd "file not found:" mold file]]
179152

180153
size: size + size? file ; for stats only
181154

182155
; Execute the include:
183-
if error? data: try select include-cmds cmd [
184-
data: disarm :data
185-
error ["***" cmd file "error:" data/id "at" mold data/near]
186-
]
156+
if error? data: try select include-cmds cmd [ error data ]
187157
; Replace include command with contents of file:
188158
remove/part blk 2
189159
insert blk data
@@ -222,7 +192,7 @@ comment (rejoin [{---- end of include } mold file { ----}])
222192
insert/only blk tmp
223193
]
224194
#comments [ ; #comments true/false
225-
process-source-comment?: either find [false off] blk/2 [false][true]
195+
include-source-comment?: either find [false off] blk/2 [false][true]
226196
blk: skip blk 2
227197
]
228198
][
@@ -234,12 +204,10 @@ comment (rejoin [{---- end of include } mold file { ----}])
234204
blk: next blk
235205
]
236206
]
237-
238-
foreach item head blk [
239-
if block? :item [size: process-source item size]
207+
unless only [
208+
foreach item head blk [
209+
if block? :item [size: process-source item size]
210+
]
240211
]
241-
242212
size
243213
]
244-
245-

0 commit comments

Comments
 (0)