00001
00002
00003
00004
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
00026
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
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 }