view 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
line wrap: on
line source

package luan.interp;

import luan.LuanFunction;
import luan.LuanState;
import luan.LuanException;
import luan.LuanSource;
import luan.LuanElement;
import luan.LuanTable;
import luan.parser.ParseException;


public final class LuanCompiler {
	private LuanCompiler() {}  // never

	public static LuanFunction compile(LuanState luan,LuanSource src,LuanTable env) throws LuanException {
		UpValue.Getter envGetter = env!=null ? new UpValue.ValueGetter(env) : new UpValue.EnvGetter();
		try {
			FnDef fnDef = LuanParser.parse(src,envGetter);
			return new Closure((LuanStateImpl)luan,fnDef);
		} catch(ParseException e) {
//e.printStackTrace();
			LuanElement le = new LuanSource.CompilerElement(src);
			throw luan.bit(le).exception( e.getFancyMessage() );
		}
	}

	public static LuanState newLuanState() {
		return new LuanStateImpl();
	}
}