home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / tcl / 1849 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.0 KB  |  48 lines

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