Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] REBOL Newbie tries to convert C source to REBOL (long posting) Part II

From: WisD00M::gmx::net at: 22-Nov-2003 5:18

Hi ! I've replied to all responses within one eMail - so if I didn't forget anybody, you should find my comments and answers to your mail below! First of all: thanks to everybody who offered support and provided useful feedback. I really appreciate all your efforts !! I didn't expect such a prompt response - and then so many replies ! On "altme", the chat client: I am certainly going to have a look into it ! Are many of you really using it ? A J Martin > I looked at the data above and noticed that it's not directly 'load-able A J Martin > with Rebol as these values "N012.11.029" will get turned into Rebol words. Well I didn't seem to have any problems loading the data - the specific needs to be addressed at a later time anyway - so insofar it's absolutely okay to initially have the data separated by whitespaces. A J Martin > So the next plan is to use 'parse. The basic application of 'parse, where A J Martin > whitespace is important is: A J Martin > parse/all data rules Indeed, I am already using parse - I've read some interesting stuff about it - on the REBOL.COM webpages, but also in other tutorials. When fooling around with parse I did have some problems though: I read it would be possible to provide parse with patterns to look for - so I tried something like: REBOL [ ] ;________________________________________ ;data is now a variable containing several lines of data i.e. ; -> datalinex HFD 111.11 N012.11.099 E034.31.114 foreach line data [ print parse line [rules] ;just to return whether the rules specified where matched or not ] ;________________________________________ However,using actual patterns didn't seem to work for me. Looking at the line of data provided in the comment above, I would want to check whether a line of data has the following form: any characters, one whitespace, 3 numbers, 1 dot, 2 numbers, 1 whitespace, 1 char N | S, 3 numbers,1 dot, 2 numbers, 1 dot, 3 numbers, 1 whitespace, 1 char E|W, 3 numbers,1 dot, 2 numbers, 1 dot, 3 numbers, 1 whitespace, So, trying to put that into REBOL's "words", I came up with the following attempt: ;-------------------------------------- REBOL [] line: "datalinex HFD 111.11 N012.11.099 E034.31.114"; example line digits: charset "0123456789"; all numbers that are allowed alpha: charset "abcdefghijklmnopqrstuvwxyz"; all characters that are allowed (not case specific) dot: #"."; a dot whitespace: #" "; a whitespace rule: [any alpha 1 whitespace 3 digits 1 dot 2 digits]; an abbreviated rule to match the first three elemnts of data print parse line [rule]; to check whether the line contains data in the format specified by rule ;-------------------------------------- However this doesn't seem to work the way I would want it to ... probably I am again making a stupid beginner's mistake A J Martin > Now to work out the rules that are needed. I can see that there are several A J Martin > sections in the line which seem to be terminated by newlines. So: A J Martin > rules: [ A J Martin > some section_rule A J Martin > end A J Martin > ] A J Martin > I can see that each section starts with a open square bracket, then there's A J Martin > a section name (which seems important) Well, the actual section name isn't really that important - indeed it is practically irrelevant, as the data in each line is supposed to get 'recognized' by its syntax - exactly like I tried to show a frew lines above: I intend to create several rules for all formats that are common - and when each section's offsets have been determined I want to run these rules against each section in order to determine whether rule1, rule2, or maybe rule11 is applicable is to the data stored in said section. A J Martin >followed by a closing square bracket, A J Martin > (perhaps optional whitespace?) and a newline. Yes, that's right: each section is determined by its name being enclosed in square brackets - with no other data on that line. A J Martin > After that, there's any number A J Martin > of data lines, which seem to form a table of values of various types, with A J Martin > perhaps a trailing empty line? This is also correct. regardin the code that you provided here as an example, it looks quite good - I will look through it and try to understand what exactly it is doing and WHY ;-) You mentioned a "pattern.r-file" written by you - is there any documenation available on the actual usage of your library file ? The 90° swapping idea looks also interesting - but I would probably rather base the conversion on a ruleset for recognition of data and then the actual conversion to a different format. That seems pretty logical to me - as most data in its basic form is unlike the syntax in each section identical. That way I could also put rules together that are intuitive: ;for example: rule_description: [any alpha] rule_coordinates: [N|S|W|E 3 digits 1 dot 2 digits] But as I said: my way of thinking doesn't seem to be right yet - cause that part isn't doing what it is supposed to do. The later conversion to CSV format shouldn't really require any external library as soon as I sorted the data in each line apart and have converted it to a format that is suitable. Just another example: While the positional data is currently stored in a format like "N034.12.331" I will need the last four bytes of the string ommitted/removed - so that I got: N034.12 Then remove the 2nd byte of the string (the 0)- then it looks like: N34.12 Then have the first byte of that string moved to the end the string so that I get: 34.12N A J Martin > I hope that helps! yes, for sure - thank you very much for your ideas and suggestions ! Tom Conlin > hopefuly this will get your mind moving slightly differently okay, thank you for the code - as well as putting comments behind it !! :-) I will have a look at it and try to incorporate the ideas into my script. Anton Rolls > What does the application do and why does it do it? The actual C application converts tables with GPS data from one format to another one. Besides the obvious GPS coordinates there is also some other information included in the file, that depending on the format might also be required to be parsed and converted to the other format (CSV). Now I want to port it to REBOL in order to enhance the functionality and ease of usability. Anton Rolls > What does the data describe? Like I said: each line contains at least longitude and latitude data (GPS) - then there are also abbreviations and numbers that might also be needed for final conversion. Anton Rolls > I've got all values as strings, but depending what they are you Anton Rolls > could use numbers, words and issues for easier handling later. strings are perfectly okay, I intend to check the validity of data with its parsing rules-so there's no need to manually check whether data is valid or not. Anton Rolls > I don't know - what do you want to do with the data? GPS coordinates and other data in a certain format need to be converted to a different format to be used with a different application. So bacially I'm having something like this in my datafile: ["dataline1" "111.11" "N012.11.029" "E034.31.110"] but my target format requires for example - field #1 to be at the 2nd position - field #2 to be at the 1st position - fields #3 & #4 to be converted to a format without miliseconds, without a leading 0 but with a trailing character (either N/S or W/E) In this example I would then need: ["111.11" "dataline1" "12.11N" "34.31E"] And as the actual data format varies with each section I just want to specify rules in order to recognize the way data is stored - and when a rule is recognized I want to apply according to that another rule for conversion. So in the above example my conversion rule would need to swap data elements with eachother, as well as splitting the GPS strings into directon, degrees,hrs,min,ms and re-align this data for a format acceptable for the other application. Anton Rolls > After finishing the extraction, you can get to the block of lines Anton Rolls > for each section like this: Anton Rolls > section1-data: select my-block "sec2" This looks indeed intuitive - so it seems with that method I wouldn't have to manually compute the offsets of each section ? - but rather store each section's name in a table ? Anton Rolls > I am assuming, for each section, that each line has the same number of Anton Rolls > elements. If not, then I recommend putting each line into a block of Anton Rolls > its own, so it looks like this: Yes, blocks seem to make sense to me, too - as each section can have a different amount of elementsl Anton Rolls > Did you do any Java? Not really Anton Rolls > "Everything is a pointer" is kind of more yes, I guess that's why I understood meanwhile - though the sytax is a bit complex, in assembler I simply consider everything a (D)WORD - so it doesn't seem to be much different with REBOL. But it's not really easy to get through the code - there are so many things to take into consideration. Sometimes I am really having trouble to decide whether to use literals or words - the evaluation seems also heavily to rely where one put brackets ... Anton Rolls > like rebol. Ask any questions here you want. We'll help you. thank you ! - I am already stunned by the enormous response my first posting received here !! Anton Rolls > This has often been wished for already. Anton Rolls > I think it's a bit of a waste of time at the moment. Anton Rolls > There are plenty of good text editors out there, and rebol syntax Anton Rolls > highlighting for them too. Sure, there are literally tens of thousands of editors out - also most of them with some basic syntax highlighting. But I thought more about an object oriented approach: an editor really supporting the programmer, and doing background parsing of the code that I write. One example: Having written some smaller View/VID test programs, I did always have to have half a dozen of browser windows with documentation in the background - just for reference! Simply, because I didn't knew for example what styles,faces and the like is supported. Unfortunately, the documentation about using actions & events with REBOL view isn't very good either - I was practically 'learning' by looking at example code from others. If instead the editor would be doing background parsing and watch me create an object or button it could really support me by displaying all possible options with that element. So when I created an object at the beginning of the file house: make object! [ door_open: false shutdoor: does [ door_open: false ] opendoor: does [ door_open: true ] ] and at a later time I clone this object by writing: greenhouse: make house [] the editor might support me by displaying the elements (variables, functions, classes) of that object and expected parameters for functions. This would be even more useful if it gets extended to the whole REBOL dialect - the editor could show in another window or maybe with popup menu the available elements in the current context. In the tutorial section on functions I read somewhere it would be possible to enclose a comment on the function's purpose within the function header - that very header might also be useful information that could get displayed. That way it could also show what styles are supported for a given type. Since it's dialect-based it should be pretty possible to read out sub-elements and display parameters and stuff like that. So you begin to open a DRAW section within a layout and voilá: REBOL shows what can be done. Seems to me like something REBOL is "born" to do ;-) Anton Rolls > There is - if you can read French it helps. Sorry, "mon ami": I don't understand any french ... thanks anyways ! P.S.: Does this list support attachments (ascii) ? Cause, actually I attached some code with my last mail but didn't see it on line (listview) - are the attachments extracted ? -- regards _________________ --------- Mike NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien... Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService Jetzt kostenlos anmelden unter +++ GMX - die erste Adresse für Mail, Message, More! +++