Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Last active December 14, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dockimbel/5083375 to your computer and use it in GitHub Desktop.
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.
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