Skip to content

Instantly share code, notes, and snippets.

@rgchris
Last active August 29, 2015 14:20
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 rgchris/4159dd40eb2eda76e2ae to your computer and use it in GitHub Desktop.
Save rgchris/4159dd40eb2eda76e2ae to your computer and use it in GitHub Desktop.
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