comparison src/luan/tools/CmdLine.java @ 104:754e6030c029

remove parboiled and rewrite parser; add jline; git-svn-id: https://luan-java.googlecode.com/svn/trunk@105 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 12 May 2014 05:57:53 +0000
parents 6ca02b188dba
children 3c404a296995
comparison
equal deleted inserted replaced
103:c6c0aed1dbec 104:754e6030c029
1 package luan.tools; 1 package luan.tools;
2 2
3 import java.util.Arrays; 3 import java.io.IOException;
4 import java.util.Scanner;
5 import luan.lib.BasicLib; 4 import luan.lib.BasicLib;
6 import luan.Luan; 5 import luan.Luan;
7 import luan.LuanState; 6 import luan.LuanState;
8 import luan.LuanFunction; 7 import luan.LuanFunction;
9 import luan.LuanTable; 8 import luan.LuanTable;
10 import luan.LuanException; 9 import luan.LuanException;
10 import jline.ConsoleReader;
11 11
12 12
13 public class CmdLine { 13 public class CmdLine {
14 14
15 public static void main(String[] args) { 15 public static void main(String[] args) {
99 System.err.println(" - stop handling options and execute stdin"); 99 System.err.println(" - stop handling options and execute stdin");
100 System.exit(-1); 100 System.exit(-1);
101 } 101 }
102 102
103 static void interactive(LuanState luan,LuanTable env) { 103 static void interactive(LuanState luan,LuanTable env) {
104 while( true ) { 104 try {
105 System.out.print("> "); 105 ConsoleReader console = new ConsoleReader();
106 String input = new Scanner(System.in).nextLine(); 106 console.setDefaultPrompt("> ");
107 try { 107 while( true ) {
108 Object[] rtn = luan.eval(input,"stdin",env); 108 String input = console.readLine();
109 if( rtn.length > 0 ) 109 if( input==null )
110 BasicLib.print(luan,rtn); 110 break;
111 } catch(LuanException e) { 111 try {
112 System.out.println(e.getMessage()); 112 Object[] rtn = luan.eval(input,"stdin",env);
113 if( rtn.length > 0 )
114 BasicLib.print(luan,rtn);
115 } catch(LuanException e) {
116 System.out.println(e.getMessage());
117 }
113 } 118 }
119 } catch(IOException e) {
120 throw new RuntimeException(e);
114 } 121 }
115 } 122 }
116 123
117 } 124 }