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

[REBOL] another parsing problem: converting dos filenames to rebol Re:

From: jelinem1:nationwide at: 15-Sep-2000 13:18

I know you're probably trying to learn parse by writing a hands-on example, but converting a MSDOS filename to REBOL format is not that tricky: dosbol: func [ dos-fn [string!] "takes a dos filename and converts to rebol format" ][ replace/all dos-fn "\\" "/" replace/all dos-fn "\" "/" replace/all dos-fn ":" "" return join "/" dos-fn ] This will take care of alot of cases which the program below doesn't apparently handle. A few comments about the program below is that you need to specify 'to or 'thru preceeding any literal you want 'parse to match, eg: copy char drive-letter to ":" Also, I don't know what the 'char is doing (above), and of course I think you meant 'drive-letter to be 'dl due the the statement following it. I'm guessing that the reason why this loops infinitely is that you are not moving the 'parse cursor with 'to or 'thru. - Michael Jelinek [princepawn--MailAndNews--com]@MailAndNews.com> on 09/15/2000 11:49:09 AM From: [princepawn--MailAndNews--com]@MailAndNews.com on 09/15/2000 11:49 AM Please respond to [list--rebol--com] Sent by: Terrence Brannon <[princepawn--MailAndNews--com]> To: [list--rebol--com] cc: Subject: [REBOL] another parsing problem: converting dos filenames to rebol Could someone please fix this? It hung my interpreter: REBOL [ Title: "DOS-REBOL File Name Conversion Routines" File: %dosbol.r Author: "Terrence Brannon" Email: [princepawn--yahoo--com] Purpose: "Ease working with dos filename in REBOL programs" Category: 'file ] dosbol: make object! [ char: make string! 0 out: make string! 0 drive-letter: charset [ #"A" - #"F" ] rules: [ copy char drive-letter ":" (out: rejoin [ "/" dl ]) | "\" (append out "/") | copy char (append out char) ] d2r: func [ dos-fn [string!] "takes a dos filename and converts to rebol format"] [ parse/all dos-fn [ any rules ] out ] ]
>> dosbol/d2r "c:\temp\file"
terrence-brannon: [[princepawn--yahoo--com] perl-refugee myth-gamer] free-email: http://www.MailAndNews.com free-usenet: http://www.mailAndNews.com ; all the above is real REBOL code, believe it or not.