Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

JythonInterpreter.java

00001 /*
00002  * JythonInterpreter.java
00003  *
00004  * Created on 13 August 2003, 15:11
00005  */
00006 
00007 package GuiComponents.scripting;
00008 import org.apache.bsf.*;
00009 import GuiComponents.Console.*;
00010 
00015 public class JythonInterpreter extends DefaultInterpreter {
00016     private int lastLevel = 0;
00017         
00018     public JythonInterpreter(JConsole console, BSFEngine engine, NameCompleter name) {
00019         super(console, engine, name);
00020         lineContinueChar = '\\';
00021         blockStartChar = ':';
00022         
00023     }
00024     
00025     /*Different algorithm for Python - count the number of tab characters and
00026      *see if it is less than the number of indents
00027      */
00028     protected boolean endBlock(String line) {        
00029         if (indentLevel(line) < nestLevel()) return true;
00030         else return false;
00031     }
00032     
00035     private int indentLevel(String line) {
00036         lastLevel = 0;
00037         while (line.charAt(lastLevel) == '\t') ++lastLevel;        
00038         return lastLevel;
00039     }
00040     
00041     protected void decIndent() {         
00042         int nTimes = nestLevel() - lastLevel;
00043         System.out.println(nTimes);
00044         while (nTimes-- > 0) {
00045             super.decIndent();
00046         }
00047     }
00048     
00049     /* Try twice - once with eval and once with exec
00050      */
00051     public void exec(String s, String source, int row, int column) {
00052         try {            
00053             Object retVal = engine.eval(source, row, column, s);                        
00054             if (printObject(retVal))
00055                 console.println(retVal.toString());
00056         } catch (BSFException be1) {
00057             try {
00058                 engine.exec(source, row, column, s);
00059             } catch (BSFException be) {
00060                 console.println(be.toString());                
00061                 be.printStackTrace();
00062             }
00063         }     
00064     }
00065 }

Generated on Thu Jul 15 09:55:45 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5