Instantly share code, notes, and snippets.

@rgchris /buckets.reb
Last active Aug 29, 2015

Embed
What would you like to do?
Fleshing out a model for a COLLECT/KEEP in Parse based on correctness.
Rebol [
Title: "Fleshing out a model for a COLLECT/KEEP in Parse based on correctness"
Date: 26-Apr-2015
Author: "Christopher Ross-Gill"
]
buckets: []
new-branch: quote (insert/only buckets bucket: copy [])
fold-branch: quote (bucket: buckets/2 append bucket take buckets)
kill-failed-branch: quote (remove buckets)
if probe parse [a b c][
new-branch
'a (append bucket 'a) ; keep 'a
[
new-branch
'b (append bucket 'b) ; keep 'b
'd (append bucket 'd) ; keep 'd
; successful end of rule
fold-branch
|
; rule failed, so
kill-failed-branch
new-branch
'b (append bucket 'b) ; keep 'b
'c (append bucket 'c) ; keep 'c
; successful end of rule
fold-branch
]
][
probe bucket
]
Rebol [
Title: "Fleshing out a model for a COLLECT/KEEP in Parse based on correctness"
Date: 26-Apr-2015
Author: "Christopher Ross-Gill"
]
buckets: []
if probe parse [a b c][
(insert/only buckets bucket: copy [])
'a (append bucket 'a) ; keep 'a
[
(insert/only buckets bucket: copy [])
'b (append bucket 'b) ; keep 'b
'd (append bucket 'd) ; keep 'd
; successful end of rule
(bucket: buckets/2 append bucket take buckets)
|
; rule failed, so
(remove buckets)
(insert/only buckets bucket: copy [])
'b (append bucket 'b) ; keep 'b
'c (append bucket 'c) ; keep 'c
; successful end of rule
(bucket: buckets/2 append bucket take buckets)
]
][
probe bucket
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment