World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Steeve 27-Jun-2007 [2022x2] | unique works for the rules which use simple constants, but i said it, i use more complex rules |
parse data [all [rule1 | rule2 | rule3 | rule4]] all rules must apply 1 time and 1 time only in any order, don't focus on what is inside rules (it contains sub-rules which contains sub-rules). | |
btiffin 27-Jun-2007 [2024] | Ok, this is convulted and probably wrong rule: [copy res subrule (remove/part find subrule compse [| (res)] 2)] subrule: ["filler" | "a" | "b" | "c"] parse "fillerabc" [4 [rule] end] Remove the alternatives from the rule as you find them...the filler is to allow | "a" to be found. |
Steeve 27-Jun-2007 [2025] | argh, this is uggly :-) not better than my current solution using counters |
btiffin 27-Jun-2007 [2026x2] | Yep...convoluted and hard to verify all the cases to boot. :) I wouldn't use it to be honest, but it was teasing my brain too much... |
Now, I'll slowly back out of the room...ducking and dodging... :) | |
Steeve 27-Jun-2007 [2028x2] | take a whisky on the rocks |
i got a beer | |
Brock 27-Jun-2007 [2030x3] | This has it... r1: "A" r2: "B" r3: "C" rule: [opt [r1 r2 r3]] parse "ABC" [[rule] [rule] [rule]] |
opt = match zero or one time | |
don't ask me to explain it, but it seems to meet your sample requirements | |
Steeve 27-Jun-2007 [2033] | have you tested ? doesn't work at all for many cases |
Brock 27-Jun-2007 [2034x3] | >> parse "BC" [[rule] [rule] [rule]] == false |
>> parse "ABC" [[rule] [rule] [rule]] == true | |
>> parse "BBC" [[rule] [rule] [rule]] == false | |
Steeve 27-Jun-2007 [2037x2] | parse "CBA" = false |
in any order, i said | |
Brock 27-Jun-2007 [2039] | damn, doesn't handle the varying order of elements |
Steeve 27-Jun-2007 [2040] | :-) |
btiffin 27-Jun-2007 [2041] | Yeah, this problem needs to allow alternatives and then remove them (or Steeve's counter) |
Steeve 27-Jun-2007 [2042x5] | agree |
but i'ts not very elegant | |
and i have such rules like this | |
sniff | |
so i have to build a pre-parser to transform rules in an elegant maner | |
btiffin 27-Jun-2007 [2047] | I'm still slowly backing out of the room...but I would not be completely surprised if another rebol gives you a "tada" solution...but I'd bet less money now. :) |
Steeve 27-Jun-2007 [2048] | hihi |
Brock 27-Jun-2007 [2049] | well, I'm stumped. Tried many variations on the theme and couldn't get any to work. Good luck. |
Chris 28-Jun-2007 [2050] | Basically you're asking for [all ["A" | "B" | "C"]] --> ABC = true BAC = true BBC = false ABCB = false |
btiffin 28-Jun-2007 [2051] | I think Steeve just left...but yep he wants a once and once only in any order |
Steeve 28-Jun-2007 [2052x3] | i'm here |
yeah Chris you got the thing | |
assuming "A" "B" and "C" could be more complex rules | |
Chris 28-Jun-2007 [2055] | You may want to check Gabriele's 'compile rules' to see if this has been solved. I have another solution, but needs hashed out a little. |
Steeve 28-Jun-2007 [2056] | i know how to build a complex solution but i would prefer a new word in the dialect , if other peoples think it's a good improvment |
Chris 28-Jun-2007 [2057] | I think so -- it's a common enough pattern... |
Gabriele 28-Jun-2007 [2058x3] | .333 |
sorry, cat on keyboard :) | |
unfortunately the cat did not type a useful parse rule. | |
Steeve 28-Jun-2007 [2061] | huhu |
Chris 28-Jun-2007 [2062] | I thought the zen answer was imminent... |
Gabriele 28-Jun-2007 [2063x3] | steve - not sure this should be a new dialect word, since it is a very specific case. basically you want all permutations of a set of rules. |
the simplest way may be to just generate all the permutations. | |
that is, parse string [a b c | a c b | c a b | c b a | b c a | b a c] | |
Steeve 28-Jun-2007 [2066] | i give another one example: imagine you have a dialect which describes a rectangle with coordinates length and color. You could write [rectangle 10x20 300 red] but [rectangle 30 red 10x20] should be correct too (and other combinations). So a parser should handle this with not too much complication. |
Gabriele 28-Jun-2007 [2067x2] | that can also be written as: parse string [a [b c | c b] | b [c a | a c] | c [b a | a b]] (faster) |
steve, we do that all the time, and we just take the last value when it is put more than once. | |
Chris 28-Jun-2007 [2069] | Steeve: In that situation, you have a little discretion to ignore excess attributes, as VID does. |
Steeve 28-Jun-2007 [2070] | but what if i have 10 rules to complete ? |
Gabriele 28-Jun-2007 [2071] | that is, two pairs is not an error, the parser just ignores one. if vid errored out it would be worse. |
older newer | first last |