Last active
December 14, 2015 11:59
-
-
Save dockimbel/5083375 to your computer and use it in GitHub Desktop.
Show how to achieve R2 source rewriting suitable for evaluation using R3 interpreter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REBOL [ | |
Author: "Nenad Rakocevic" | |
Date: 04/03/2013 | |
Purpose: { | |
Show how to achieve R2 source rewriting suitable for evaluation | |
using R3 interpreter. | |
} | |
Note: "Use it from %Red/ folder" | |
] | |
context [ | |
do*: s: none | |
path-rewrite: [ | |
some [ | |
s: integer! (if negative? s/1 [s/1: s/1 + 1]) | |
;| handle other indexed-access cases here | |
| skip | |
] | |
] | |
patched-do: func [value /arg /local saved rule mark path file][ | |
unless file? :value [return do* value] | |
saved: system/script/path | |
set [path file] split-path :value | |
change-dir path | |
value: load file | |
parse value rule: [ | |
any [ | |
mark: [path! | set-path! | lit-path!] :mark into path-rewrite | |
;; | mark: string! :mark into string-rewrite | |
;; add more rewritting rules here | |
| mark: any-block! :mark into rule | |
| skip | |
] | |
] | |
also | |
do* value | |
system/script/path: saved | |
] | |
set 'do-r2 func [blk [block!]][ | |
do*: :do | |
set 'do :patched-do | |
do blk | |
set 'do :do* | |
] | |
] | |
do-r2 [ | |
do %red/compiler.r | |
] | |
save %red.new red ;-- inspect the file to see the changes | |
halt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment