World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
Janko 14-May-2009 [2181] | you mean parsing with charsets or the "normal" parsing? |
mhinson 14-May-2009 [2182x2] | normal I think |
Like it took me an hour to work out how to modify Steeve's example to only output the first occurance of the match. | |
Janko 14-May-2009 [2184x2] | aha, that is easier to learn .. I also don't the advanced parsing that oldes gave you example, and I wrote a couple of finished programs that used "normal" parsing as a main featurea |
start with easy examples and go forward from that | |
mhinson 14-May-2009 [2186x3] | Trouble is that the easy examples dont produce the results I need for processing my data :-( |
I have spent about 6 hours so far trying to convert this sort of format {random 2/2,2/4-6,2/33-37} to module: 2 port: [2 4 5 6 33 34 35 36 37] So far even with lots of help I have only managed to extract the module number & the ranges, but not the last one because there is no comma after it. | |
I suppose I could add a comma to the end of the string then I would be able to use it as a marker. | |
Janko 14-May-2009 [2189x2] | sometimes an easier solution is possible if you do it in more parse runs |
or if only comma is the problem slap it at the end and be done with it | |
Henrik 14-May-2009 [2191] | yes, for something like that, I would do some simple splitting to get the numbers isolated. |
Janko 14-May-2009 [2192] | ... from where do you parse 5 out... is that supose NUM-NUM suppose to be ranges? |
mhinson 14-May-2009 [2193] | so I will add a comma to the end, then parse data [any [ some digit #"/" copy result #"," (insert results result) | skip]] |
Janko 14-May-2009 [2194] | If it is I wouldn't call that a parse problem, ... remember you have to divide and conquer the problems , and that looks like a compound problem which parsing is not the big part of.. you just need regular "split" method |
mhinson 14-May-2009 [2195] | some are ranges & some are single ports |
Janko 14-May-2009 [2196] | what does 2 mean in 2/x-y ? |
mhinson 14-May-2009 [2197] | the 2 is a module number on a Cisco catos switch |
Janko 14-May-2009 [2198] | I qould 1) split on comma to get list of entities 2) for each entity if it's a single num append it to block, else split again and append whole range to the block |
mhinson 14-May-2009 [2199] | the port information is stored in a form like set port disable 2/2,2/4,2/6-8 set port disable 3/1-5,3/7 Then the same sort of thing for the names given to the ports. I want to extract it all into a standard format for analysis & comparison of IOS based information (done the IOS stuff ok) |
BrianH 14-May-2009 [2200] | a: [...] some-a-with-comma: [a any ["," a]] |
mhinson 14-May-2009 [2201] | CIsco operating systems are IOS or CATOS on switches and output formats are very different. |
Ladislav 14-May-2009 [2202] | mhinson: the above {copy result #","} does not look intended to me |
mhinson 14-May-2009 [2203] | ah, do I need a copy result to perhaps? |
Ladislav 14-May-2009 [2204x3] | if {copy result to ...} is what you want then I understand why you are having trouble with the END |
not-comma: complement charset "," copy result any [not-comma | skip] | |
sorry, just copy result not-comma | |
PeterWood 14-May-2009 [2207] | I think the advice to break the problem down and use more than one parse statement is good advice. Let's see how we can do that. I'll go through how I would approach the problem step by step. Sorry that I'll be squashing things on to one line but AltME paste doesn't work well on Mac. |
mhinson 14-May-2009 [2208] | :-) |
PeterWood 14-May-2009 [2209] | I usually try to take a few small steps rather than try to get the answer straight away. The test data: >> inp: {random 2/2,2/4-6,2/33-37} == "random 2/2,2/4-6,2/33-37" |
mhinson 14-May-2009 [2210] | random is sometimes a word & sometimes a number between 1 & 1000 |
PeterWood 14-May-2009 [2211x2] | We'll need to look for digits so : > digit: charset [#"0" - #"9"] == make bitset! #{ 000000000000FF03000000000000000000000000000000000000000000000000 } |
Does random ever have the sequence 2/number in it? | |
mhinson 14-May-2009 [2213x2] | no |
specific words (not many of them) on numeric alone | |
PeterWood 14-May-2009 [2215] | So what we need to look for are the patterns 2/number and 2/number-number. |
mhinson 14-May-2009 [2216x3] | on=or |
or 3/number...etc or 4/ or 12/ | |
but not on the same occasion | |
PeterWood 14-May-2009 [2219x2] | Let's start with 2/ and see how we get on >> parse/all inp [ any [copy range "2/" some digit (print range) | skip ]] 2/ 2/ 2/ |
So I've found all the sequences of 2/ but didn't capture the following digits. Can you see my mistake? | |
mhinson 14-May-2009 [2221] | I see why it has done that but I dont know how to extend the copy to the comma except with to #"," |
PeterWood 14-May-2009 [2222x2] | Let's change the parse rule so that I capture more than just the 2/: >> parse/all inp [ any [copy range ["2/" some digit] (print range) | skip ]] 2/2 2/4 2/33 == true |
You don't need to worry about the commas. skip will take care of them. | |
mhinson 14-May-2009 [2224] | so copy range has captured everything up to the point it no longer matches the expression in the [] a bit like a regular expression match. |
PeterWood 14-May-2009 [2225x2] | So now I'm capturing the first number after the 2/ but not the range. So let's add a little more to the parse rule to capture that: >> parse/all inp [ any [copy range ["2/" some [digit | "-"]] (print range) | skip ]] 2/2 2/4-6 2/33-37 == true |
Yes copy captures everything that it matches. | |
mhinson 14-May-2009 [2227] | a bit like copy thru? |
PeterWood 14-May-2009 [2228x2] | You only need to use thru when you can't specify exactly what you want to copy. |
I think of it this way: copy variable pattern-to-copy copy variable pattern-to-start-copying-from thru pattern-to-stop-copying-at | |
mhinson 14-May-2009 [2230] | So essential in cases where the middle bit is truly unpredictable |
older newer | first last |