World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
Maxim 14-May-2009 [2349] | even if it's similar in intent. |
mhinson 14-May-2009 [2350] | my first any needs to be inside the [ ... that would seem to mike it apply to the "a" |
Maxim 14-May-2009 [2351x3] | >> parse "aaa" [any [[here: "a" (print here)] | [skip] ]] aaa aa a == true |
>> parse "zaz" [any [[here: "a" (print here)] | [skip] ]] az == true | |
>> parse "zzz" [any [[here: "a" (print here)] | [skip] ]] == true | |
mhinson 14-May-2009 [2354] | that seems logica, but this does not parse {aaa} [any[here: "a" (print here)] | [skip] ] aaa aa a |
Maxim 14-May-2009 [2355] | note that the rule returns true everytime. it did not fail. |
mhinson 14-May-2009 [2356] | why does it skip in my example? |
Maxim 14-May-2009 [2357] | it doesn't... each time it hits "a" the first rule matches. |
mhinson 14-May-2009 [2358] | which moves the Parse pointer on |
Maxim 14-May-2009 [2359x2] | in your example, you have two rules, the any only applies to the first rule. the | skip basically will never be used, cause any will never fail. |
any will repeat until it doesn't match, but it still doesn't fail. | |
mhinson 14-May-2009 [2361] | & if i use data of zzz it returns false... I see why now, I think this is key to why I have been so frustrated with getting these rules to work. |
Maxim 14-May-2009 [2362] | now be carefull... the parse function returns false IF it didn't match all of the input string. |
mhinson 14-May-2009 [2363] | oh, no I dont, not if any makes it always return true |
Maxim 14-May-2009 [2364x2] | so the any actually didn't fail, and thus the skip never go to do its stuff. |
other examples. >> parse "aza" [any [here: "a" (print here)] | skip] aza == false >> parse "aza" [any [here: "a" (print here)] skip skip] aza == true | |
mhinson 14-May-2009 [2366x3] | so why did the parse return false? >> parse {zzz} [any[here: "a" (print here)] | [skip] ] == false |
is it because the skip never get called so the parse is stuck on the first position or match & parse needs to move to the tail to return true? | |
I need to dream about this EVERY night. | |
Maxim 14-May-2009 [2369x2] | yep. it hit the "z" stopped (but didn't "fail") so the skip isn't reached. |
the second example, both skip ARE evaluated, thus it returns true. | |
mhinson 14-May-2009 [2371] | Maxim, you are a very patient teacher. |
Maxim 14-May-2009 [2372x2] | :-) I missed such a big feature of rebol for sooo long, just because I didn't get these nuances. and its hard to make a tutorial out of this, cause it sooooo boring, and you don't realize why its so important until you really start to use parse. |
btw, I keep logging off, cause the winds are wreaking havoc on the electricity lines! there is probably a loose connector on some junction and my whole house has rebooted at least 15 times in the last 2 hours :-/ | |
mhinson 14-May-2009 [2374x2] | I agree, it needs to be interactively taught. I know I will still get it wrong, but I fee more confident to analyse what is going wrong now. |
wow, are you still in the winter? Are you in Canada? | |
Maxim 14-May-2009 [2376] | all of northern usa should be affected the same way, it snowed yesterday in central canada! yet we are already at temperatures of 65-70 on average... its just clash of northern and southern winds... creating a massive disruption here. |
mhinson 15-May-2009 [2377] | Hi, I am after some advice on creating a data structure please. I read data from my file in this sort of order. disabled 2/34 2/35 vlan 3 2/35 2/48 vlan 5 2/3 2/24 name 2/1 name one 2/35 second name Then I want to export it in this sort of format. port <tab> disabled <tab> vlan <tab> name 2/1 name one 2/3 5 2/24 disabled 2/34 5 2/35 disabled 3 second name 2/48 3 I am hoping that I can create a structure that mimics the data its self. maybe like data/2/35/disabled = "disabled" data/2/35/vlan = "3" data/2/35/name = "second name" Then some how use the input data to define what part of the structure the item is recorded in. Once I have it in a structure like this I am expecting it to be simple to enumerate each part to do my export. |
Geomol 15-May-2009 [2378x3] | Use blocks. >> data: [[] [[vlan 3]]] == [[] [[vlan 3]]] >> data/2/1/vlan == 3 |
And then probably PARSE should be used to scan the input and put values in the data block structure (maybe building the structure along the way, if it's known beforehand). | |
if it's *not* known beforehand | |
mhinson 15-May-2009 [2381] | That looks exactly the structure I had in mind, but how do I get the data into the right part of the structure? if I have data of 3 2/1 & I know it refers to a vlan. I will have up to about 1500 of these for each file |
Geomol 15-May-2009 [2382] | If there can only be two indexs into the data, you setup those indexs, when you scan input. Something like (pseudo code): vlan: 3 idx1: 2 idx2: 1 data/:idx1/:idx2/vlan: vlan If you don't have the full data structure before you start, you might have to check like: if idx1 > length? data [ ... create the required blocks inside data ...] if idx2 > length? data/:idx1 [ ... create the required blocks inside data/:idx1 ...] |
mhinson 15-May-2009 [2383x2] | That would mean I read the input repeatedly (up to about 400 times) for each input wouldnt it? |
sorry, secont part of your message answers that option | |
Geomol 15-May-2009 [2385x2] | :-) |
You can also do it without using PARSE, if that's too much to start with. Read the input as lines with READ/LINES A line could then be: line: "vlan 3" And you can pick the parts with something like: >> copy/part line find line " " == "vlan" >> next find line " " == "3" Using PARSE is the elegant way to do it, but can be a bit tricky, until you've used it a few times. | |
Pekr 15-May-2009 [2387] | or use parse line " ", which will return block of "words" |
mhinson 15-May-2009 [2388x2] | In fact I do know the index structure, so your first example is exactly what I need. :-) How do I get the data back out of this structure please? I dont understand all the colons in it. |
The input data is the result of a lot of parsing. | |
Geomol 15-May-2009 [2390x2] | If you use integers and words as your indexâÊyou don't have colon, like in: data/2/35/vlan If you have a variable with the index, you need the colon to get the value of the variable, else REBOL will see it as a word, like in: idx1: 2 idx2: 35 data/:idx1/:idx2/vlan |
If you write data/idx1/idx2/vlan REBOL will look for the word idx1 in data, and it's not there. | |
mhinson 15-May-2009 [2392] | I can't get it to work. >> data/1/2/vlan: 3 ** Script Error: Cannot use path on none! value ** Near: data/1/2/vlan: 3 |
Geomol 15-May-2009 [2393x2] | Has you defined data? |
Have | |
mhinson 15-May-2009 [2395x2] | I dont know how to |
I have tried data: [] | |
Geomol 15-May-2009 [2397] | data: [ [ [] [vlan 0] ] ] Your data has nothing in it. To be able to write data/1/2/vlan: 3 you need to have at least one entry in data, and inside that two entries and inside that the word vlan and a value. |
mhinson 15-May-2009 [2398] | so I need to define all possiable parts of the structure before I use it. |
older newer | first last |