Mercurial Hosting > luan
comparison src/luan/interp/LuanCompiler.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 | 1f8b6edc2b08 |
children | 3c404a296995 |
comparison
equal
deleted
inserted
replaced
103:c6c0aed1dbec | 104:754e6030c029 |
---|---|
1 package luan.interp; | 1 package luan.interp; |
2 | 2 |
3 import org.parboiled.Parboiled; | |
4 import org.parboiled.errors.ErrorUtils; | |
5 import org.parboiled.parserunners.ReportingParseRunner; | |
6 import org.parboiled.parserunners.TracingParseRunner; | |
7 import org.parboiled.support.ParsingResult; | |
8 import luan.LuanFunction; | 3 import luan.LuanFunction; |
9 import luan.LuanState; | 4 import luan.LuanState; |
10 import luan.LuanException; | 5 import luan.LuanException; |
11 import luan.LuanSource; | 6 import luan.LuanSource; |
12 import luan.LuanElement; | 7 import luan.LuanElement; |
13 import luan.LuanTable; | 8 import luan.LuanTable; |
9 import luan.parser.ParseException; | |
14 | 10 |
15 | 11 |
16 public final class LuanCompiler { | 12 public final class LuanCompiler { |
17 private LuanCompiler() {} // never | 13 private LuanCompiler() {} // never |
18 | 14 |
19 public static LuanFunction compile(LuanState luan,LuanSource src,LuanTable env) throws LuanException { | 15 public static LuanFunction compile(LuanState luan,LuanSource src,LuanTable env) throws LuanException { |
20 UpValue.Getter envGetter = env!=null ? new UpValue.ValueGetter(env) : new UpValue.EnvGetter(); | 16 UpValue.Getter envGetter = env!=null ? new UpValue.ValueGetter(env) : new UpValue.EnvGetter(); |
21 LuanParser parser = Parboiled.createParser(LuanParser.class,src,envGetter); | 17 try { |
22 ParsingResult<?> result = new ReportingParseRunner(parser.Target()).run(src.text); | 18 FnDef fnDef = LuanParser.parse(src,envGetter); |
23 // ParsingResult<?> result = new TracingParseRunner(parser.Target()).run(src); | 19 return new Closure((LuanStateImpl)luan,fnDef); |
24 if( result.hasErrors() ) { | 20 } catch(ParseException e) { |
25 // throw luan.COMPILER.exception( ErrorUtils.printParseErrors(result) ); | 21 //e.printStackTrace(); |
26 LuanElement le = new LuanSource.CompilerElement(src); | 22 LuanElement le = new LuanSource.CompilerElement(src); |
27 throw luan.bit(le).exception( ErrorUtils.printParseErrors(result) ); | 23 throw luan.bit(le).exception( e.getFancyMessage() ); |
28 } | 24 } |
29 FnDef fnDef = (FnDef)result.resultValue; | |
30 return new Closure((LuanStateImpl)luan,fnDef); | |
31 } | 25 } |
32 | 26 |
33 public static LuanState newLuanState() { | 27 public static LuanState newLuanState() { |
34 return new LuanStateImpl(); | 28 return new LuanStateImpl(); |
35 } | 29 } |