01: /*
02: * TclParserExtension.java
03: *
04: * Load parser package commands
05: *
06: * Copyright (c) 2005 Mo DeJong
07: *
08: * See the file "license.terms" for information on usage and
09: * redistribution of this file, and for a DISCLAIMER OF ALL
10: * WARRANTIES.
11: *
12: * RCS: @(#) $Id: TclParserExtension.java,v 1.2 2005/10/20 18:54:23 mdejong Exp $
13: *
14: */
15:
16: package tcl.lang;
17:
18: public class TclParserExtension extends Extension implements Command {
19:
20: // name and version of this package
21:
22: static String packageName = "parser";
23: static String packageVersion = "1.4";
24:
25: /*
26: * Called via [java::load tcl.lang.TclParserExtension]
27: * or from the jaclloadparser command implemented below.
28: */
29:
30: public void init(Interp interp) throws TclException {
31: interp.createCommand("parse", new TclParser());
32: interp.pkgProvide(packageName, packageVersion);
33: }
34:
35: /*
36: * Invoked when loaded into a safe interp.
37: */
38:
39: public void safeInit(Interp safeInterp) throws TclException {
40: this .init(safeInterp);
41: }
42:
43: /*
44: * Invoked when [package require parser] is run from Tcl.
45: * This method is needed so that parser can be loaded
46: * without having first loaded the Java package.
47: */
48:
49: public void cmdProc(Interp interp, // Current interpreter.
50: TclObject[] objv) // Arguments to "jaclloadparser" command.
51: throws TclException {
52: // This method takes no arguments
53: if (objv.length != 1) {
54: throw new TclNumArgsException(interp, 1, objv, "");
55: }
56:
57: this .init(interp);
58:
59: interp.deleteCommand(objv[0].toString());
60: }
61: }
|