World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
mhinson 14-May-2009 [2230] | So essential in cases where the middle bit is truly unpredictable |
PeterWood 14-May-2009 [2231x2] | Yes |
Now we can change the parse rule to work with 3/. 4 and /12: > parse/all inp [ any [copy range [["2/" | "3/" | "4/" | "12/"] some digit] (print range) | skip ]] 2/2 2/4 2/33 == true | |
mhinson 14-May-2009 [2233] | the 2/ part can be any number from 1 to 13 |
PeterWood 14-May-2009 [2234] | Do you want to capture all of them? |
mhinson 14-May-2009 [2235] | absolutely |
Ladislav 14-May-2009 [2236] | one-to-thirteen: ["1" digit | non-zero-digit] |
PeterWood 14-May-2009 [2237] | Then we can come up with a pattern for them: digit opt digit "/" |
mhinson 14-May-2009 [2238] | could we use 1 2 digit #"/" ? |
Ladislav 14-May-2009 [2239x2] | at-most-three: [#"0" - #"3"] non-zero-digit: [#"1" - #"9"] |
one-to-thirteen: ["1" at-most-three | non-zero-digit] | |
PeterWood 14-May-2009 [2241] | I'm presuming that the only possible values are 1 to 13. |
mhinson 14-May-2009 [2242] | they are, but there will never be a 0/ or 22/ that we want to avoid in this case |
PeterWood 14-May-2009 [2243x3] | Ladislav's will select values 1 to 13 from any numbers and so is more correct. |
This is the amended rule: >> parse/all inp [ any [copy range [[digit opt digit "/"] some digit] (print range) | skip ]] 2/2 2/4 2/33 == true | |
Oops I've lost the range again: >> parse/all inp [ any [copy range [[digit opt digit "/"] [some digit "-" some digit]] (print range) | skip ]] 2/4-6 2/33-37 == true | |
Steeve 14-May-2009 [2246] | To be more lecturable, perhaps you could deal with named sub-rules |
Ladislav 14-May-2009 [2247x2] | yes, we should describe the structure using named parts like: record: [random-part whitespace repeated-part any ["," repeated-part]] |
mhinson, does the structure I described correspond to what you need? | |
PeterWood 14-May-2009 [2249x3] | That's a good idea but I was being lazy partly because it's such a pain to copy and paste in AltME (it strips out all line endings). |
Here's the big rule now fixed : >> parse/all inp [ any [copy range [[digit opt digit "/"] [some digit opt ["-" some digit]]] (print range) | skip ]] 2/2 2/4-6 2/33-37 == true | |
Ladislav, that's my understanding | |
Steeve 14-May-2009 [2252] | rewrote Peter's with named sub-rules prefix: [digit opt digit] sufix: [some digit opt ["-" some digit]] target: [prefix #"/" sufix] parse/all inp [any [copy range target (print range) | skip]] |
PeterWood 14-May-2009 [2253] | Thanks, Steeve |
mhinson 14-May-2009 [2254] | sorry the phone rang |
PeterWood 14-May-2009 [2255] | So now we can capture all the ranges: >> all-ranges: copy [] == [] >> parse/all inp [any [copy range target (insert tail all-ranges range) | skip]] == true >> all-ranges == ["2/2" "2/4-6" "2/33-37"] |
Steeve 14-May-2009 [2256] | prefix can be: prefix: [1 2 digit] |
PeterWood 14-May-2009 [2257] | Once we've captured all-ranges, we can process them in a second step : |
mhinson 14-May-2009 [2258] | Ladislav, I am not sure I understand your terminology. record: [random-part whitespace repeated-part any ["," repeated-part]] random-part may be absent repeated-part is a number between 1 & 13 followed by "/" any is the bit we want and will be a number or a range , is not present at the end of the line repeated-part is the same as above, but will not be the last thing on the line. |
PeterWood 14-May-2009 [2259] | I need to go now but your in good hands. |
Ladislav 14-May-2009 [2260x3] | mhinson: OK, let's proceed further |
so you are saying, that random-part may be a-word a-number or absent. This is it: random-part: [a-word | a-number | none] | |
is this understood? | |
mhinson 14-May-2009 [2263x2] | Thanks for your help Peter. I am taking notes & understanding it I think. |
Yes, that sounds a good description of the random part. | |
Ladislav 14-May-2009 [2265x2] | fine, we need to describe further, what is a-word: a-word: [some alpha] , is this adequate? |
alpha: charset [#"a" - #"z" #"A" - #"Z"] | |
mhinson 14-May-2009 [2267] | yes |
Ladislav 14-May-2009 [2268] | fine, now for the a-number part. how big a number can it be? |
mhinson 14-May-2009 [2269] | 1 to 2000 will cover it |
Ladislav 14-May-2009 [2270] | a-number: [one-to-two 3 digit | non-zero-digit 0 2 digit] |
Steeve 14-May-2009 [2271] | hum.. a-number: [1 4 digit] is that not enough ? |
Ladislav 14-May-2009 [2272x2] | that allows for 0 |
as well as for 9999 | |
mhinson 14-May-2009 [2274] | that would be fine |
Ladislav 14-May-2009 [2275] | ok then, you pick what is appropriate |
Steeve 14-May-2009 [2276x2] | yep but it's an average limit that mhinson gave |
no need to be strict here, i think | |
Ladislav 14-May-2009 [2278x2] | repeated-part will not be the last thing on the line : fine, what will be the last thing on the line? |
(except for the newline character, of course) | |
older newer | first last |