[comp.lang.icon] parsing the backslash character

MYankowski@DOCKMASTER.NCSC.MIL (09/04/90)

I am trying to parse a string which is a DOS path name.  I cannot pull
out the directory separators ("\") because ICON recognizes them as an
escape sequence, if it is valid, or just returns the character that
follows the backslash.  Can anyone offer any sug- gestions.



Michael Yankowski Dockmaster.ARPA

nowlin@iwtqg.att.com (09/04/90)

> I am trying to parse a string which is a DOS path name.  I cannot pull
> out the directory separators ("\") because ICON recognizes them as an
> escape sequence, if it is valid, or just returns the character that
> follows the backslash.  Can anyone offer any sug- gestions.
> 
> Michael Yankowski Dockmaster.ARPA

A backslash is just another character if it's in a string you're
scanning.  The trick is specifying the backslash as the scanning
target.  Two backslashes is the way.  For example, if the your
program reads lines containing DOS pathnames to be scanned you
could pull off the directory segments of the paths and the command
names with this simple program:

procedure main()

	while line := read() do {

		line ? {
			dir := []
			while put(dir,tab(upto('\\'))) do tab(many('\\'))
			cmd := tab(0)
		}

		every writes(!dir,"\\")
		write(cmd)
	}
end

This program reconstructs the paths and writes them back out but
you could do anything with them at that point.

Jerry Nowlin
(...!att!iwtqg!nowlin)