Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Created December 21, 2021 19:35
Show Gist options
  • Save dockimbel/3ebf48b58acdb3781c6e8f7adefe2959 to your computer and use it in GitHub Desktop.
Save dockimbel/3ebf48b58acdb3781c6e8f7adefe2959 to your computer and use it in GitHub Desktop.
Tracing handler for extracting top expressions
Red []
detect: function [
event [word!]
code [any-block! none!]
offset [integer!]
value [any-type!]
ref [any-type!]
frame [pair!]
][
range: []
stack: []
switch event [
set return exit fetch [
if find [set return] event [take/last stack]
if empty? stack [
if event = 'exit [append range offset]
either 1 >= length? range [append range offset][
if range/1 < range/2 [
code: head code
print ["expr:" mold copy/part at code range/1 + 1 range/2 - range/1]
]
remove range
]
]
]
open [append/only stack :value]
]
]
mark-expr: function [code][do/trace :code :detect]
mark-expr [print a: 1 b: 3 print either a > 2 [a + 3][a - 1]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment