01: /*
02: * TestParsevarnameCmd.java --
03: *
04: * This procedure implements the "testparsevarname" command. It is
05: * used for testing Parser.parseVarName.
06: *
07: * Copyright (c) 1997 by Sun Microsystems, Inc.
08: *
09: * See the file "license.terms" for information on usage and redistribution
10: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11: *
12: * RCS: @(#) $Id: TestParsevarnameCmd.java,v 1.2 2005/10/29 00:27:43 mdejong Exp $
13: */
14:
15: package tcl.lang;
16:
17: public class TestParsevarnameCmd implements Command {
18:
19: public void cmdProc(Interp interp, // Current interpreter.
20: TclObject[] objv) // The argument objects.
21: throws TclException {
22: String string;
23: int length;
24: boolean append;
25: TclParse parse = null;
26: CharPointer script;
27:
28: if (objv.length != 4) {
29: throw new TclNumArgsException(interp, 1, objv,
30: "script length append");
31: }
32: string = objv[1].toString();
33: length = TclInteger.get(interp, objv[2]);
34: if (length == 0) {
35: length = string.length();
36: }
37: append = TclBoolean.get(interp, objv[3]);
38: script = new CharPointer(string);
39: parse = Parser.parseVarName(interp, script.array, script.index,
40: length, parse, append);
41:
42: if (parse.result != TCL.OK) {
43: interp.addErrorInfo("\n (remainder of script: \"");
44: interp.addErrorInfo(new String(parse.string,
45: parse.termIndex,
46: (string.length() - parse.termIndex)));
47: interp.addErrorInfo("\")");
48: throw new TclException(TCL.ERROR);
49: }
50:
51: // The parse completed successfully. Just print out the contents
52: // of the parse structure into the interpreter's result.
53:
54: parse.commentSize = 0;
55: parse.commandStart = script.index + parse.tokenList[0].size;
56: parse.commandSize = 0;
57: try {
58: TclObject tlist = TclList.newInstance();
59: TestExprParserCmd.PrintParse(interp, parse, tlist);
60: interp.setResult(tlist);
61: } finally {
62: parse.release();
63: }
64: return;
65: }
66: } // end TestParsevarnameCmd
|