Last active
March 20, 2025 23:37
-
-
Save GiuseppeChillemi/191e55404f76c24ffeb48beb4a8587f3 to your computer and use it in GitHub Desktop.
Delimits elements to be used with parse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Title: "Delimit elements" | |
Description: "Delimit and quotes elements for parse" | |
Version: 1.1 | |
] | |
delimit-elements: func [ | |
"Delimits and quotes a block of elements to be used with parse" | |
block [block!] | |
/local | |
datatypes-rule | |
parse-dsl-rule | |
rule | |
] [ | |
datatypes-rule: [ | |
set rule word! | |
[ | |
if (datatype? get/any rule) | |
| if (typeset? get/any rule) | |
] | |
] | |
parse-dsl-rule: [ | |
set-word! | |
| get-word! | |
| word! | |
| integer! | |
| paren! | |
| block! | |
;--- We need to quote it, as it is forbiden | |
| path! | |
] | |
parse block [ | |
any [ | |
change set rule datatypes-rule (reduce [rule '|]) | |
| change set rule parse-dsl-rule (reduce ['quote rule '|]) | |
| change set rule any-type! (reduce [rule '|]) | |
] | |
] | |
if not empty? head block [remove at tail block -1] | |
block | |
] | |
comment [ | |
probe delimit-elements [a 'b c: x/y/z (aa) [bb] :d 1 2 3 4 integer! none fail path!] | |
;[quote a | 'b | quote c: | quote x/y/z | quote (aa) | quote [bb] | quote :d | quote 1 | quote 2 | quote 3 | quote 4 | integer! | quote none | quote fail | path!] | |
probe delimit-elements [integer! path!] | |
;[integer! | path!] | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. I have added
/any
later, but not removeattempt