01: /*
02: * TestParserCmd.java --
03: *
04: * This procedure implements the "testparser" command. It is
05: * used for testing Parser.parseCommand.
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: TestParserCmd.java,v 1.2 2005/10/29 00:27:43 mdejong Exp $
13: */
14:
15: package tcl.lang;
16:
17: public class TestParserCmd implements Command {
18:
19: /*
20: *----------------------------------------------------------------------
21: *
22: * cmdProc --
23: *
24: * |>description<|
25: *
26: * Results:
27: * None.
28: *
29: * Side effects:
30: * None.
31: *
32: *----------------------------------------------------------------------
33: */
34:
35: public void cmdProc(Interp interp, // Current interpreter.
36: TclObject[] objv) // The argument objects.
37: throws TclException {
38: String string, fileName;
39: int lineNumber, length;
40: TclParse parse = null;
41: CharPointer script;
42:
43: if (objv.length != 3) {
44: throw new TclNumArgsException(interp, 1, objv,
45: "script length");
46: }
47:
48: string = objv[1].toString();
49: length = TclInteger.get(interp, objv[2]);
50: if (length == 0) {
51: length = string.length();
52: }
53: script = new CharPointer(string);
54: fileName = "";
55: lineNumber = -1;
56:
57: parse = Parser.parseCommand(interp, script.array, script.index,
58: length, fileName, lineNumber, false);
59:
60: if (parse.result != TCL.OK) {
61: interp.addErrorInfo("\n (remainder of script: \"");
62: interp
63: .addErrorInfo(new String(parse.string,
64: parse.termIndex,
65: (parse.endIndex - parse.termIndex)));
66: interp.addErrorInfo("\")");
67: throw new TclException(TCL.ERROR);
68: }
69:
70: // The parse completed successfully. Just print out the contents
71: // of the parse structure into the interpreter's result.
72:
73: parse.endIndex = string.length();
74: interp.setResult(parse.get());
75: return;
76: }
77: }
|