# $Header: /home/cvsroot/tcldb/ucodb/Tlib/findExpr,v 1.1.1.1 1996/10/12 01:08:25 de Exp $
# tcl procs saved on Sun Sep 03 16:19:07 PDT 1995

proc findExpr {ind line} {

#	Note:  arg line must have been Tokenized!
#	returns 2 inds to use in an lrange expression

#	we know where we think the expression begins, but it might be a
#	a multi-word delimited expression:  we will lose all BSL QQ 
#	and LCB that begin it, but save any [] or () delimited strings

	set junk "BSL LCB RCB QQ"
	set odelim "LSB LPA"
	set cdelim "RSB RPA"

#	strip out all extraneous chars
	foreach j $junk {
		regsub -all "$j" $line "" line
	}

#	kill leading spaces
	set line [string trimleft $line]

#	Now get the word we think is the expr
	set temp [lindex $line $ind]

#	if the word contains a known open delim, then find the index of the
#	word containing the close delim matching it  (making an assumption
#	here that there are not nested delims of same type in the expr!)

	foreach o $odelim {
		set of [string first $o $temp]
		if {$of	>= 0} {
			break
		}
	}

	set c [lindex $cdelim [lsearch $odelim $o]]
	set cloc [string first $c $line]

	if {$cloc >= 0} {
		set cend [expr {$cloc + 2}]
		set sub [crange $line 0 $cend]
		set slen [llength $sub]
		return "[lrange $line $ind [expr {$ind + $slen - 1}]]"
	} else {
		return "[lrange $line $ind $ind]"
	}

}

