Mercurial Hosting > luan
comparison src/luan/impl/LuanParser.java @ 1335:e0cf0d108a77
major cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 14 Feb 2019 03:10:45 -0700 |
parents | 25746915a241 |
children | f5368cd8c056 |
comparison
equal
deleted
inserted
replaced
1334:c88b486a9511 | 1335:e0cf0d108a77 |
---|---|
364 | 364 |
365 private Expr callExpStr(Expr fn,Expr args) { | 365 private Expr callExpStr(Expr fn,Expr args) { |
366 Expr exp = new Expr(null,true); | 366 Expr exp = new Expr(null,true); |
367 exp.add( "Luan.checkFunction(" ); | 367 exp.add( "Luan.checkFunction(" ); |
368 exp.addAll( fn.single() ); | 368 exp.addAll( fn.single() ); |
369 exp.add( ").call(luan," ); | 369 exp.add( ").call(" ); |
370 exp.addAll( args.array() ); | 370 exp.addAll( args.array() ); |
371 exp.add( ")" ); | 371 exp.add( ")" ); |
372 return exp; | 372 return exp; |
373 } | 373 } |
374 | 374 |
375 private Stmts TemplateStmt() throws ParseException { | 375 private Stmts TemplateStmt() throws ParseException { |
376 Expr exprs = TemplateExpressions(In.NOTHING); | 376 Expr exprs = TemplateExpressions(In.NOTHING); |
377 if( exprs == null ) | 377 if( exprs == null ) |
378 return null; | 378 return null; |
379 Stmts stmt = new Stmts(); | 379 Stmts stmt = new Stmts(); |
380 stmt.add( "Luan.checkFunction(luan.index(PackageLuan.require(luan,\"luan:Io.luan\"),\"template_write\")).call(luan," ); | 380 stmt.add( "Luan.checkFunction(luan.index(PackageLuan.require(luan,\"luan:Io.luan\"),\"template_write\")).call(" ); |
381 stmt.addAll( exprs.array() ); | 381 stmt.addAll( exprs.array() ); |
382 stmt.add( "); " ); | 382 stmt.add( "); " ); |
383 return stmt; | 383 return stmt; |
384 } | 384 } |
385 | 385 |
506 Expr expr = RequiredExpr(In.NOTHING).single(); | 506 Expr expr = RequiredExpr(In.NOTHING).single(); |
507 RequiredKeyword("do"); | 507 RequiredKeyword("do"); |
508 | 508 |
509 String fnVar = "fn"+ ++forCounter; | 509 String fnVar = "fn"+ ++forCounter; |
510 Expr fnExp = new Expr(null,false); | 510 Expr fnExp = new Expr(null,false); |
511 fnExp.add( fnVar + ".call(luan)" ); | 511 fnExp.add( fnVar + ".call()" ); |
512 Stmts stmt = new Stmts(); | 512 Stmts stmt = new Stmts(); |
513 stmt.add( "" | 513 stmt.add( "" |
514 +"LuanFunction "+fnVar+" = Luan.checkFunction(" | 514 +"LuanFunction "+fnVar+" = Luan.checkFunction(" |
515 ); | 515 ); |
516 stmt.addAll( expr ); | 516 stmt.addAll( expr ); |
826 if( parser.match("==") ) { | 826 if( parser.match("==") ) { |
827 Spaces(); | 827 Spaces(); |
828 exp = exp.single(); | 828 exp = exp.single(); |
829 Expr exp2 = required(ConcatExpr(in)).single(); | 829 Expr exp2 = required(ConcatExpr(in)).single(); |
830 Expr newExp = new Expr(Val.SINGLE,false); | 830 Expr newExp = new Expr(Val.SINGLE,false); |
831 newExp.add( "LuanImpl.eq(luan," ); | 831 newExp.add( "LuanImpl.eq(" ); |
832 newExp.addAll( exp ); | 832 newExp.addAll( exp ); |
833 newExp.add( "," ); | 833 newExp.add( "," ); |
834 newExp.addAll( exp2 ); | 834 newExp.addAll( exp2 ); |
835 newExp.add( ")" ); | 835 newExp.add( ")" ); |
836 exp = newExp; | 836 exp = newExp; |
837 } else if( parser.match("~=") ) { | 837 } else if( parser.match("~=") ) { |
838 Spaces(); | 838 Spaces(); |
839 exp = exp.single(); | 839 exp = exp.single(); |
840 Expr exp2 = required(ConcatExpr(in)).single(); | 840 Expr exp2 = required(ConcatExpr(in)).single(); |
841 Expr newExp = new Expr(Val.SINGLE,false); | 841 Expr newExp = new Expr(Val.SINGLE,false); |
842 newExp.add( "!LuanImpl.eq(luan," ); | 842 newExp.add( "!LuanImpl.eq(" ); |
843 newExp.addAll( exp ); | 843 newExp.addAll( exp ); |
844 newExp.add( "," ); | 844 newExp.add( "," ); |
845 newExp.addAll( exp2 ); | 845 newExp.addAll( exp2 ); |
846 newExp.add( ")" ); | 846 newExp.add( ")" ); |
847 exp = newExp; | 847 exp = newExp; |
848 } else if( parser.match("<=") ) { | 848 } else if( parser.match("<=") ) { |
849 Spaces(); | 849 Spaces(); |
850 exp = exp.single(); | 850 exp = exp.single(); |
851 Expr exp2 = required(ConcatExpr(in)).single(); | 851 Expr exp2 = required(ConcatExpr(in)).single(); |
852 Expr newExp = new Expr(Val.SINGLE,false); | 852 Expr newExp = new Expr(Val.SINGLE,false); |
853 newExp.add( "LuanImpl.le(luan," ); | 853 newExp.add( "LuanImpl.le(" ); |
854 newExp.addAll( exp ); | 854 newExp.addAll( exp ); |
855 newExp.add( "," ); | 855 newExp.add( "," ); |
856 newExp.addAll( exp2 ); | 856 newExp.addAll( exp2 ); |
857 newExp.add( ")" ); | 857 newExp.add( ")" ); |
858 exp = newExp; | 858 exp = newExp; |
859 } else if( parser.match(">=") ) { | 859 } else if( parser.match(">=") ) { |
860 Spaces(); | 860 Spaces(); |
861 exp = exp.single(); | 861 exp = exp.single(); |
862 Expr exp2 = required(ConcatExpr(in)).single(); | 862 Expr exp2 = required(ConcatExpr(in)).single(); |
863 Expr newExp = new Expr(Val.SINGLE,false); | 863 Expr newExp = new Expr(Val.SINGLE,false); |
864 newExp.add( "LuanImpl.le(luan," ); | 864 newExp.add( "LuanImpl.le(" ); |
865 newExp.addAll( exp2 ); | 865 newExp.addAll( exp2 ); |
866 newExp.add( "," ); | 866 newExp.add( "," ); |
867 newExp.addAll( exp ); | 867 newExp.addAll( exp ); |
868 newExp.add( ")" ); | 868 newExp.add( ")" ); |
869 exp = newExp; | 869 exp = newExp; |
870 } else if( parser.match("<") ) { | 870 } else if( parser.match("<") ) { |
871 Spaces(); | 871 Spaces(); |
872 exp = exp.single(); | 872 exp = exp.single(); |
873 Expr exp2 = required(ConcatExpr(in)).single(); | 873 Expr exp2 = required(ConcatExpr(in)).single(); |
874 Expr newExp = new Expr(Val.SINGLE,false); | 874 Expr newExp = new Expr(Val.SINGLE,false); |
875 newExp.add( "LuanImpl.lt(luan," ); | 875 newExp.add( "LuanImpl.lt(" ); |
876 newExp.addAll( exp ); | 876 newExp.addAll( exp ); |
877 newExp.add( "," ); | 877 newExp.add( "," ); |
878 newExp.addAll( exp2 ); | 878 newExp.addAll( exp2 ); |
879 newExp.add( ")" ); | 879 newExp.add( ")" ); |
880 exp = newExp; | 880 exp = newExp; |
881 } else if( parser.match(">") ) { | 881 } else if( parser.match(">") ) { |
882 Spaces(); | 882 Spaces(); |
883 exp = exp.single(); | 883 exp = exp.single(); |
884 Expr exp2 = required(ConcatExpr(in)).single(); | 884 Expr exp2 = required(ConcatExpr(in)).single(); |
885 Expr newExp = new Expr(Val.SINGLE,false); | 885 Expr newExp = new Expr(Val.SINGLE,false); |
886 newExp.add( "LuanImpl.lt(luan," ); | 886 newExp.add( "LuanImpl.lt(" ); |
887 newExp.addAll( exp2 ); | 887 newExp.addAll( exp2 ); |
888 newExp.add( "," ); | 888 newExp.add( "," ); |
889 newExp.addAll( exp ); | 889 newExp.addAll( exp ); |
890 newExp.add( ")" ); | 890 newExp.add( ")" ); |
891 exp = newExp; | 891 exp = newExp; |
903 if( parser.match("..") ) { | 903 if( parser.match("..") ) { |
904 Spaces(); | 904 Spaces(); |
905 exp = exp.single(); | 905 exp = exp.single(); |
906 Expr exp2 = required(ConcatExpr(in)).single(); | 906 Expr exp2 = required(ConcatExpr(in)).single(); |
907 Expr newExp = new Expr(Val.SINGLE,false); | 907 Expr newExp = new Expr(Val.SINGLE,false); |
908 newExp.add( "LuanImpl.concat(luan," ); | 908 newExp.add( "LuanImpl.concat(" ); |
909 newExp.addAll( exp ); | 909 newExp.addAll( exp ); |
910 newExp.add( "," ); | 910 newExp.add( "," ); |
911 newExp.addAll( exp2 ); | 911 newExp.addAll( exp2 ); |
912 newExp.add( ")" ); | 912 newExp.add( ")" ); |
913 exp = newExp; | 913 exp = newExp; |
924 if( parser.match('+') ) { | 924 if( parser.match('+') ) { |
925 Spaces(); | 925 Spaces(); |
926 exp = exp.single(); | 926 exp = exp.single(); |
927 Expr exp2 = required(TermExpr(in)).single(); | 927 Expr exp2 = required(TermExpr(in)).single(); |
928 Expr newExp = new Expr(Val.SINGLE,false); | 928 Expr newExp = new Expr(Val.SINGLE,false); |
929 newExp.add( "LuanImpl.add(luan," ); | 929 newExp.add( "LuanImpl.add(" ); |
930 newExp.addAll( exp ); | 930 newExp.addAll( exp ); |
931 newExp.add( "," ); | 931 newExp.add( "," ); |
932 newExp.addAll( exp2 ); | 932 newExp.addAll( exp2 ); |
933 newExp.add( ")" ); | 933 newExp.add( ")" ); |
934 exp = newExp; | 934 exp = newExp; |
935 } else if( Minus() ) { | 935 } else if( Minus() ) { |
936 Spaces(); | 936 Spaces(); |
937 exp = exp.single(); | 937 exp = exp.single(); |
938 Expr exp2 = required(TermExpr(in)).single(); | 938 Expr exp2 = required(TermExpr(in)).single(); |
939 Expr newExp = new Expr(Val.SINGLE,false); | 939 Expr newExp = new Expr(Val.SINGLE,false); |
940 newExp.add( "LuanImpl.sub(luan," ); | 940 newExp.add( "LuanImpl.sub(" ); |
941 newExp.addAll( exp ); | 941 newExp.addAll( exp ); |
942 newExp.add( "," ); | 942 newExp.add( "," ); |
943 newExp.addAll( exp2 ); | 943 newExp.addAll( exp2 ); |
944 newExp.add( ")" ); | 944 newExp.add( ")" ); |
945 exp = newExp; | 945 exp = newExp; |
963 if( parser.match('*') ) { | 963 if( parser.match('*') ) { |
964 Spaces(); | 964 Spaces(); |
965 exp = exp.single(); | 965 exp = exp.single(); |
966 Expr exp2 = required(UnaryExpr(in)).single(); | 966 Expr exp2 = required(UnaryExpr(in)).single(); |
967 Expr newExp = new Expr(Val.SINGLE,false); | 967 Expr newExp = new Expr(Val.SINGLE,false); |
968 newExp.add( "LuanImpl.mul(luan," ); | 968 newExp.add( "LuanImpl.mul(" ); |
969 newExp.addAll( exp ); | 969 newExp.addAll( exp ); |
970 newExp.add( "," ); | 970 newExp.add( "," ); |
971 newExp.addAll( exp2 ); | 971 newExp.addAll( exp2 ); |
972 newExp.add( ")" ); | 972 newExp.add( ")" ); |
973 exp = newExp; | 973 exp = newExp; |
974 } else if( parser.match('/') ) { | 974 } else if( parser.match('/') ) { |
975 Spaces(); | 975 Spaces(); |
976 exp = exp.single(); | 976 exp = exp.single(); |
977 Expr exp2 = required(UnaryExpr(in)).single(); | 977 Expr exp2 = required(UnaryExpr(in)).single(); |
978 Expr newExp = new Expr(Val.SINGLE,false); | 978 Expr newExp = new Expr(Val.SINGLE,false); |
979 newExp.add( "LuanImpl.div(luan," ); | 979 newExp.add( "LuanImpl.div(" ); |
980 newExp.addAll( exp ); | 980 newExp.addAll( exp ); |
981 newExp.add( "," ); | 981 newExp.add( "," ); |
982 newExp.addAll( exp2 ); | 982 newExp.addAll( exp2 ); |
983 newExp.add( ")" ); | 983 newExp.add( ")" ); |
984 exp = newExp; | 984 exp = newExp; |
985 } else if( Mod() ) { | 985 } else if( Mod() ) { |
986 Spaces(); | 986 Spaces(); |
987 exp = exp.single(); | 987 exp = exp.single(); |
988 Expr exp2 = required(UnaryExpr(in)).single(); | 988 Expr exp2 = required(UnaryExpr(in)).single(); |
989 Expr newExp = new Expr(Val.SINGLE,false); | 989 Expr newExp = new Expr(Val.SINGLE,false); |
990 newExp.add( "LuanImpl.mod(luan," ); | 990 newExp.add( "LuanImpl.mod(" ); |
991 newExp.addAll( exp ); | 991 newExp.addAll( exp ); |
992 newExp.add( "," ); | 992 newExp.add( "," ); |
993 newExp.addAll( exp2 ); | 993 newExp.addAll( exp2 ); |
994 newExp.add( ")" ); | 994 newExp.add( ")" ); |
995 exp = newExp; | 995 exp = newExp; |
1017 } | 1017 } |
1018 if( Minus() ) { | 1018 if( Minus() ) { |
1019 Spaces(); | 1019 Spaces(); |
1020 Expr exp = required(UnaryExpr(in)).single(); | 1020 Expr exp = required(UnaryExpr(in)).single(); |
1021 Expr newExp = new Expr(Val.SINGLE,false); | 1021 Expr newExp = new Expr(Val.SINGLE,false); |
1022 newExp.add( "LuanImpl.unm(luan," ); | 1022 newExp.add( "LuanImpl.unm(" ); |
1023 newExp.addAll( exp ); | 1023 newExp.addAll( exp ); |
1024 newExp.add( ")" ); | 1024 newExp.add( ")" ); |
1025 return parser.success(newExp); | 1025 return parser.success(newExp); |
1026 } | 1026 } |
1027 if( Keyword("not") ) { | 1027 if( Keyword("not") ) { |
1046 return parser.failure(null); | 1046 return parser.failure(null); |
1047 if( parser.match('^') ) { | 1047 if( parser.match('^') ) { |
1048 Spaces(); | 1048 Spaces(); |
1049 Expr exp2 = required(PowExpr(in)); | 1049 Expr exp2 = required(PowExpr(in)); |
1050 Expr newExp = new Expr(Val.SINGLE,false); | 1050 Expr newExp = new Expr(Val.SINGLE,false); |
1051 newExp.add( "LuanImpl.pow(luan," ); | 1051 newExp.add( "LuanImpl.pow(" ); |
1052 newExp.addAll( exp1.single() ); | 1052 newExp.addAll( exp1.single() ); |
1053 newExp.add( "," ); | 1053 newExp.add( "," ); |
1054 newExp.addAll( exp2.single() ); | 1054 newExp.addAll( exp2.single() ); |
1055 newExp.add( ")" ); | 1055 newExp.add( ")" ); |
1056 exp1 = newExp; | 1056 exp1 = newExp; |
2013 +"import luan.LuanFunction; " | 2013 +"import luan.LuanFunction; " |
2014 +"import luan.LuanException; " | 2014 +"import luan.LuanException; " |
2015 +"import luan.modules.PackageLuan; " | 2015 +"import luan.modules.PackageLuan; " |
2016 | 2016 |
2017 +"public class " + className +" extends LuanClosure { " | 2017 +"public class " + className +" extends LuanClosure { " |
2018 +"public "+className+"(boolean javaOk,String sourceName) throws LuanException { " | 2018 +"public "+className+"(Luan luan,boolean javaOk,String sourceName) throws LuanException { " |
2019 +"super("+upValueSymbols.size()+",javaOk,sourceName); " | 2019 +"super(luan,"+upValueSymbols.size()+",javaOk,sourceName); " |
2020 + init(upValueSymbols) | 2020 + init(upValueSymbols) |
2021 +"} " | 2021 +"} " |
2022 | 2022 |
2023 +"@Override public Object doCall(Luan luan,Object[] args) throws LuanException { " | 2023 +"@Override public Object doCall(Luan luan,Object[] args) throws LuanException { " |
2024 +"final Pointer[] parentUpValues = upValues; " | 2024 +"final Pointer[] parentUpValues = upValues; " |
2034 stmt.addNewLines(); | 2034 stmt.addNewLines(); |
2035 if( !stmt.hasReturn ) | 2035 if( !stmt.hasReturn ) |
2036 stmt.add( "return LuanFunction.NOTHING; " ); | 2036 stmt.add( "return LuanFunction.NOTHING; " ); |
2037 Expr exp = new Expr(Val.SINGLE,false); | 2037 Expr exp = new Expr(Val.SINGLE,false); |
2038 exp.add( "" | 2038 exp.add( "" |
2039 +"new LuanClosure("+upValueSymbols.size()+",javaOk,sourceName) { " | 2039 +"new LuanClosure(luan(),"+upValueSymbols.size()+",javaOk,sourceName) { " |
2040 +"{ " | 2040 +"{ " |
2041 + init(upValueSymbols) | 2041 + init(upValueSymbols) |
2042 +"} " | 2042 +"} " |
2043 +"@Override public Object doCall(Luan luan,Object[] args) throws LuanException { " | 2043 +"@Override public Object doCall(Luan luan,Object[] args) throws LuanException { " |
2044 ); | 2044 ); |