Mercurial Hosting > luan
comparison src/luan/interp/LuaCompiler.java @ 40:e3624b7cd603
implement stack trace
git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 21 Dec 2012 10:45:54 +0000 |
parents | 5cf15507d77e |
children |
comparison
equal
deleted
inserted
replaced
39:e5bcb1eeafc1 | 40:e3624b7cd603 |
---|---|
6 import org.parboiled.parserunners.TracingParseRunner; | 6 import org.parboiled.parserunners.TracingParseRunner; |
7 import org.parboiled.support.ParsingResult; | 7 import org.parboiled.support.ParsingResult; |
8 import luan.LuaFunction; | 8 import luan.LuaFunction; |
9 import luan.LuaState; | 9 import luan.LuaState; |
10 import luan.LuaException; | 10 import luan.LuaException; |
11 import luan.LuaSource; | |
12 import luan.LuaElement; | |
11 | 13 |
12 | 14 |
13 public final class LuaCompiler { | 15 public final class LuaCompiler { |
14 private LuaCompiler() {} // never | 16 private LuaCompiler() {} // never |
15 | 17 |
16 public static LuaFunction compile(LuaState lua,String src) throws LuaException { | 18 public static LuaFunction compile(LuaState lua,LuaSource src) throws LuaException { |
17 LuaParser parser = Parboiled.createParser(LuaParser.class); | 19 LuaParser parser = Parboiled.createParser(LuaParser.class); |
18 ParsingResult<?> result = new ReportingParseRunner(parser.Target()).run(src); | 20 parser.source = src; |
21 ParsingResult<?> result = new ReportingParseRunner(parser.Target()).run(src.text); | |
19 // ParsingResult<?> result = new TracingParseRunner(parser.Target()).run(src); | 22 // ParsingResult<?> result = new TracingParseRunner(parser.Target()).run(src); |
20 if( result.hasErrors() ) | 23 if( result.hasErrors() ) |
21 throw new LuaException( ErrorUtils.printParseErrors(result) ); | 24 throw new LuaException( lua, null, ErrorUtils.printParseErrors(result) ); |
22 Object resultValue = result.resultValue; | 25 Object resultValue = result.resultValue; |
23 if( resultValue instanceof Expressions ) { | 26 if( resultValue instanceof Expressions ) { |
24 final Expressions expressions = (Expressions)resultValue; | 27 final Expressions expressions = (Expressions)resultValue; |
25 return new LuaFunction() { | 28 return new LuaFunction() { |
26 public Object[] call(LuaState lua,Object... args) throws LuaException { | 29 public Object[] call(LuaState lua,Object[] args) throws LuaException { |
27 return expressions.eval((LuaStateImpl)lua); | 30 return expressions.eval((LuaStateImpl)lua); |
28 } | 31 } |
29 }; | 32 }; |
30 } | 33 } |
31 Chunk chunk = (Chunk)resultValue; | 34 Chunk chunk = (Chunk)resultValue; |