Mercurial Hosting > luan
changeset 1496:6c830be6be98
parse fix
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 08 May 2020 10:46:13 -0600 |
parents | 2e8a5df45d56 |
children | f04bfbb08721 |
files | src/luan/impl/LuanCompiler.java src/luan/impl/LuanParser.java |
diffstat | 2 files changed, 34 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/impl/LuanCompiler.java Tue May 05 11:03:48 2020 -0600 +++ b/src/luan/impl/LuanCompiler.java Fri May 08 10:46:13 2020 -0600 @@ -2,8 +2,8 @@ import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.Map; import java.util.HashMap; import java.util.Base64; @@ -19,10 +19,10 @@ public final class LuanCompiler { private static final Map<String,WeakReference<Class>> map = new HashMap<String,WeakReference<Class>>(); - public static LuanFunction compile(Luan luan,String sourceText,String sourceName,boolean persist,LuanTable env) - throws LuanException - { - if( persist && env!=null ) + public static LuanFunction compile(Luan luan,String sourceText,String sourceName,boolean persist,LuanTable env) + throws LuanException + { + if( persist && env!=null ) throw new LuanException("can't persist with env"); Class fnClass = persist ? getClass(sourceText,sourceName) : getClass(sourceText,sourceName,env); boolean javaOk = false; @@ -48,8 +48,8 @@ return closure; } - private static synchronized Class getClass(String sourceText,String sourceName) - throws LuanException + private static synchronized Class getClass(String sourceText,String sourceName) + throws LuanException { String key = sourceName + "~~~" + sourceText; WeakReference<Class> ref = map.get(key); @@ -57,35 +57,35 @@ Class cls = ref.get(); if( cls != null ) return cls; - } - String fileName; - try { - byte[] a = MessageDigest.getInstance("MD5").digest(key.getBytes()); - String s = Base64.getUrlEncoder().encodeToString(a); -//System.err.println("qqqqqqqqqq "+s); - fileName = s + ".luanc"; - } catch(NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - Compiled compiled = Compiled.load(fileName,key); - //Compiled compiled = null; - if( compiled==null ) { - compiled = getCompiled(sourceText,sourceName,null); - compiled.save(fileName,key); + } + String fileName; + try { + byte[] a = MessageDigest.getInstance("MD5").digest(key.getBytes()); + String s = Base64.getUrlEncoder().encodeToString(a); +//System.err.println("qqqqqqqqqq "+s); + fileName = s + ".luanc"; + } catch(NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + Compiled compiled = Compiled.load(fileName,key); + //Compiled compiled = null; + if( compiled==null ) { + compiled = getCompiled(sourceText,sourceName,null); + compiled.save(fileName,key); } Class cls = compiled.loadClass(); map.put(key,new WeakReference<Class>(cls)); return cls; } - private static Class getClass(String sourceText,String sourceName,LuanTable env) - throws LuanException - { - return getCompiled(sourceText,sourceName,env).loadClass(); - } + private static Class getClass(String sourceText,String sourceName,LuanTable env) + throws LuanException + { + return getCompiled(sourceText,sourceName,env).loadClass(); + } - private static Compiled getCompiled(String sourceText,String sourceName,LuanTable env) - throws LuanException + private static Compiled getCompiled(String sourceText,String sourceName,LuanTable env) + throws LuanException { LuanParser parser = new LuanParser(sourceText,sourceName); parser.addVar( "require" ); @@ -98,14 +98,15 @@ } } - public static String toJava(String sourceText,String sourceName) - throws LuanException + public static String toJava(String sourceText,String sourceName) + throws LuanException { LuanParser parser = new LuanParser(sourceText,sourceName); parser.addVar( "require" ); try { return parser.RequiredModuleSource(); } catch(ParseException e) { +//e.printStackTrace(); throw new LuanException( e.getFancyMessage() ); } }
--- a/src/luan/impl/LuanParser.java Tue May 05 11:03:48 2020 -0600 +++ b/src/luan/impl/LuanParser.java Fri May 08 10:46:13 2020 -0600 @@ -1021,7 +1021,7 @@ return parser.failure(null); if( parser.match('^') ) { Spaces(); - Expr exp2 = required(PowExpr()); + Expr exp2 = required(UnaryExpr()); Expr newExp = new Expr(Val.SINGLE,false); newExp.add( "LuanImpl.pow(" ); newExp.addAll( exp1.single() );