# blend.pdx --
#
#	This file implements the TclPro Debugger extension for the
#	TclBlend extension.
#
# Copyright (c) 1998-2000 Ajuba Solutions
# All rights reserved.
# 
# RCS: @(#) $Id: uplevel.pdx,v 1.3 2003/03/31 23:01:22 vincentdarley Exp $

# Register the TclBlend extension

instrument::addExtension 2.0 {parseUplevel}

namespace eval parseUplevel {
}

# Register handlers for each of the TclBlend commands

instrument::addCommand uplevel \
	{parseSimpleArgs 1 -1 parseUplevel::parseUplevelCmd}

# parseUplevel::parseUplevelCmd --
#
#	This routine wraps the foobar command.
#	Parse args of the pattern:
#		?catch exception_pair script ... ? ?finally script?
#
# Arguments:
#	tokens		The list of word tokens for the current command.
#	index		The index of the next word to be parsed.
#
# Results:
#	Returns the index of the last token + 1 (all have been parsed).

proc parseUplevel::parseUplevelCmd {tokens index} {
    set argc [expr {[llength $tokens] - $index}]

    if {$argc == 1} {
	return [instrument::parseSimpleArgs 1 1 {parseBody} $tokens $index]
    } elseif {$argc == 2} {
	instrument::getLiteral [lindex $tokens $index] literal
	if {[regexp {^\#?[0-9]+$} $literal]} {
	    # If there's a literal level arg, call parseWord on it.

	    return [instrument::parseSimpleArgs 2 2 {parseWord parseBody} \
		    $tokens $index]
	}
    }
    return [instrument::parseSimpleArgs 1 -1 {parseWord} $tokens $index]
}
