I am trying to parse some introductory lines, but I am trying my best to see a solution. However, it should be a well-known template - this is just one that I don't come across often.
Background: I have a short list of string keywords ("HEAD", "GET", "POST", "PUT"), followed by additional string data. In any order there can be a multiple sequence ("KEYWORD blah blah blah KEYWORD blah blah blah"). There are no end characters or end keywords, because XML would have either a new keyword event or end of input. Example:
str: {HEAD stuff here GET more stuff here POST other stuff here GET even more stuff here PUT still more stuff here POST random stuff}
The result that I would like to achieve:
results: [
"HEAD" ["stuff here"]
"GET" ["more stuff here" "even more stuff here"]
"POST" ["other stuff here" "random stuff"]
"PUT" ["still more stuff here"]
]
My unsuccessful attempt:
results: ["head" [] "get" [] "post" [] "put" []]
rule1: ["HEAD" (r: "head") | "GET" (r: "get") | "POST" (r: "post") | "PUT" (r: "put")]
rule2: [to "HEAD" | to "GET" | to "POST" | to "PUT" | to end]
parse/all str [
some [
start: rule1 rule2 ending:
(offs: offset? start ending
append select results r trim copy/part start offs
) :ending
| skip]
]
, -2 - - "to" - ; , , - .
.