Skip to content

Commit

Permalink
FEAT: hides parse-trace dependencies in a local context.
Browse files Browse the repository at this point in the history
  • Loading branch information
dockimbel committed Jan 14, 2020
1 parent e4d17f8 commit 3f5a7fa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 45 deletions.
4 changes: 2 additions & 2 deletions boot.red
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Red [
#include %environment/routines.red
#include %environment/scalars.red
#include %environment/colors.red

#register-intrinsics
#include %environment/functions.red
#include %environment/system.red
#include %environment/operators.red

#register-intrinsics

#include %environment/codecs/png.red
#include %environment/codecs/jpeg.red
#include %environment/codecs/bmp.red
Expand Down
88 changes: 45 additions & 43 deletions environment/functions.red
Original file line number Diff line number Diff line change
Expand Up @@ -300,55 +300,57 @@ charset: func [
make bitset! spec
]

p-indent: make string! 30 ;@@ to be put in a local context

on-parse-event: func [
"Standard parse/trace callback used by PARSE-TRACE"
event [word!] "Trace events: push, pop, fetch, match, iterate, paren, end"
match? [logic!] "Result of last matching operation"
rule [block!] "Current rule at current position"
input [series!] "Input series at next position to match"
stack [block!] "Internal parse rules stack"
return: [logic!] "TRUE: continue parsing, FALSE: stop and exit parsing"
][
switch event [
push [
print [p-indent "-->"]
append p-indent " "
]
pop [
clear back back tail p-indent
print [p-indent "<--"]
]
fetch [
print [
p-indent "match:" mold/flat/part rule 50 newline
p-indent "input:" mold/flat/part input 50 p-indent
context [
p-indent: make string! 30

on-parse-event: func [
"Standard parse/trace callback used by PARSE-TRACE"
event [word!] "Trace events: push, pop, fetch, match, iterate, paren, end"
match? [logic!] "Result of last matching operation"
rule [block!] "Current rule at current position"
input [series!] "Input series at next position to match"
stack [block!] "Internal parse rules stack"
return: [logic!] "TRUE: continue parsing, FALSE: stop and exit parsing"
][
switch event [
push [
print [p-indent "-->"]
append p-indent " "
]
pop [
clear back back tail p-indent
print [p-indent "<--"]
]
fetch [
print [
p-indent "match:" mold/flat/part rule 50 newline
p-indent "input:" mold/flat/part input 50 p-indent
]
]
match [print [p-indent "==>" pick ["matched" "not matched"] match?]]
end [print ["return:" match?]]
]
match [print [p-indent "==>" pick ["matched" "not matched"] match?]]
end [print ["return:" match?]]
true
]
true
]

parse-trace: func [
"Wrapper for parse/trace using the default event processor"
input [series!]
rules [block!]
/case "Uses case-sensitive comparison"
/part "Limit to a length or position"
limit [integer!]
return: [logic! block!]
][
clear p-indent
either case [
parse/case/trace input rules :on-parse-event
set 'parse-trace func [
"Wrapper for parse/trace using the default event processor"
input [series!]
rules [block!]
/case "Uses case-sensitive comparison"
/part "Limit to a length or position"
limit [integer!]
return: [logic! block!]
][
either part [
parse/part/trace input rules limit :on-parse-event
clear p-indent
either case [
parse/case/trace input rules :on-parse-event
][
parse/trace input rules :on-parse-event
either part [
parse/part/trace input rules limit :on-parse-event
][
parse/trace input rules :on-parse-event
]
]
]
]
Expand Down

0 comments on commit 3f5a7fa

Please sign in to comment.