|
| 1 | +package plugin.kpa.scriptparser; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.lang.reflect.Constructor; |
| 5 | +import java.lang.reflect.Field; |
| 6 | +import java.lang.reflect.Method; |
| 7 | +import java.util.regex.Matcher; |
| 8 | +import java.util.regex.Pattern; |
| 9 | + |
| 10 | +import plugin.kpa.scriptparser.Script.Dog; |
| 11 | +import plugin.kpa.scriptparser.Script.FParser; |
| 12 | + |
| 13 | +public class Main { |
| 14 | + |
| 15 | + public static void main(String[] args) |
| 16 | + { |
| 17 | + |
| 18 | +// |
| 19 | + |
| 20 | + for(Method m:Dog.class.getMethods()) |
| 21 | + System.out.println(m.toGenericString()); |
| 22 | + for(Field m:Dog.class.getDeclaredFields()) |
| 23 | + System.out.println("ddd:"+m.toGenericString()); |
| 24 | + |
| 25 | + |
| 26 | + Pattern pattern = Pattern.compile("a([+|\\-|*|/|>|<])(.*)"); |
| 27 | + Matcher test = pattern.matcher("a*_b"); |
| 28 | + if(test.find()) { |
| 29 | + System.out.println(test.group()); |
| 30 | + // return; |
| 31 | + }else |
| 32 | + { |
| 33 | + |
| 34 | + } |
| 35 | + |
| 36 | + FParser parser = new FParser(); |
| 37 | + parser.addScriptListener(new TestScript()); |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + try { |
| 42 | + parser.parse(" a=1+3"); |
| 43 | + parser.parse("b=4*99"); |
| 44 | + parser.parse("if _a==4 :print('test')"); |
| 45 | + parser.parse("if _a==4 :print('nice');print('jjj')"); |
| 46 | + parser.parse("getPath=getMethod('java.io.File','public java.lang.String java.io.File.getPath()')"); |
| 47 | + parser.parse("construct=getConstruct('java.io.File','public java.io.File(java.lang.String)')"); |
| 48 | + parser.parse("file=constructObject(_construct,'\\/sdcard\\/file')"); |
| 49 | +// //函数二级嵌套失败.. |
| 50 | +// parser.parse("result=invokeMethod(_getPath,_file)"); |
| 51 | +// parser.parse("print(_result)"); |
| 52 | + |
| 53 | + parser.parse("method mymethod(str,yyy):print('test'+_str);print(33+_yyy)end"); |
| 54 | + parser.parse("mymethod('ddd',44)"); |
| 55 | +// parser.parse("b=1"); |
| 56 | +// parser.parse("_b=_b+1"); |
| 57 | +// parser.parse("print(_b)"); |
| 58 | +// parser.parse("for(a=0;_a<5;_a=_a+1):print('heooe');print('dd'+_a)"); |
| 59 | + |
| 60 | + Dog dog = new Dog("formatfa",20); |
| 61 | + dog.setName("lf"); |
| 62 | + dog.setAge(10); |
| 63 | + //set field test |
| 64 | + //private java.lang.String plugin.kpa.scriptparser.Script.Dog.name |
| 65 | + parser.getVm().setValue("dog",dog); |
| 66 | + System.out.println(dog.toString()); |
| 67 | + parser.parse("setField('plugin.kpa.scriptparser.Script.Dog','private java.lang.String plugin.kpa.scriptparser.Script.Dog.name',_dog,'dragon')"); |
| 68 | + parser.parse("print(_dog)"); |
| 69 | + System.out.println(dog.toString()); |
| 70 | + |
| 71 | + // parser.parse("stop"); |
| 72 | + |
| 73 | + parser.parse("test=getField('plugin.kpa.scriptparser.Script.Dog','private java.lang.String plugin.kpa.scriptparser.Script.Dog.name',_dog)"); |
| 74 | + |
| 75 | + parser.parse("print('dd'+_test)"); |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + parser.parse("kk=10"); |
| 80 | + parser.parse("print('ttt'+_kk)"); |
| 81 | + |
| 82 | + |
| 83 | + parser.parse("method add(a,b):print(_a+_b)end"); |
| 84 | + |
| 85 | + parser.parse("add(2,8)"); |
| 86 | + // parser.parse("print('第一个参数的值是:'+_arg0)"); |
| 87 | + } catch (Exception e) { |
| 88 | + System.out.println(e.toString()); |
| 89 | + e.printStackTrace(); |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + } |
| 94 | +} |
0 commit comments