[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,
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]>
Subject: [REBOL] another parsing problem: converting dos filenames to
Could someone please fix this? It hung my interpreter:
Title: "DOS-REBOL File Name Conversion Routines"
Author: "Terrence Brannon"
Purpose: "Ease working with dos filename in REBOL programs"
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
parse/all dos-fn [ any rules ]
>> dosbol/d2r "c:\temp\file"
terrence-brannon: [[princepawn--yahoo--com] perl-refugee myth-gamer]
; all the above is real REBOL code, believe it or not.