home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.tcl
- Path: sparky!uunet!caen!sol.ctr.columbia.edu!src.honeywell.com!mail-enters-news
- From: jkimball@src.honeywell.com (John Kimball)
- Subject: evalling a string
- To: comp.lang.tcl
- Message-ID: <9211171516.AA26302@valiant.src.honeywell.com>
- Posted-Date: Tue, 17 Nov 92 09: 16:05 CST
- Sender: jkimball@src.honeywell.com (John Kimball)
- Organization: Honeywell Systems & Research Center
- Date: Tue, 17 Nov 1992 15:16:05 GMT
- Received-Date: Tue, 17 Nov 92 09: 16:06 CST
- Lines: 34
-
- Seems to me this should be easy, but I'm having trouble thinking of a good
- way to do it.
-
- I have a string of substrings. The substrings may be enclosed in
- double-quotes, or they may be enclosed in curly braces. The substrings may
- have embedded variable references, maybe even embedded bracketed commands.
-
- For instance,
- stuff-stuff "press here" -aardvarks "foo -x $a"
- or
- stuff-stuff "press here" -aardvarks {foo -x $a}
-
- I want to preprocess the string "according to the normal Tcl rules" -- the
- variable references which are not protected by curly braces should be
- replaced by their values; similarly, the bracketed commands which aren't
- protected should be evaluated and replaced by their results. So in the
- first example, $a should be replaced by its value, but in the second it
- should be left alone.
-
- I can't simply eval the string, because eval wants stuff-stuff to be a
- command name. If I use lindex to tease apart the top-level chunks, I lose
- the information about which chunks were wrapped in double quotes and which
- ones were wrapped in curly braces. As a workaround, I can define a proc
- stuff-stuff, but that seems unusually perverse.
-
- What am I missing?
-
- John Kimball
-
- DOMAIN: jkimball@src.honeywell.com Honeywell Systems and Research Center
- postmaster@src.honeywell.com Computer Sciences/Software Technology
- UUCP: <any-smart-host>!srcsip!jkimball 3660 Technology Drive, MN65-2100
- VOICE: +1 612/951-7343 FAX: 7438 Minneapolis, MN 55418-1006
- STATUS: "Will do research for food."
-