annotate core/src/luan/impl/LuanParser.java @ 693:ca169567ce07

module URIs must now include ".luan"
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 19 Apr 2016 15:54:11 -0600
parents f99f51bc5bea
children b620b8e1010f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
166
4eaee12f6c65 move luan/interp to impl
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 165
diff changeset
1 package luan.impl;
5
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
3 //import java.io.StringWriter;
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
4 //import java.io.PrintWriter;
12
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
5 import java.util.Set;
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
6 import java.util.HashSet;
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
7 import java.util.Arrays;
9
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
8 import java.util.List;
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
9 import java.util.ArrayList;
676
Franklin Schmidt <fschmidt@gmail.com>
parents: 675
diff changeset
10 import java.util.concurrent.atomic.AtomicInteger;
48
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
11 import luan.Luan;
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 46
diff changeset
12 import luan.LuanState;
503
92c3d22745b8 make _ENV optional
Franklin Schmidt <fschmidt@gmail.com>
parents: 460
diff changeset
13 import luan.LuanTable;
186
cf939124461a don't import modules by default
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 181
diff changeset
14 import luan.modules.PackageLuan;
5
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
15
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
16
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
17 final class LuanParser {
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
18
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
19 private interface Sym {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
20 public Expr exp();
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
21 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
22
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
23 private int symCounter = 0;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
24
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
25 private class LocalSym implements Sym {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
26 final String name;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
27 final String javaName;
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
28 boolean isPointer = false;
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
29
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
30 LocalSym(String name) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
31 this.name = name;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
32 this.javaName = name + "_" + (++symCounter);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
33 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
34
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
35 Stmts declaration(Expr value) {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
36 Stmts stmt = new Stmts();
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
37 if( value==null ) {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
38 stmt.add( new Object() {
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
39 @Override public String toString() {
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
40 if( !isPointer )
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
41 return "Object " + javaName + "; ";
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
42 else
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
43 return "final Pointer " + javaName + " = new Pointer(); ";
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
44 }
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
45 } );
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
46 } else {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
47 if( value.valType != Val.SINGLE ) throw new RuntimeException();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
48 stmt.add( new Object() {
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
49 @Override public String toString() {
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
50 if( !isPointer )
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
51 return "Object " + javaName + " = ";
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
52 else
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
53 return "final Pointer " + javaName + " = new Pointer(";
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
54 }
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
55 } );
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
56 stmt.addAll(value);
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
57 stmt.add( new Object() {
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
58 @Override public String toString() {
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
59 if( !isPointer )
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
60 return "; ";
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
61 else
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
62 return "); ";
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
63 }
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
64 } );
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
65 }
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
66 return stmt;
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
67 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
68
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
69 @Override public Expr exp() {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
70 Expr exp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
71 exp.add( new Object() {
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
72 @Override public String toString() {
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
73 if( !isPointer )
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
74 return javaName;
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
75 else
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
76 return javaName + ".o";
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
77 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
78 } );
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
79 return exp;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
80 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
81 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
82
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
83 private class UpSym implements Sym {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
84 final String name;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
85 final int i;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
86 final String value;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
87
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
88 UpSym(String name,int i,String value) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
89 this.name = name;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
90 this.i = i;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
91 this.value = value;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
92 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
93
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
94 String init() {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
95 return "upValues[" + i + "] = " + value + "; ";
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
96 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
97
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
98 @Override public Expr exp() {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
99 Expr exp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
100 exp.add( new Object() {
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
101 @Override public String toString() {
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
102 return "upValues[" + i + "].o";
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
103 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
104 } );
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
105 return exp;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
106 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
107 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
108
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
109 private final class Frame {
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
110 final Frame parent;
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
111 final List<LocalSym> symbols = new ArrayList<LocalSym>();
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
112 int loops = 0;
24
7ee247560db5 add VarArgs
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 21
diff changeset
113 boolean isVarArg = false;
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
114 final List<UpSym> upValueSymbols = new ArrayList<UpSym>();
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
115
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
116 Frame() {
34
0cdc1da466ee implement _G and _ENV
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 33
diff changeset
117 this.parent = null;
0cdc1da466ee implement _G and _ENV
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 33
diff changeset
118 }
0cdc1da466ee implement _G and _ENV
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 33
diff changeset
119
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
120 Frame(Frame parent) {
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
121 this.parent = parent;
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
122 }
32
c3eab5a3ce3c implement closures
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
123
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
124 LocalSym addLocalSym(String name) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
125 LocalSym sym = new LocalSym(name);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
126 symbols.add(sym);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
127 return sym;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
128 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
129
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
130 UpSym addUpSym(String name,String value) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
131 UpSym sym = new UpSym( name, upValueSymbols.size(), value );
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
132 upValueSymbols.add(sym);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
133 return sym;
32
c3eab5a3ce3c implement closures
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
134 }
c3eab5a3ce3c implement closures
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
135
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
136 LocalSym getLocalSym(String name) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
137 int i = symbols.size();
32
c3eab5a3ce3c implement closures
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
138 while( --i >= 0 ) {
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
139 LocalSym sym = symbols.get(i);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
140 if( sym.name.equals(name) )
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
141 return sym;
32
c3eab5a3ce3c implement closures
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
142 }
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
143 return null;
32
c3eab5a3ce3c implement closures
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
144 }
108
3c404a296995 make Package module more standard;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 107
diff changeset
145
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
146 UpSym getUpSym(String name) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
147 for( UpSym upSym : upValueSymbols ) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
148 if( upSym.name.equals(name) )
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
149 return upSym;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
150 }
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
151 if( parent != null ) {
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
152 LocalSym sym = parent.getLocalSym(name);
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
153 if( sym != null ) {
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
154 sym.isPointer = true;
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
155 return addUpSym(name,sym.javaName);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
156 }
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
157 UpSym upSym = parent.getUpSym(name);
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
158 if( upSym != null ) {
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
159 return addUpSym(name,"parentUpValues["+upSym.i+"]");
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
160 }
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
161 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
162 return null;
108
3c404a296995 make Package module more standard;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 107
diff changeset
163 }
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
164
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
165 Sym getSym(String name) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
166 Sym sym = getLocalSym(name);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
167 return sym != null ? sym : getUpSym(name);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
168 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
169
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
170 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
171
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
172 private static class In {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
173 static final In NOTHING = new In(false);
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
174
157
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
175 final boolean template;
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
176
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
177 private In(boolean template) {
157
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
178 this.template = template;
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
179 }
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
180
157
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
181 In template() {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
182 return template ? this : new In(true);
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
183 }
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
184 }
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
185
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
186 private Frame frame;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
187 private final Parser parser;
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
188 private final Stmts top;
86
6db8f286fa6c _ENV is per module, not global
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 83
diff changeset
189
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
190 LuanParser(String sourceName,String sourceText) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
191 this.frame = new Frame();
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
192 this.parser = new Parser(sourceName,sourceText);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
193 this.top = new Stmts();
108
3c404a296995 make Package module more standard;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 107
diff changeset
194 }
3c404a296995 make Package module more standard;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 107
diff changeset
195
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
196 void addVar(String name) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
197 UpSym upSym = frame.addUpSym( "-ADDED-" ,"new Pointer()");
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 684
diff changeset
198 LocalSym sym = frame.addLocalSym( name );
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 684
diff changeset
199 sym.isPointer = true;
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 684
diff changeset
200 top.add( "final Pointer " + sym.javaName + " = upValues[" + upSym.i + "]; " );
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
201 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
202
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
203 private int symbolsSize() {
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
204 return frame.symbols.size();
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
205 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
206
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
207 private Stmts addSymbol(String name,Expr value) {
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
208 final LocalSym sym = frame.addLocalSym(name);
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
209 return sym.declaration(value);
28
df923e5835b2 fix local initial assignment
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 26
diff changeset
210 }
df923e5835b2 fix local initial assignment
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 26
diff changeset
211
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
212 private Sym getSym(String name) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
213 return frame.getSym(name);
17
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
214 }
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
215
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
216 private void popSymbols(int n) {
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
217 List<LocalSym> symbols = frame.symbols;
19
a7c13c6017f7 add GenericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 18
diff changeset
218 while( n-- > 0 ) {
a7c13c6017f7 add GenericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 18
diff changeset
219 symbols.remove(symbols.size()-1);
a7c13c6017f7 add GenericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 18
diff changeset
220 }
a7c13c6017f7 add GenericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 18
diff changeset
221 }
a7c13c6017f7 add GenericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 18
diff changeset
222
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
223 private void incLoops() {
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
224 frame.loops++;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
225 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
226
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
227 private void decLoops() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
228 frame.loops--;
20
d85510d92eee add BreakStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 19
diff changeset
229 }
d85510d92eee add BreakStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 19
diff changeset
230
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
231 private <T> T required(T t) throws ParseException {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
232 if( t==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
233 throw parser.exception();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
234 return t;
20
d85510d92eee add BreakStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 19
diff changeset
235 }
d85510d92eee add BreakStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 19
diff changeset
236
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
237 private <T> T required(T t,String msg) throws ParseException {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
238 if( t==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
239 throw parser.exception(msg);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
240 return t;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
241 }
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
242
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
243 private Class newFnClass(Stmts stmt) {
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
244 return toFnClass( stmt, frame.upValueSymbols );
32
c3eab5a3ce3c implement closures
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
245 }
20
d85510d92eee add BreakStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 19
diff changeset
246
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
247 private Expr newFnExp(Stmts stmt,String name) {
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
248 return toFnExp( stmt, frame.upValueSymbols, name );
665
41f8fdbc3a0a compile modules
Franklin Schmidt <fschmidt@gmail.com>
parents: 664
diff changeset
249 }
41f8fdbc3a0a compile modules
Franklin Schmidt <fschmidt@gmail.com>
parents: 664
diff changeset
250
667
08966099aa6d implement Closure directly
Franklin Schmidt <fschmidt@gmail.com>
parents: 666
diff changeset
251 Class Expression() throws ParseException {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
252 Spaces();
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
253 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
254 Expr expr = ExprZ(In.NOTHING);
158
cced1c4d3575 only allow TemplateExpressions at end of expr list;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 157
diff changeset
255 if( expr != null && parser.endOfInput() ) {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
256 top.add( "return " );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
257 top.addAll( expr );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
258 top.add( "; " );
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
259 top.hasReturn = true;
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
260 return parser.success(newFnClass(top));
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
261 }
108
3c404a296995 make Package module more standard;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 107
diff changeset
262 return parser.failure(null);
3c404a296995 make Package module more standard;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 107
diff changeset
263 }
3c404a296995 make Package module more standard;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 107
diff changeset
264
667
08966099aa6d implement Closure directly
Franklin Schmidt <fschmidt@gmail.com>
parents: 666
diff changeset
265 Class RequiredModule() throws ParseException {
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
266 GetRequiredModule();
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
267 return newFnClass(top);
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
268 }
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
269
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
270 String RequiredModuleSource() throws ParseException {
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
271 GetRequiredModule();
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
272 return toFnString( top, frame.upValueSymbols );
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
273 }
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
274
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
275 void GetRequiredModule() throws ParseException {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
276 Spaces();
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
277 parser.begin();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
278 frame.isVarArg = true;
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
279 top.add( "final Object[] varArgs = LuanImpl.varArgs(args,0); " );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
280 Stmts block = RequiredBlock();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
281 top.addAll( block );
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
282 top.hasReturn = block.hasReturn;
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
283 if( !parser.endOfInput() )
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
284 throw parser.exception();
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
285 parser.success();
11
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
286 }
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
287
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
288 private Stmts RequiredBlock() throws ParseException {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
289 Stmts stmts = new Stmts();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
290 int stackStart = symbolsSize();
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
291 do {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
292 Spaces();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
293 stmts.addNewLines();
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
294 Stmts stmt = Stmt();
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
295 if( stmt != null ) {
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
296 stmts.addAll(stmt);
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
297 stmts.hasReturn = stmt.hasReturn;
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
298 }
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
299 } while( !stmts.hasReturn && (StmtSep() || TemplateSep(stmts)) );
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
300 Spaces();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
301 while( StmtSep() )
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
302 Spaces();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
303 stmts.addNewLines();
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
304 int stackEnd = symbolsSize();
19
a7c13c6017f7 add GenericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 18
diff changeset
305 popSymbols( stackEnd - stackStart );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
306 return stmts;
12
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
307 }
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
308
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
309 private boolean StmtSep() throws ParseException {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
310 return parser.match( ';' ) || EndOfLine();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
311 }
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
312
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
313 private boolean TemplateSep(Stmts stmts) throws ParseException {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
314 Stmts stmt = TemplateStmt();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
315 if( stmt != null ) {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
316 stmts.addAll(stmt);
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
317 return true;
157
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
318 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
319 return false;
14
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
320 }
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
321
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
322 private boolean EndOfLine() {
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
323 if( MatchEndOfLine() ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
324 parser.sb().append('\n');
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
325 return true;
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
326 } else {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
327 return false;
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
328 }
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
329 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
330
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
331 private boolean MatchEndOfLine() {
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
332 return parser.match( "\r\n" ) || parser.match( '\r' ) || parser.match( '\n' );
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
333 }
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
334
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
335 private Stmts Stmt() throws ParseException {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
336 Stmts stmt;
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
337 if( (stmt=ReturnStmt()) != null
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
338 || (stmt=FunctionStmt()) != null
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
339 || (stmt=LocalStmt()) != null
661
1bbb08c0d8f1 compile LocalFunctionStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 660
diff changeset
340 || (stmt=LocalFunctionStmt()) != null
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
341 || (stmt=BreakStmt()) != null
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
342 || (stmt=ForStmt()) != null
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
343 || (stmt=DoStmt()) != null
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
344 || (stmt=WhileStmt()) != null
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
345 || (stmt=RepeatStmt()) != null
653
538b0ae08faa compile IfStmt and BreakStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 652
diff changeset
346 || (stmt=IfStmt()) != null
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
347 || (stmt=SetStmt()) != null
159
0abc9181061a revert rev 154 but only allow FnCall, AndExpr, or OrExpr in ExpressionsStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 158
diff changeset
348 || (stmt=ExpressionsStmt()) != null
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
349 ) {
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
350 return stmt;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
351 }
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
352 return null;
12
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
353 }
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
354
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
355 private Expr indexExpStr(Expr exp1,Expr exp2) {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
356 Expr exp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
357 exp.add( "luan.index(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
358 exp.addAll( exp1.single() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
359 exp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
360 exp.addAll( exp2.single() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
361 exp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
362 return exp;
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
363 }
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
364
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
365 private Expr callExpStr(Expr fn,Expr args) {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
366 Expr exp = new Expr(null,true);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
367 exp.add( "Luan.checkFunction(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
368 exp.addAll( fn.single() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
369 exp.add( ").call(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
370 exp.addAll( args.array() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
371 exp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
372 return exp;
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
373 }
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
374
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
375 private Stmts TemplateStmt() throws ParseException {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
376 Expr exprs = TemplateExpressions(In.NOTHING);
369
85bf9f0379aa template statements no longer depend on 'Io' being defined
Franklin Schmidt <fschmidt@gmail.com>
parents: 356
diff changeset
377 if( exprs == null )
157
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
378 return null;
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
379 Stmts stmt = new Stmts();
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 688
diff changeset
380 stmt.add( "Luan.checkFunction(luan.index(PackageLuan.require(luan,\"luan:Io.luan\"),\"template_write\")).call(luan," );
680
ecd436959855 improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents: 679
diff changeset
381 stmt.addAll( exprs.array() );
ecd436959855 improve template statements
Franklin Schmidt <fschmidt@gmail.com>
parents: 679
diff changeset
382 stmt.add( "); " );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
383 return stmt;
157
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
384 }
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
385
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
386 private Expr TemplateExpressions(In in) throws ParseException {
157
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
387 if( in.template )
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
388 return null;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
389 int start = parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
390 if( !parser.match( "%>" ) )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
391 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
392 EndOfLine();
157
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
393 In inTemplate = in.template();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
394 List<Expr> builder = new ArrayList<Expr>();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
395 while(true) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
396 if( parser.match( "<%=" ) ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
397 Spaces();
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
398 builder.add( RequiredExpr(inTemplate) );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
399 RequiredMatch( "%>" );
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
400 } else if( parser.match( "<%" ) ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
401 Spaces();
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
402 return parser.success(expString(builder));
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
403 } else {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
404 int i = parser.currentIndex();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
405 do {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
406 if( parser.match( "%>" ) )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
407 throw parser.exception("'%>' unexpected");
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
408 if( !parser.anyChar() )
157
1de3e4a6e82d remove LuanJavaFunction.RTN_NUMBER_ARRAY;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 155
diff changeset
409 throw parser.exception("Unclosed template expression");
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
410 } while( !parser.test( "<%" ) );
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
411 String match = parser.textFrom(i);
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
412 builder.add( constExpStr(match) );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
413 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
414 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
415 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
416
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
417 private Stmts ReturnStmt() throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
418 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
419 if( !Keyword("return") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
420 return parser.failure(null);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
421 Expr exprs = ExpStringList(In.NOTHING);
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
422 Stmts stmt = new Stmts();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
423 stmt.add( "return " );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
424 if( exprs != null )
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
425 stmt.addAll( exprs );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
426 else
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
427 stmt.add( "LuanFunction.NOTHING" );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
428 stmt.add( "; " );
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
429 stmt.hasReturn = true;
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
430 return parser.success( stmt );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
431 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
432
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
433 private Stmts FunctionStmt() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
434 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
435 if( !Keyword("function") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
436 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
437
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
438 parser.currentIndex();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
439 String name = RequiredName();
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
440 Var var = nameVar(name);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
441 while( parser.match( '.' ) ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
442 Spaces();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
443 // Expr exp = NameExpr();
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
444 name = Name();
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
445 if( name==null )
636
13b390bfed32 parser fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 604
diff changeset
446 return parser.failure(null);
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
447 var = indexVar( var.exp(), constExpStr(name) );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
448 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
449
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
450 Expr fnDef = RequiredFunction(name);
665
41f8fdbc3a0a compile modules
Franklin Schmidt <fschmidt@gmail.com>
parents: 664
diff changeset
451 return parser.success( var.set(fnDef) );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
452 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
453
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
454 private Stmts LocalFunctionStmt() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
455 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
456 if( !(Keyword("local") && Keyword("function")) )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
457 return parser.failure(null);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
458 Stmts stmt = new Stmts();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
459 String name = RequiredName();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
460 stmt.addAll( addSymbol(name,null) );
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
461 Expr fnDef = RequiredFunction(name);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
462 stmt.addAll( nameVar(name).set(fnDef) );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
463 return parser.success( stmt );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
464 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
465
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
466 private Stmts BreakStmt() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
467 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
468 if( !Keyword("break") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
469 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
470 if( frame.loops <= 0 )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
471 throw parser.exception("'break' outside of loop");
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
472 Stmts stmt = new Stmts();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
473 stmt.add( "break; " );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
474 return parser.success( stmt );
17
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
475 }
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
476
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
477 int forCounter = 0;
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
478
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
479 private Stmts ForStmt() throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
480 parser.begin();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
481 int stackStart = symbolsSize();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
482 if( !Keyword("for") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
483 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
484 List<String> names = RequiredNameList();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
485 if( !Keyword("in") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
486 return parser.failure(null);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
487 Expr expr = RequiredExpr(In.NOTHING).single();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
488 RequiredKeyword("do");
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
489
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
490 String fnVar = "fn"+ ++forCounter;
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
491 Expr fnExp = new Expr(null,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
492 fnExp.add( fnVar + ".call(luan)" );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
493 Stmts stmt = new Stmts();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
494 stmt.add( ""
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
495 +"LuanFunction "+fnVar+" = Luan.checkFunction("
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
496 );
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
497 stmt.addAll( expr );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
498 stmt.add( "); " );
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
499 stmt.add( "while(true) { " );
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
500 stmt.addAll( makeLocalSetStmt(names,fnExp) );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
501 stmt.add( "if( " );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
502 stmt.addAll( nameVar(names.get(0)).exp() );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
503 stmt.add( "==null ) break; " );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
504 Stmts loop = RequiredLoopBlock();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
505 RequiredKeyword("end");
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
506 stmt.addAll( loop );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
507 stmt.add( "} " );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
508 popSymbols( symbolsSize() - stackStart );
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
509 return parser.success(stmt);
54
f5b27ef14d73 add OutputStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 51
diff changeset
510 }
f5b27ef14d73 add OutputStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 51
diff changeset
511
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
512 private Stmts DoStmt() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
513 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
514 if( !Keyword("do") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
515 return parser.failure(null);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
516 Stmts stmt = RequiredBlock();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
517 RequiredKeyword("end");
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
518 return parser.success(stmt);
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
519 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
520
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
521 private Stmts LocalStmt() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
522 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
523 if( !Keyword("local") )
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
524 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
525 List<String> names = NameList();
356
5e34702423a0 better parser error message
Franklin Schmidt <fschmidt@gmail.com>
parents: 326
diff changeset
526 if( names==null ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
527 if( Keyword("function") )
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
528 return parser.failure(null); // handled later
356
5e34702423a0 better parser error message
Franklin Schmidt <fschmidt@gmail.com>
parents: 326
diff changeset
529 throw parser.exception("Invalid local statement");
5e34702423a0 better parser error message
Franklin Schmidt <fschmidt@gmail.com>
parents: 326
diff changeset
530 }
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
531 Stmts stmt = new Stmts();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
532 if( parser.match( '=' ) ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
533 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
534 Expr values = ExpStringList(In.NOTHING);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
535 if( values==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
536 throw parser.exception("Expressions expected");
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
537 stmt.addAll( makeLocalSetStmt(names,values) );
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
538 } else {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
539 Expr value = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
540 value.add( "null" );
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
541 for( String name : names ) {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
542 stmt.addAll( addSymbol(name,value) );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
543 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
544 }
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
545 return parser.success(stmt);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
546 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
547
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
548 private List<String> RequiredNameList() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
549 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
550 List<String> names = NameList();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
551 if( names==null )
139
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
552 throw parser.exception("Name expected");
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
553 return parser.success(names);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
554 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
555
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
556 private List<String> NameList() throws ParseException {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
557 String name = Name();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
558 if( name==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
559 return null;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
560 List<String> names = new ArrayList<String>();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
561 names.add(name);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
562 while( (name=anotherName()) != null ) {
139
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
563 names.add(name);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
564 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
565 return names;
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
566 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
567
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
568 private String anotherName() throws ParseException {
139
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
569 parser.begin();
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
570 if( !parser.match( ',' ) )
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
571 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
572 Spaces();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
573 String name = Name();
139
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
574 if( name==null )
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
575 return parser.failure(null);
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
576 return parser.success(name);
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
577 }
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
578
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
579 private Stmts WhileStmt() throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
580 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
581 if( !Keyword("while") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
582 return parser.failure(null);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
583 Expr cnd = RequiredExpr(In.NOTHING).single();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
584 RequiredKeyword("do");
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
585 Stmts loop = RequiredLoopBlock();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
586 RequiredKeyword("end");
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
587 Stmts stmt = new Stmts();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
588 stmt.add( "while( Luan.checkBoolean(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
589 stmt.addAll( cnd );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
590 stmt.add( ") ) { " );
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
591 stmt.addAll( loop );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
592 stmt.add( "} " );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
593 return parser.success( stmt );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
594 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
595
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
596 private Stmts RepeatStmt() throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
597 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
598 if( !Keyword("repeat") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
599 return parser.failure(null);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
600 Stmts loop =RequiredLoopBlock();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
601 RequiredKeyword("until");
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
602 Expr cnd = RequiredExpr(In.NOTHING).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
603 Stmts stmt = new Stmts();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
604 stmt.add( "do { " );
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
605 stmt.addAll( loop );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
606 stmt.add( "} while( !Luan.checkBoolean(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
607 stmt.addAll( cnd );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
608 stmt.add( ") ); " );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
609 return parser.success( stmt );
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
610 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
611
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
612 private Stmts RequiredLoopBlock() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
613 incLoops();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
614 Stmts stmt = RequiredBlock();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
615 decLoops();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
616 return stmt;
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
617 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
618
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
619 private Stmts IfStmt() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
620 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
621 if( !Keyword("if") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
622 return parser.failure(null);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
623 Stmts stmt = new Stmts();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
624 Expr cnd;
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
625 Stmts block;
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
626 boolean hasReturn = true;
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
627 cnd = RequiredExpr(In.NOTHING).single();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
628 RequiredKeyword("then");
653
538b0ae08faa compile IfStmt and BreakStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 652
diff changeset
629 block = RequiredBlock();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
630 stmt.add( "if( Luan.checkBoolean(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
631 stmt.addAll( cnd );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
632 stmt.add( ") ) { " );
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
633 stmt.addAll( block );
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
634 if( !block.hasReturn )
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
635 hasReturn = false;
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
636 while( Keyword("elseif") ) {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
637 cnd = RequiredExpr(In.NOTHING).single();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
638 RequiredKeyword("then");
653
538b0ae08faa compile IfStmt and BreakStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 652
diff changeset
639 block = RequiredBlock();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
640 stmt.add( "} else if( Luan.checkBoolean(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
641 stmt.addAll( cnd );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
642 stmt.add( ") ) { " );
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
643 stmt.addAll( block );
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
644 if( !block.hasReturn )
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
645 hasReturn = false;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
646 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
647 if( Keyword("else") ) {
653
538b0ae08faa compile IfStmt and BreakStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 652
diff changeset
648 block = RequiredBlock();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
649 stmt.add( "} else { " );
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
650 stmt.addAll( block );
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
651 if( !block.hasReturn )
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
652 hasReturn = false;
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
653 } else {
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
654 hasReturn = false;
653
538b0ae08faa compile IfStmt and BreakStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 652
diff changeset
655 }
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
656 RequiredKeyword("end");
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
657 stmt.add( "} " );
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
658 stmt.hasReturn = hasReturn;
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
659 return parser.success( stmt );
20
d85510d92eee add BreakStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 19
diff changeset
660 }
d85510d92eee add BreakStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 19
diff changeset
661
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
662 private Stmts SetStmt() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
663 parser.begin();
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
664 List<Var> vars = new ArrayList<Var>();
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
665 Var v = SettableVar();
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
666 if( v == null )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
667 return parser.failure(null);
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
668 vars.add(v);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
669 while( parser.match( ',' ) ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
670 Spaces();
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
671 v = SettableVar();
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
672 if( v == null )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
673 return parser.failure(null);
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
674 vars.add(v);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
675 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
676 if( !parser.match( '=' ) )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
677 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
678 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
679 Expr values = ExpStringList(In.NOTHING);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
680 if( values==null )
274
8afe9f2fdfec AB testing, not fully tested
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 271
diff changeset
681 // throw parser.exception("Expressions expected");
8afe9f2fdfec AB testing, not fully tested
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 271
diff changeset
682 return parser.failure(null);
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
683 return parser.success( makeSetStmt(vars,values) );
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
684 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
685
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
686 private Stmts makeSetStmt(List<Var> vars,Expr values) throws ParseException {
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
687 int n = vars.size();
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
688 if( n == 1 )
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
689 return vars.get(0).set(values);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
690 Stmts stmt = new Stmts();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
691 String varName = values.valType==Val.ARRAY ? "a" : "t";
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
692 stmt.add( varName + " = " );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
693 stmt.addAll( values );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
694 stmt.add( "; " );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
695 Expr t = new Expr(values.valType,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
696 t.add( varName );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
697 t = t.single();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
698 stmt.addAll( vars.get(0).set(t) );
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
699 for( int i=1; i<n; i++ ) {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
700 t.clear();
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
701 t.add( "LuanImpl.pick(" + varName + ","+i+")" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
702 stmt.addAll( vars.get(i).set(t) );
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
703 }
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
704 return stmt;
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
705 }
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
706
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
707 private Stmts makeLocalSetStmt(List<String> names,Expr values) throws ParseException {
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
708 int n = names.size();
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
709 if( n == 1 )
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
710 return addSymbol(names.get(0),values.single());
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
711 Stmts stmt = new Stmts();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
712 String varName = values.valType==Val.ARRAY ? "a" : "t";
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
713 stmt.add( varName + " = " );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
714 stmt.addAll( values );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
715 stmt.add( "; " );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
716 Expr t = new Expr(values.valType,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
717 t.add( varName );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
718 t = t.single();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
719 stmt.addAll( addSymbol(names.get(0),t) );
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
720 for( int i=1; i<n; i++ ) {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
721 t.clear();
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
722 t.add( "LuanImpl.pick(" + varName + ","+i+")" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
723 stmt.addAll( addSymbol(names.get(i),t) );
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
724 }
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
725 return stmt;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
726 }
671
82f130eba7b0 improve declarations
Franklin Schmidt <fschmidt@gmail.com>
parents: 670
diff changeset
727
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
728 private Stmts ExpressionsStmt() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
729 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
730 Expr exp = ExprZ(In.NOTHING);
651
140cc5191b7a start compiling statements
Franklin Schmidt <fschmidt@gmail.com>
parents: 650
diff changeset
731 if( exp != null && exp.isStmt ) {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
732 Stmts stmt = new Stmts();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
733 if( exp.valType==Val.SINGLE ) {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
734 stmt.add( "LuanImpl.nop(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
735 stmt.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
736 stmt.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
737 } else {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
738 stmt.addAll( exp );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
739 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
740 stmt.add( "; " );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
741 return parser.success( stmt );
651
140cc5191b7a start compiling statements
Franklin Schmidt <fschmidt@gmail.com>
parents: 650
diff changeset
742 }
159
0abc9181061a revert rev 154 but only allow FnCall, AndExpr, or OrExpr in ExpressionsStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 158
diff changeset
743 return parser.failure(null);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
744 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
745
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
746 private Var SettableVar() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
747 int start = parser.begin();
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
748 Var var = VarZ(In.NOTHING);
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
749 if( var==null || !var.isSettable() )
155
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
750 return parser.failure(null);
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
751 return parser.success( var );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
752 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
753
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
754 private Expr RequiredExpr(In in) throws ParseException {
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
755 parser.begin();
211
284eddd599b1 fix parsing bug
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 209
diff changeset
756 return parser.success(required(ExprZ(in),"Bad expression"));
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
757 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
758
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
759 private Expr ExprZ(In in) throws ParseException {
449
e89bf64a0d05 fix parse error
Franklin Schmidt <fschmidt@gmail.com>
parents: 369
diff changeset
760 return OrExpr(in);
19
a7c13c6017f7 add GenericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 18
diff changeset
761 }
a7c13c6017f7 add GenericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 18
diff changeset
762
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
763 private Expr OrExpr(In in) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
764 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
765 Expr exp = AndExpr(in);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
766 if( exp==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
767 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
768 while( Keyword("or") ) {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
769 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
770 Expr exp2 = required(RelExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
771 Expr newExp = new Expr(Val.SINGLE,true);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
772 newExp.add( "(LuanImpl.cnd(t = " );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
773 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
774 newExp.add( ") ? t : (" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
775 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
776 newExp.add( "))" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
777 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
778 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
779 return parser.success(exp);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
780 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
781
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
782 private Expr AndExpr(In in) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
783 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
784 Expr exp = RelExpr(in);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
785 if( exp==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
786 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
787 while( Keyword("and") ) {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
788 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
789 Expr exp2 = required(RelExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
790 Expr newExp = new Expr(Val.SINGLE,true);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
791 newExp.add( "(LuanImpl.cnd(t = " );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
792 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
793 newExp.add( ") ? (" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
794 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
795 newExp.add( ") : t)" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
796 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
797 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
798 return parser.success(exp);
18
3971113699b8 add NumericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 17
diff changeset
799 }
3971113699b8 add NumericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 17
diff changeset
800
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
801 private Expr RelExpr(In in) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
802 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
803 Expr exp = ConcatExpr(in);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
804 if( exp==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
805 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
806 while(true) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
807 if( parser.match("==") ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
808 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
809 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
810 Expr exp2 = required(ConcatExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
811 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
812 newExp.add( "LuanImpl.eq(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
813 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
814 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
815 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
816 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
817 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
818 } else if( parser.match("~=") ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
819 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
820 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
821 Expr exp2 = required(ConcatExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
822 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
823 newExp.add( "!LuanImpl.eq(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
824 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
825 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
826 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
827 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
828 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
829 } else if( parser.match("<=") ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
830 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
831 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
832 Expr exp2 = required(ConcatExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
833 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
834 newExp.add( "LuanImpl.le(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
835 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
836 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
837 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
838 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
839 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
840 } else if( parser.match(">=") ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
841 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
842 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
843 Expr exp2 = required(ConcatExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
844 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
845 newExp.add( "LuanImpl.le(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
846 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
847 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
848 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
849 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
850 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
851 } else if( parser.match("<") ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
852 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
853 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
854 Expr exp2 = required(ConcatExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
855 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
856 newExp.add( "LuanImpl.lt(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
857 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
858 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
859 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
860 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
861 exp = newExp;
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
862 } else if( parser.match(">") ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
863 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
864 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
865 Expr exp2 = required(ConcatExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
866 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
867 newExp.add( "LuanImpl.lt(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
868 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
869 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
870 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
871 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
872 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
873 } else
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
874 break;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
875 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
876 return parser.success(exp);
42
786699c78837 implement try-catch
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
877 }
786699c78837 implement try-catch
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
878
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
879 private Expr ConcatExpr(In in) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
880 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
881 Expr exp = SumExpr(in);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
882 if( exp==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
883 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
884 if( parser.match("..") ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
885 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
886 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
887 Expr exp2 = required(ConcatExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
888 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
889 newExp.add( "LuanImpl.concat(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
890 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
891 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
892 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
893 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
894 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
895 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
896 return parser.success(exp);
28
df923e5835b2 fix local initial assignment
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 26
diff changeset
897 }
df923e5835b2 fix local initial assignment
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 26
diff changeset
898
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
899 private Expr SumExpr(In in) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
900 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
901 Expr exp = TermExpr(in);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
902 if( exp==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
903 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
904 while(true) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
905 if( parser.match('+') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
906 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
907 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
908 Expr exp2 = required(TermExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
909 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
910 newExp.add( "LuanImpl.add(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
911 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
912 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
913 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
914 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
915 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
916 } else if( Minus() ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
917 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
918 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
919 Expr exp2 = required(TermExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
920 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
921 newExp.add( "LuanImpl.sub(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
922 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
923 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
924 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
925 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
926 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
927 } else
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
928 break;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
929 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
930 return parser.success(exp);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
931 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
932
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
933 private boolean Minus() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
934 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
935 return parser.match('-') && !parser.match('-') ? parser.success() : parser.failure();
12
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
936 }
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
937
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
938 private Expr TermExpr(In in) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
939 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
940 Expr exp = UnaryExpr(in);
650
d658eab7bf4c finish compiling operators
Franklin Schmidt <fschmidt@gmail.com>
parents: 649
diff changeset
941 if( exp==null )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
942 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
943 while(true) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
944 if( parser.match('*') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
945 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
946 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
947 Expr exp2 = required(UnaryExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
948 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
949 newExp.add( "LuanImpl.mul(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
950 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
951 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
952 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
953 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
954 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
955 } else if( parser.match('/') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
956 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
957 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
958 Expr exp2 = required(UnaryExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
959 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
960 newExp.add( "LuanImpl.div(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
961 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
962 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
963 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
964 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
965 exp = newExp;
107
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
966 } else if( Mod() ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
967 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
968 exp = exp.single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
969 Expr exp2 = required(UnaryExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
970 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
971 newExp.add( "LuanImpl.mod(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
972 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
973 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
974 newExp.addAll( exp2 );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
975 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
976 exp = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
977 } else
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
978 break;
17
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
979 }
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
980 return parser.success(exp);
17
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
981 }
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
982
107
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
983 private boolean Mod() {
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
984 parser.begin();
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
985 return parser.match('%') && !parser.match('>') ? parser.success() : parser.failure();
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
986 }
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
987
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
988 private Expr UnaryExpr(In in) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
989 parser.begin();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
990 if( parser.match('#') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
991 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
992 Expr exp = required(UnaryExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
993 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
994 newExp.add( "LuanImpl.len(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
995 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
996 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
997 return parser.success(newExp);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
998 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
999 if( Minus() ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1000 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1001 Expr exp = required(UnaryExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1002 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1003 newExp.add( "LuanImpl.unm(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1004 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1005 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1006 return parser.success(newExp);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1007 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1008 if( Keyword("not") ) {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1009 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1010 Expr exp = required(UnaryExpr(in)).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1011 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1012 newExp.add( "!Luan.checkBoolean(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1013 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1014 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1015 return parser.success(newExp);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1016 }
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1017 Expr exp = PowExpr(in);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1018 if( exp==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1019 return parser.failure(null);
650
d658eab7bf4c finish compiling operators
Franklin Schmidt <fschmidt@gmail.com>
parents: 649
diff changeset
1020 return parser.success(exp);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1021 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1022
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1023 private Expr PowExpr(In in) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1024 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1025 Expr exp1 = SingleExpr(in);
657
8081713bf7d9 compile literals
Franklin Schmidt <fschmidt@gmail.com>
parents: 656
diff changeset
1026 if( exp1==null )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1027 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1028 if( parser.match('^') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1029 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1030 Expr exp2 = required(PowExpr(in));
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1031 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1032 newExp.add( "LuanImpl.pow(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1033 newExp.addAll( exp1.single() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1034 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1035 newExp.addAll( exp2.single() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1036 newExp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1037 exp1 = newExp;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1038 }
650
d658eab7bf4c finish compiling operators
Franklin Schmidt <fschmidt@gmail.com>
parents: 649
diff changeset
1039 return parser.success(exp1);
14
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1040 }
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1041
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1042 private Expr SingleExpr(In in) throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1043 parser.begin();
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1044 Expr exp = FunctionExpr();
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1045 if( exp != null )
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1046 return parser.success(exp);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1047 exp = VarExp(in);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1048 if( exp != null )
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1049 return parser.success(exp);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1050 exp = VarArgs();
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1051 if( exp != null )
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1052 return parser.success(exp);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1053 return parser.failure(null);
14
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1054 }
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1055
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1056 private Expr FunctionExpr() throws ParseException {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1057 if( !Keyword("function") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1058 return null;
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1059 return RequiredFunction(null);
20
d85510d92eee add BreakStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 19
diff changeset
1060 }
d85510d92eee add BreakStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 19
diff changeset
1061
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1062 private Expr RequiredFunction(String name) throws ParseException {
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1063 parser.begin();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1064 RequiredMatch('(');
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1065 Spaces();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1066 frame = new Frame(frame);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1067 Stmts stmt = new Stmts();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1068 List<String> names = NameList();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1069 if( names != null ) {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1070 Expr args = new Expr(Val.ARRAY,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1071 args.add( "args" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1072 stmt.addAll( makeLocalSetStmt(names,args) );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1073 if( parser.match(',') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1074 Spaces();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1075 if( !parser.match("...") )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1076 throw parser.exception();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1077 Spaces();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1078 frame.isVarArg = true;
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1079 stmt.add( "final Object[] varArgs = LuanImpl.varArgs(args," + names.size() + "); " );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1080 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1081 } else if( parser.match("...") ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1082 Spaces();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1083 frame.isVarArg = true;
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1084 stmt.add( "final Object[] varArgs = LuanImpl.varArgs(args,0); " );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1085 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1086 RequiredMatch(')');
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1087 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1088 Stmts block = RequiredBlock();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1089 stmt.addAll( block );
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1090 stmt.hasReturn = block.hasReturn;
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1091 Expr fnDef = newFnExp(stmt,name);
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1092 RequiredKeyword("end");
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1093 frame = frame.parent;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1094 return parser.success(fnDef);
11
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
1095 }
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
1096
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1097 private Expr VarArgs() throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1098 parser.begin();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1099 if( !frame.isVarArg || !parser.match("...") )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1100 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1101 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1102 Expr exp = new Expr(Val.ARRAY,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1103 exp.add("varArgs");
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1104 return parser.success(exp);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1105 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1106
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1107 private Expr TableExpr() throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1108 parser.begin();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1109 if( !parser.match('{') )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1110 return parser.failure(null);
682
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1111 Expr tblExp = new Expr(Val.SINGLE,false);
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1112 tblExp.add( "LuanImpl.table(" );
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1113 Expr lastExp = tblExp;
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1114 List<Expr> builder = new ArrayList<Expr>();
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1115 /*
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1116 Spaces();
655
e2be71451d04 compile TableExpr
Franklin Schmidt <fschmidt@gmail.com>
parents: 654
diff changeset
1117 Field(builder);
604
b73f005f3735 table constructor now uses end_of_line as a delimiter
Franklin Schmidt <fschmidt@gmail.com>
parents: 584
diff changeset
1118 while( FieldSep() ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1119 Spaces();
655
e2be71451d04 compile TableExpr
Franklin Schmidt <fschmidt@gmail.com>
parents: 654
diff changeset
1120 Field(builder);
604
b73f005f3735 table constructor now uses end_of_line as a delimiter
Franklin Schmidt <fschmidt@gmail.com>
parents: 584
diff changeset
1121 }
682
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1122 */
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1123 do {
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1124 Spaces(); lastExp.addNewLines();
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1125 Expr exp = Field();
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1126 if( exp != null ) {
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1127 builder.add(exp);
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1128 lastExp = exp;
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1129 Spaces(); lastExp.addNewLines();
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1130 }
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1131 } while( FieldSep() );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1132 Expr exp = TemplateExpressions(In.NOTHING);
245
2ed8465a9d62 allow TemplateExpressions at end of table constructor
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 211
diff changeset
1133 if( exp != null )
2ed8465a9d62 allow TemplateExpressions at end of table constructor
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 211
diff changeset
1134 builder.add(exp);
107
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1135 if( !parser.match('}') )
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1136 throw parser.exception("Expected table element or '}'");
682
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1137 tblExp.addAll( expString(builder).array() );
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1138 tblExp.add( ")" );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1139 Spaces();
682
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1140 tblExp.addNewLines();
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1141 return parser.success( tblExp );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1142 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1143
604
b73f005f3735 table constructor now uses end_of_line as a delimiter
Franklin Schmidt <fschmidt@gmail.com>
parents: 584
diff changeset
1144 private boolean FieldSep() throws ParseException {
b73f005f3735 table constructor now uses end_of_line as a delimiter
Franklin Schmidt <fschmidt@gmail.com>
parents: 584
diff changeset
1145 return parser.anyOf(",;") || EndOfLine();
14
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1146 }
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1147
682
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1148 private Expr Field() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1149 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1150 Expr exp = SubExpr(In.NOTHING);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1151 if( exp==null )
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1152 exp = NameExpr();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1153 if( exp!=null && parser.match('=') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1154 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1155 Expr val = RequiredExpr(In.NOTHING).single();
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1156 Expr newExp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1157 newExp.add( "new TableField(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1158 newExp.addAll( exp );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1159 newExp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1160 newExp.addAll( val );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1161 newExp.add( ")" );
682
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1162 return parser.success(newExp);
17
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
1163 }
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1164 parser.rollback();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1165 Expr exprs = ExprZ(In.NOTHING);
154
c2e5101682ae Expr extends Expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 153
diff changeset
1166 if( exprs != null ) {
682
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1167 return parser.success(exprs);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1168 }
682
0c334975d526 finish stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 681
diff changeset
1169 return parser.failure(null);
7
bca8fc5d928b work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 6
diff changeset
1170 }
bca8fc5d928b work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 6
diff changeset
1171
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1172 private Expr VarExp(In in) throws ParseException {
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
1173 Var var = VarZ(in);
656
471be4752b9e compiling
Franklin Schmidt <fschmidt@gmail.com>
parents: 655
diff changeset
1174 return var==null ? null : var.exp();
8
8896068e0a4b finish operators
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 7
diff changeset
1175 }
8896068e0a4b finish operators
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 7
diff changeset
1176
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
1177 private Var VarZ(In in) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1178 parser.begin();
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1179 Var var = VarStart(in);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1180 if( var==null )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1181 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1182 Var var2;
656
471be4752b9e compiling
Franklin Schmidt <fschmidt@gmail.com>
parents: 655
diff changeset
1183 while( (var2=Var2(in,var.exp())) != null ) {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1184 var = var2;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1185 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1186 return parser.success(var);
7
bca8fc5d928b work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 6
diff changeset
1187 }
bca8fc5d928b work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 6
diff changeset
1188
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1189 private Var VarStart(In in) throws ParseException {
206
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1190 if( parser.match('(') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1191 Spaces();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1192 Expr exp = RequiredExpr(in).single();
206
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1193 RequiredMatch(')');
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1194 Spaces();
206
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1195 return exprVar(exp);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1196 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1197 String name = Name();
206
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1198 if( name != null )
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1199 return nameVar(name);
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1200 Expr exp;
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1201 exp = TableExpr();
206
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1202 if( exp != null )
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1203 return exprVar(exp);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1204 exp = Literal();
206
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1205 if( exp != null )
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1206 return exprVar(exp);
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1207 return null;
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
1208 }
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 20
diff changeset
1209
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1210 private Var Var2(In in,Expr exp1) throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1211 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1212 Expr exp2 = SubExpr(in);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1213 if( exp2 != null )
656
471be4752b9e compiling
Franklin Schmidt <fschmidt@gmail.com>
parents: 655
diff changeset
1214 return parser.success(indexVar(exp1,exp2));
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1215 if( parser.match('.') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1216 Spaces();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1217 exp2 = NameExpr();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1218 if( exp2!=null )
656
471be4752b9e compiling
Franklin Schmidt <fschmidt@gmail.com>
parents: 655
diff changeset
1219 return parser.success(indexVar(exp1,exp2));
636
13b390bfed32 parser fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 604
diff changeset
1220 return parser.failure(null);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1221 }
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1222 Expr fnCall = Args( in, exp1, new ArrayList<Expr>() );
206
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1223 if( fnCall != null )
77365c9fdfe4 remove -> operator
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 203
diff changeset
1224 return parser.success(exprVar(fnCall));
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1225 return parser.failure(null);
9
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1226 }
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1227
503
92c3d22745b8 make _ENV optional
Franklin Schmidt <fschmidt@gmail.com>
parents: 460
diff changeset
1228 private interface Var {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1229 public Expr exp() throws ParseException;
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1230 // public Settable settable() throws ParseException;
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1231 public boolean isSettable();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1232 public Stmts set(Expr val) throws ParseException;
503
92c3d22745b8 make _ENV optional
Franklin Schmidt <fschmidt@gmail.com>
parents: 460
diff changeset
1233 }
92c3d22745b8 make _ENV optional
Franklin Schmidt <fschmidt@gmail.com>
parents: 460
diff changeset
1234
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1235 private Expr env() {
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1236 Sym sym = getSym("_ENV");
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1237 if( sym != null )
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1238 return sym.exp();
503
92c3d22745b8 make _ENV optional
Franklin Schmidt <fschmidt@gmail.com>
parents: 460
diff changeset
1239 return null;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1240 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1241
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1242 private Var nameVar(final String name) {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1243 return new Var() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1244
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1245 public Expr exp() throws ParseException {
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1246 Sym sym = getSym(name);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1247 if( sym != null )
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1248 return sym.exp();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1249 Expr envExpr = env();
503
92c3d22745b8 make _ENV optional
Franklin Schmidt <fschmidt@gmail.com>
parents: 460
diff changeset
1250 if( envExpr != null )
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1251 return indexExpStr( envExpr, constExpStr(name) );
503
92c3d22745b8 make _ENV optional
Franklin Schmidt <fschmidt@gmail.com>
parents: 460
diff changeset
1252 parser.failure(null);
92c3d22745b8 make _ENV optional
Franklin Schmidt <fschmidt@gmail.com>
parents: 460
diff changeset
1253 throw parser.exception("name '"+name+"' not defined");
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1254 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1255
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1256 public boolean isSettable() {
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1257 return true;
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1258 }
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1259
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1260 public Stmts set(Expr val) throws ParseException {
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1261 Sym sym = getSym(name);
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1262 if( sym != null ) {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1263 Stmts stmt = new Stmts();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1264 stmt.addAll( sym.exp() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1265 stmt.add( " = " );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1266 stmt.addAll( val.single() );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1267 stmt.add( "; " );
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1268 return stmt;
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1269 }
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1270 Expr envExpr = env();
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1271 if( envExpr != null )
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1272 return indexVar( envExpr, constExpStr(name) ).set(val);
687
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 684
diff changeset
1273 parser.failure(null);
fc08c3b42010 add theme_to_luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 684
diff changeset
1274 throw parser.exception("name '"+name+"' not defined");
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1275 }
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1276 };
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1277 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1278
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1279 private Var exprVar(final Expr expr) {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1280 return new Var() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1281
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1282 public Expr exp() {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1283 return expr;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1284 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1285
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1286 public boolean isSettable() {
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1287 return false;
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1288 }
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1289
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1290 public Stmts set(Expr val) {
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1291 throw new RuntimeException();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1292 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1293 };
11
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
1294 }
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
1295
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1296 private Var indexVar(final Expr table,final Expr key) {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1297 return new Var() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1298
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1299 public Expr exp() {
656
471be4752b9e compiling
Franklin Schmidt <fschmidt@gmail.com>
parents: 655
diff changeset
1300 return indexExpStr( table, key );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1301 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1302
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1303 public boolean isSettable() {
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1304 return true;
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1305 }
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1306
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1307 public Stmts set(Expr val) {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1308 Stmts stmt = new Stmts();
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1309 stmt.add( "LuanImpl.put(luan," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1310 stmt.addAll( table.single() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1311 stmt.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1312 stmt.addAll( key.single() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1313 stmt.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1314 stmt.addAll( val.single() );
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1315 stmt.add( "); " );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1316 return stmt;
660
e064377994b2 compile table put
Franklin Schmidt <fschmidt@gmail.com>
parents: 658
diff changeset
1317 }
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1318 };
9
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1319 }
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1320
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1321 private Expr Args(In in,Expr fn,List<Expr> builder) throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1322 parser.begin();
129
486a0641bca4 add pickle client/server;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 128
diff changeset
1323 return args(in,builder)
656
471be4752b9e compiling
Franklin Schmidt <fschmidt@gmail.com>
parents: 655
diff changeset
1324 ? parser.success( callExpStr( fn, expString(builder) ) )
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1325 : parser.failure((Expr)null);
107
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1326 }
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1327
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1328 private boolean args(In in,List<Expr> builder) throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1329 parser.begin();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1330 if( parser.match('(') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1331 Spaces();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1332 ExpList(in,builder); // optional
107
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1333 if( !parser.match(')') )
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1334 throw parser.exception("Expression or ')' expected");
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1335 Spaces();
195
24ede40ee0aa make MetatableGetter DeepCloneable, scoped, and secure
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 193
diff changeset
1336 return parser.success();
107
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1337 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1338 Expr exp = TableExpr();
107
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1339 if( exp != null ) {
655
e2be71451d04 compile TableExpr
Franklin Schmidt <fschmidt@gmail.com>
parents: 654
diff changeset
1340 builder.add(exp);
195
24ede40ee0aa make MetatableGetter DeepCloneable, scoped, and secure
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 193
diff changeset
1341 return parser.success();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1342 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1343 String s = StringLiteral();
107
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1344 if( s != null ) {
657
8081713bf7d9 compile literals
Franklin Schmidt <fschmidt@gmail.com>
parents: 656
diff changeset
1345 builder.add( constExpStr(s) );
195
24ede40ee0aa make MetatableGetter DeepCloneable, scoped, and secure
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 193
diff changeset
1346 return parser.success();
107
dbf459397217 change OutputStatement to JspExpressions;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 106
diff changeset
1347 }
195
24ede40ee0aa make MetatableGetter DeepCloneable, scoped, and secure
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 193
diff changeset
1348 return parser.failure();
11
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
1349 }
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
1350
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1351 private Expr ExpStringList(In in) throws ParseException {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1352 List<Expr> builder = new ArrayList<Expr>();
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
1353 return ExpList(in,builder) ? expString(builder) : null;
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1354 }
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1355
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1356 private boolean ExpList(In in,List<Expr> builder) throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1357 parser.begin();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1358 Expr exp = TemplateExpressions(in);
158
cced1c4d3575 only allow TemplateExpressions at end of expr list;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 157
diff changeset
1359 if( exp != null ) {
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
1360 builder.add(exp);
158
cced1c4d3575 only allow TemplateExpressions at end of expr list;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 157
diff changeset
1361 return parser.success();
cced1c4d3575 only allow TemplateExpressions at end of expr list;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 157
diff changeset
1362 }
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
1363 exp = ExprZ(in);
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
1364 if( exp==null )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1365 return parser.failure();
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
1366 builder.add(exp);
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1367 while( parser.match(',') ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1368 Spaces();
158
cced1c4d3575 only allow TemplateExpressions at end of expr list;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 157
diff changeset
1369 exp = TemplateExpressions(in);
cced1c4d3575 only allow TemplateExpressions at end of expr list;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 157
diff changeset
1370 if( exp != null ) {
654
ea7dbd2dfa65 compile TemplateStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 653
diff changeset
1371 builder.add(exp);
158
cced1c4d3575 only allow TemplateExpressions at end of expr list;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 157
diff changeset
1372 return parser.success();
cced1c4d3575 only allow TemplateExpressions at end of expr list;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 157
diff changeset
1373 }
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1374 builder.add( RequiredExpr(in) );
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1375 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1376 return parser.success();
9
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1377 }
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1378
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1379 private Expr SubExpr(In in) throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1380 parser.begin();
209
239c8d650028 convert returned arrays to tables for java methods
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 206
diff changeset
1381 if( !parser.match('[') || parser.test("[") || parser.test("=") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1382 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1383 Spaces();
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1384 Expr exp = RequiredExpr(In.NOTHING).single();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1385 RequiredMatch(']');
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1386 Spaces();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1387 return parser.success(exp);
11
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
1388 }
b7d7069fee58 add assignment statement and CmdLine
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 9
diff changeset
1389
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1390 private Expr NameExpr() throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1391 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1392 String name = Name();
195
24ede40ee0aa make MetatableGetter DeepCloneable, scoped, and secure
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 193
diff changeset
1393 if( name==null )
24ede40ee0aa make MetatableGetter DeepCloneable, scoped, and secure
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 193
diff changeset
1394 return parser.failure(null);
656
471be4752b9e compiling
Franklin Schmidt <fschmidt@gmail.com>
parents: 655
diff changeset
1395 return parser.success(constExpStr(name));
54
f5b27ef14d73 add OutputStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 51
diff changeset
1396 }
f5b27ef14d73 add OutputStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 51
diff changeset
1397
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1398 private String RequiredName() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1399 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1400 String name = Name();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1401 if( name==null )
139
3b384dc5ca91 replace WebShell.java with web_shell.luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 137
diff changeset
1402 throw parser.exception("Name expected");
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1403 return parser.success(name);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1404 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1405
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1406 private String Name() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1407 int start = parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1408 if( !NameFirstChar() )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1409 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1410 while( NameChar() );
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1411 String match = parser.textFrom(start);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1412 if( keywords.contains(match) )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1413 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1414 Spaces();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1415 return parser.success(match);
17
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
1416 }
09d41f7490a8 add local variables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 16
diff changeset
1417
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1418 private boolean NameChar() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1419 return NameFirstChar() || Digit();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1420 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1421
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1422 private boolean NameFirstChar() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1423 return parser.inCharRange('a', 'z') || parser.inCharRange('A', 'Z') || parser.match('_');
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1424 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1425
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1426 private void RequiredMatch(char c) throws ParseException {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1427 if( !parser.match(c) )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1428 throw parser.exception("'"+c+"' expected");
9
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1429 }
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1430
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1431 private void RequiredMatch(String s) throws ParseException {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1432 if( !parser.match(s) )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1433 throw parser.exception("'"+s+"' expected");
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1434 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1435
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1436 private void RequiredKeyword(String keyword) throws ParseException {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1437 if( !Keyword(keyword) )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1438 throw parser.exception("'"+keyword+"' expected");
9
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1439 }
600676034a1a add variables and tables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 8
diff changeset
1440
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1441 private boolean Keyword(String keyword) throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1442 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1443 if( !parser.match(keyword) || NameChar() )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1444 return parser.failure();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1445 Spaces();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1446 return parser.success();
12
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1447 }
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1448
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1449 private static final Set<String> keywords = new HashSet<String>(Arrays.asList(
12
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1450 "and",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1451 "break",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1452 "do",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1453 "else",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1454 "elseif",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1455 "end",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1456 "false",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1457 "for",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1458 "function",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1459 "goto",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1460 "if",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1461 "in",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1462 "local",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1463 "nil",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1464 "not",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1465 "or",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1466 "repeat",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1467 "return",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1468 "then",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1469 "true",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1470 "until",
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1471 "while"
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1472 ));
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1473
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1474 private Expr Literal() throws ParseException {
645
859c0dedc8b6 remove LuanSource
Franklin Schmidt <fschmidt@gmail.com>
parents: 636
diff changeset
1475 parser.begin();
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1476 if( NilLiteral() ) {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1477 Expr exp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1478 exp.add( "null" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1479 return parser.success(exp);
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1480 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1481 Boolean b = BooleanLiteral();
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1482 if( b != null ) {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1483 Expr exp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1484 exp.add( b.toString() );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1485 return parser.success(exp);
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1486 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1487 Number n = NumberLiteral();
657
8081713bf7d9 compile literals
Franklin Schmidt <fschmidt@gmail.com>
parents: 656
diff changeset
1488 if( n != null ) {
8081713bf7d9 compile literals
Franklin Schmidt <fschmidt@gmail.com>
parents: 656
diff changeset
1489 String s = n.toString();
8081713bf7d9 compile literals
Franklin Schmidt <fschmidt@gmail.com>
parents: 656
diff changeset
1490 if( n instanceof Long )
8081713bf7d9 compile literals
Franklin Schmidt <fschmidt@gmail.com>
parents: 656
diff changeset
1491 s += "L";
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1492 Expr exp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1493 exp.add( s );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1494 return parser.success(exp);
657
8081713bf7d9 compile literals
Franklin Schmidt <fschmidt@gmail.com>
parents: 656
diff changeset
1495 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1496 String s = StringLiteral();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1497 if( s != null )
656
471be4752b9e compiling
Franklin Schmidt <fschmidt@gmail.com>
parents: 655
diff changeset
1498 return parser.success(constExpStr(s));
195
24ede40ee0aa make MetatableGetter DeepCloneable, scoped, and secure
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 193
diff changeset
1499 return parser.failure(null);
5
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1500 }
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1501
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1502 private static int STR_LIM = 65000;
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1503
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1504 private Expr constExpStr(String s) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1505 int n = 0;
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1506 int from = 0;
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1507 while( (from = s.indexOf('\n',from) + 1) != 0 ) {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1508 n++;
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1509 }
664
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1510 s = s
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1511 .replace("\\","\\\\")
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1512 .replace("\"","\\\"")
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1513 .replace("\n","\\n")
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1514 .replace("\r","\\r")
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1515 .replace("\t","\\t")
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1516 .replace("\b","\\b")
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1517 ;
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1518 if( s.length() > STR_LIM ) {
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1519 int len = s.length();
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1520 StringBuilder sb = new StringBuilder();
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1521 sb.append( "LuanImpl.strconcat(" );
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1522 int start = 0;
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1523 while(true) {
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1524 int end = start + STR_LIM;
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1525 if( end >= len )
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1526 break;
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1527 sb.append( "\"" ).append( s.substring(start,end) ).append( "\"," );
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1528 start = end;
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1529 }
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1530 sb.append( "\"" ).append( s.substring(start) ).append( "\")" );
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1531 s = sb.toString();
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1532 } else
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1533 s = "\"" + s + "\"";
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1534 while( n-- > 0 )
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1535 s += "\n";
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1536 Expr exp = new Expr(Val.SINGLE,false);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1537 exp.add( s );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1538 return exp;
664
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1539 }
71f8f5075df8 compile FnDef
Franklin Schmidt <fschmidt@gmail.com>
parents: 663
diff changeset
1540
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1541 private boolean NilLiteral() throws ParseException {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1542 return Keyword("nil");
65
1ff53a88579a multi-line statements
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 60
diff changeset
1543 }
1ff53a88579a multi-line statements
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 60
diff changeset
1544
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1545 private Boolean BooleanLiteral() throws ParseException {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1546 if( Keyword("true") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1547 return true;
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1548 if( Keyword("false") )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1549 return false;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1550 return null;
5
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1551 }
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1552
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1553 private Number NumberLiteral() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1554 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1555 Number n;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1556 if( parser.matchIgnoreCase("0x") ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1557 n = HexNumber();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1558 } else {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1559 n = DecNumber();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1560 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1561 if( n==null || NameChar() )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1562 return parser.failure(null);
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1563 Spaces();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1564 return parser.success(n);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1565 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1566
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1567 private Number DecNumber() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1568 int start = parser.begin();
535
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1569 boolean isInt = true;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1570 if( Int() ) {
535
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1571 if( parser.match('.') ) {
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1572 isInt = false;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1573 Int(); // optional
535
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1574 }
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1575 } else if( parser.match('.') && Int() ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1576 // ok
535
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1577 isInt = false;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1578 } else
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1579 return parser.failure(null);
535
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1580 if( Exponent() ) // optional
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1581 isInt = false;
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1582 String s = parser.textFrom(start);
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1583 if( isInt ) {
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1584 try {
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1585 return parser.success(Integer.valueOf(s));
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1586 } catch(NumberFormatException e) {}
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1587 try {
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1588 return parser.success(Long.valueOf(s));
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1589 } catch(NumberFormatException e) {}
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1590 }
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1591 return parser.success(Double.valueOf(s));
5
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1592 }
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1593
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1594 private boolean Exponent() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1595 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1596 if( !parser.matchIgnoreCase("e") )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1597 return parser.failure();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1598 parser.anyOf("+-"); // optional
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1599 if( !Int() )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1600 return parser.failure();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1601 return parser.success();
5
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1602 }
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1603
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1604 private boolean Int() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1605 if( !Digit() )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1606 return false;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1607 while( Digit() );
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1608 return true;
5
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1609 }
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1610
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1611 private boolean Digit() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1612 return parser.inCharRange('0', '9');
16
2a30281ef47c finish number literals;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 15
diff changeset
1613 }
2a30281ef47c finish number literals;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 15
diff changeset
1614
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1615 private Number HexNumber() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1616 int start = parser.begin();
535
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1617 long nLong = 0;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1618 double n;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1619 if( HexInt() ) {
535
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1620 nLong = Long.parseLong(parser.textFrom(start),16);
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1621 n = (double)nLong;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1622 if( parser.match('.') ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1623 start = parser.currentIndex();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1624 if( HexInt() ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1625 String dec = parser.textFrom(start);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1626 n += (double)Long.parseLong(dec,16) / Math.pow(16,dec.length());
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1627 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1628 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1629 } else if( parser.match('.') && HexInt() ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1630 String dec = parser.textFrom(start+1);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1631 n = (double)Long.parseLong(dec,16) / Math.pow(16,dec.length());
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1632 } else {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1633 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1634 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1635 if( parser.matchIgnoreCase("p") ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1636 parser.anyOf("+-"); // optional
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1637 start = parser.currentIndex();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1638 if( !HexInt() )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1639 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1640 n *= Math.pow(2,(double)Long.parseLong(parser.textFrom(start)));
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1641 }
535
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1642 if( nLong == n ) {
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1643 int nInt = (int)nLong;
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1644 if( nInt == nLong )
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1645 return parser.success(Integer.valueOf(nInt));
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1646 return parser.success(Long.valueOf(nLong));
289908469e02 parse numeric constants to ints or longs if possible
Franklin Schmidt <fschmidt@gmail.com>
parents: 534
diff changeset
1647 }
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1648 return parser.success(Double.valueOf(n));
16
2a30281ef47c finish number literals;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 15
diff changeset
1649 }
2a30281ef47c finish number literals;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 15
diff changeset
1650
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1651 private boolean HexInt() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1652 if( !HexDigit() )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1653 return false;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1654 while( HexDigit() );
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1655 return true;
16
2a30281ef47c finish number literals;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 15
diff changeset
1656 }
2a30281ef47c finish number literals;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 15
diff changeset
1657
2a30281ef47c finish number literals;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 15
diff changeset
1658
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1659 private boolean HexDigit() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1660 return Digit() || parser.anyOf("abcdefABCDEF");
6
a315783c9524 more parsing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 5
diff changeset
1661 }
a315783c9524 more parsing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 5
diff changeset
1662
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1663 private String StringLiteral() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1664 String s;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1665 if( (s=QuotedString('"'))==null
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1666 && (s=QuotedString('\''))==null
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1667 && (s=LongString())==null
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1668 )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1669 return null;
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1670 Spaces();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1671 return s;
16
2a30281ef47c finish number literals;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 15
diff changeset
1672 }
2a30281ef47c finish number literals;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 15
diff changeset
1673
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1674 private String LongString() throws ParseException {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1675 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1676 if( !parser.match('[') )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1677 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1678 int start = parser.currentIndex();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1679 while( parser.match('=') );
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1680 int nEquals = parser.currentIndex() - start;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1681 if( !parser.match('[') )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1682 return parser.failure(null);
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1683 MatchEndOfLine();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1684 start = parser.currentIndex();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1685 while( !LongBracketsEnd(nEquals) ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1686 if( !parser.anyChar() )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1687 throw parser.exception("Unclosed long string");
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1688 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1689 String s = parser.text.substring( start, parser.currentIndex() - nEquals - 2 );
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1690 return parser.success(s);
6
a315783c9524 more parsing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 5
diff changeset
1691 }
a315783c9524 more parsing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 5
diff changeset
1692
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1693 private String QuotedString(char quote) throws ParseException {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1694 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1695 if( !parser.match(quote) )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1696 return parser.failure(null);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1697 StringBuilder buf = new StringBuilder();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1698 while( !parser.match(quote) ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1699 Character c = EscSeq();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1700 if( c != null ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1701 buf.append(c);
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1702 } else {
271
82a3ebcfbafa add internal tests
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 260
diff changeset
1703 if( parser.test('\r') || parser.test('\n') || !parser.anyChar() )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1704 throw parser.exception("Unclosed string");
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1705 buf.append(parser.lastChar());
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1706 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1707 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1708 return parser.success(buf.toString());
6
a315783c9524 more parsing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 5
diff changeset
1709 }
a315783c9524 more parsing
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 5
diff changeset
1710
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1711 private Character EscSeq() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1712 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1713 if( !parser.match('\\') )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1714 return parser.failure(null);
155
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1715 if( parser.match('a') ) return parser.success('\u0007');
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1716 if( parser.match('b') ) return parser.success('\b');
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1717 if( parser.match('f') ) return parser.success('\f');
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1718 if( parser.match('n') ) return parser.success('\n');
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1719 if( parser.match('r') ) return parser.success('\r');
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1720 if( parser.match('t') ) return parser.success('\t');
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1721 if( parser.match('v') ) return parser.success('\u000b');
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1722 if( parser.match('\\') ) return parser.success('\\');
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1723 if( parser.match('"') ) return parser.success('"');
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1724 if( parser.match('\'') ) return parser.success('\'');
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1725 int start = parser.currentIndex();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1726 if( parser.match('x') && HexDigit() && HexDigit() )
155
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1727 return parser.success((char)Integer.parseInt(parser.textFrom(start+1),16));
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1728 if( Digit() ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1729 if( Digit() ) Digit(); // optional
155
db7b3902e01c fix parsing problems
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 154
diff changeset
1730 return parser.success((char)Integer.parseInt(parser.textFrom(start)));
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1731 }
684
41f791e4206d bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 682
diff changeset
1732 if( MatchEndOfLine() ) {
271
82a3ebcfbafa add internal tests
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 260
diff changeset
1733 return parser.success('\n');
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1734 }
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1735 return parser.failure(null);
14
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1736 }
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1737
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1738 private void Spaces() throws ParseException {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1739 while( parser.anyOf(" \t") || Comment() || ContinueOnNextLine() );
14
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1740 }
2ddf85634d20 whitespace handling;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 12
diff changeset
1741
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1742 private boolean ContinueOnNextLine() {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1743 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1744 return parser.match('\\') && EndOfLine() ? parser.success() : parser.failure();
7
bca8fc5d928b work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 6
diff changeset
1745 }
bca8fc5d928b work on expressions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 6
diff changeset
1746
247
b5995d77878a fix parsing of comments
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 245
diff changeset
1747 private boolean Comment() throws ParseException {
b5995d77878a fix parsing of comments
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 245
diff changeset
1748 if( LongComment() )
b5995d77878a fix parsing of comments
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 245
diff changeset
1749 return true;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1750 if( parser.match("--") ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1751 while( parser.noneOf("\r\n") );
247
b5995d77878a fix parsing of comments
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 245
diff changeset
1752 return true;
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1753 }
247
b5995d77878a fix parsing of comments
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 245
diff changeset
1754 return false;
18
3971113699b8 add NumericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 17
diff changeset
1755 }
3971113699b8 add NumericForStmt
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 17
diff changeset
1756
247
b5995d77878a fix parsing of comments
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 245
diff changeset
1757 private boolean LongComment() throws ParseException {
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1758 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1759 if( !parser.match("--[") )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1760 return parser.failure();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1761 int start = parser.currentIndex();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1762 while( parser.match('=') );
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1763 int nEquals = parser.currentIndex() - start;
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1764 if( !parser.match('[') )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1765 return parser.failure();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1766 while( !LongBracketsEnd(nEquals) ) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1767 if( !(EndOfLine() || parser.anyChar()) )
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1768 throw parser.exception("Unclosed comment");
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1769 }
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1770 parser.upSb();
104
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1771 return parser.success();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1772 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1773
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1774 private boolean LongBracketsEnd(int nEquals) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1775 parser.begin();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1776 if( !parser.match(']') )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1777 return parser.failure();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1778 while( nEquals-- > 0 ) {
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1779 if( !parser.match('=') )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1780 return parser.failure();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1781 }
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1782 if( !parser.match(']') )
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1783 return parser.failure();
754e6030c029 remove parboiled and rewrite parser;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 99
diff changeset
1784 return parser.success();
12
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1785 }
9cea1aea5eef CmdLine can run files
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 11
diff changeset
1786
648
e387e4021afe start compiler with len operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 645
diff changeset
1787
e387e4021afe start compiler with len operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 645
diff changeset
1788
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1789 private class ParseList extends ArrayList {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1790
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1791 void addNewLines() {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1792 if( parser.sb().length() > 0 ) {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1793 add( parser.sb().toString() );
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1794 parser.sb().setLength(0);
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1795 /*
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1796 if( parser.sourceName.equals("stdin") ) {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1797 StringWriter sw = new StringWriter();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1798 new Throwable().printStackTrace(new PrintWriter(sw,true));
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1799 // add(sw.toString());
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1800 }
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1801 */
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1802 }
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1803 }
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1804
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1805 ParseList() {
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1806 addNewLines();
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1807 }
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1808
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1809 @Override public boolean add(Object obj) {
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1810 if( obj instanceof List ) throw new RuntimeException();
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1811 return super.add(obj);
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1812 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1813
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1814 @Override public void add(int index,Object obj) {
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1815 if( obj instanceof List ) throw new RuntimeException();
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1816 super.add(index,obj);
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1817 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1818
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1819 @Override public String toString() {
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1820 StringBuilder sb = new StringBuilder();
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1821 for( Object o : this ) {
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1822 sb.append( o.toString() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1823 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1824 return sb.toString();
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1825 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1826 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1827
648
e387e4021afe start compiler with len operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 645
diff changeset
1828
676
Franklin Schmidt <fschmidt@gmail.com>
parents: 675
diff changeset
1829 private static AtomicInteger classCounter = new AtomicInteger();
648
e387e4021afe start compiler with len operator
Franklin Schmidt <fschmidt@gmail.com>
parents: 645
diff changeset
1830
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1831 private enum Val { SINGLE, ARRAY }
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1832
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1833 private class Expr extends ParseList {
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1834 final Val valType;
649
37f0cf43f191 UnaryExpr now compiled
Franklin Schmidt <fschmidt@gmail.com>
parents: 648
diff changeset
1835 final boolean isStmt;
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1836
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1837 Expr(Val valType,boolean isStmt) {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1838 this.valType = valType;
649
37f0cf43f191 UnaryExpr now compiled
Franklin Schmidt <fschmidt@gmail.com>
parents: 648
diff changeset
1839 this.isStmt = isStmt;
37f0cf43f191 UnaryExpr now compiled
Franklin Schmidt <fschmidt@gmail.com>
parents: 648
diff changeset
1840 }
37f0cf43f191 UnaryExpr now compiled
Franklin Schmidt <fschmidt@gmail.com>
parents: 648
diff changeset
1841
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1842 Expr single() {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1843 if( valType==Val.SINGLE )
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1844 return this;
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1845 Expr exp = new Expr(Val.SINGLE,isStmt);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1846 exp.add( valType==Val.ARRAY ? "LuanImpl.first(" : "Luan.first(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1847 exp.addAll( this );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1848 exp.add( ")" );
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1849 return exp;
649
37f0cf43f191 UnaryExpr now compiled
Franklin Schmidt <fschmidt@gmail.com>
parents: 648
diff changeset
1850 }
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1851
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1852 Expr array() {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1853 if( valType==Val.ARRAY )
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1854 return this;
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1855 Expr exp = new Expr(Val.ARRAY,isStmt);
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1856 if( valType==Val.SINGLE ) {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1857 exp.add( "new Object[]{" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1858 exp.addAll( this );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1859 exp.add( "}" );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1860 } else {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1861 exp.add( "Luan.array(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1862 exp.addAll( this );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1863 exp.add( ")" );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1864 }
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1865 return exp;
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1866 }
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1867
650
d658eab7bf4c finish compiling operators
Franklin Schmidt <fschmidt@gmail.com>
parents: 649
diff changeset
1868 }
d658eab7bf4c finish compiling operators
Franklin Schmidt <fschmidt@gmail.com>
parents: 649
diff changeset
1869
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1870 private Expr expString(List<Expr> list) {
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1871 Expr exp = new Expr(Val.ARRAY,false);
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1872 switch(list.size()) {
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1873 case 0:
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1874 exp.add("LuanFunction.NOTHING");
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1875 return exp;
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1876 case 1:
653
538b0ae08faa compile IfStmt and BreakStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 652
diff changeset
1877 return list.get(0);
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1878 default:
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1879 int lastI = list.size() - 1;
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1880 exp.add( "new Object[]{" );
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1881 for( int i=0; i<lastI; i++ ) {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1882 exp.addAll( list.get(i).single() );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1883 exp.add( "," );
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1884 }
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1885 Expr last = list.get(lastI);
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1886 if( last.valType==Val.SINGLE ) {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1887 exp.addAll( last );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1888 exp.add( "}" );
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1889 } else {
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1890 exp.add( "}" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1891 exp.add( 0, "LuanImpl.concatArgs(" );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1892 exp.add( "," );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1893 exp.addAll( last );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1894 exp.add( ")" );
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1895 }
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1896 return exp;
652
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1897 }
067d9470184d compile SetStmt and ForStmt
Franklin Schmidt <fschmidt@gmail.com>
parents: 651
diff changeset
1898 }
657
8081713bf7d9 compile literals
Franklin Schmidt <fschmidt@gmail.com>
parents: 656
diff changeset
1899
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1900 private class Stmts extends ParseList {
663
b438a47196bc finish compiling function blocks
Franklin Schmidt <fschmidt@gmail.com>
parents: 662
diff changeset
1901 boolean hasReturn = false;
651
140cc5191b7a start compiling statements
Franklin Schmidt <fschmidt@gmail.com>
parents: 650
diff changeset
1902 }
140cc5191b7a start compiling statements
Franklin Schmidt <fschmidt@gmail.com>
parents: 650
diff changeset
1903
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1904 private Class toFnClass(Stmts stmts,List<UpSym> upValueSymbols) {
676
Franklin Schmidt <fschmidt@gmail.com>
parents: 675
diff changeset
1905 String className = "EXP" + classCounter.incrementAndGet();
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1906 String classCode = toFnString(stmts,upValueSymbols,className);
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1907 try {
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1908 //System.out.println(parser.sourceName);
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1909 //System.out.println(classCode);
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1910 return LuanJavaCompiler.compile("luan.impl."+className,parser.sourceName,classCode);
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1911 } catch(ClassNotFoundException e) {
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1912 throw new RuntimeException(e);
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1913 }
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1914 }
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1915
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1916 private String toFnString(Stmts stmts,List<UpSym> upValueSymbols) {
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1917 String className = "EXP" + classCounter.incrementAndGet();
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1918 return toFnString(stmts,upValueSymbols,className);
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1919 }
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1920
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1921 private String toFnString(Stmts stmts,List<UpSym> upValueSymbols,String className) {
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1922 if( !stmts.hasReturn )
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1923 stmts.add( "\nreturn LuanFunction.NOTHING;" );
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1924 return ""
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1925 +"package luan.impl; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1926 +"import luan.Luan; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1927 +"import luan.LuanFunction; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1928 +"import luan.LuanState; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1929 +"import luan.LuanJava; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1930 +"import luan.LuanException; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1931 +"import luan.modules.PackageLuan; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1932
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1933 +"public class " + className +" extends Closure { "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1934 +"public "+className+"(LuanJava java) throws LuanException { "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1935 +"super("+upValueSymbols.size()+",java); "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1936 + init(upValueSymbols)
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1937 +"} "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1938
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1939 +"@Override public Object doCall(LuanState luan,Object[] args) throws LuanException { "
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
1940 +"final Pointer[] parentUpValues = upValues; "
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1941 +"Object t; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1942 +"Object[] a; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1943 + stmts
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1944 +"\n} "
663
b438a47196bc finish compiling function blocks
Franklin Schmidt <fschmidt@gmail.com>
parents: 662
diff changeset
1945 +"}\n"
b438a47196bc finish compiling function blocks
Franklin Schmidt <fschmidt@gmail.com>
parents: 662
diff changeset
1946 ;
b438a47196bc finish compiling function blocks
Franklin Schmidt <fschmidt@gmail.com>
parents: 662
diff changeset
1947 }
b438a47196bc finish compiling function blocks
Franklin Schmidt <fschmidt@gmail.com>
parents: 662
diff changeset
1948
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1949 private Expr toFnExp(Stmts stmt,List<UpSym> upValueSymbols,String name) {
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1950 stmt.addNewLines();
678
49f3d290bebd add luan_to_java
Franklin Schmidt <fschmidt@gmail.com>
parents: 677
diff changeset
1951 if( !stmt.hasReturn )
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1952 stmt.add( "return LuanFunction.NOTHING; " );
674
2994e46f62b7 some optimization
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
1953 Expr exp = new Expr(Val.SINGLE,false);
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1954 exp.add( ""
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1955 +"new Closure("+upValueSymbols.size()+",java) { "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1956 +"{ "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1957 + init(upValueSymbols)
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1958 +"} "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1959 +"@Override public Object doCall(LuanState luan,Object[] args) throws LuanException { "
681
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1960 );
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1961 if( name != null ) {
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1962 exp.add( ""
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1963 +"return _" + name + "(luan,args); "
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1964 +"} "
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1965 +"private Object _" + name + "(LuanState luan,Object[] args) throws LuanException { "
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1966 );
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1967 }
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 680
diff changeset
1968 exp.add( ""
688
f99f51bc5bea fix up-values
Franklin Schmidt <fschmidt@gmail.com>
parents: 687
diff changeset
1969 +"final Pointer[] parentUpValues = upValues; "
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1970 +"Object t; "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1971 +"Object[] a; "
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1972 );
677
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1973 exp.addAll( stmt );
Franklin Schmidt <fschmidt@gmail.com>
parents: 676
diff changeset
1974 exp.add( ""
679
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1975 +"} "
43522473599d make java line numbers match
Franklin Schmidt <fschmidt@gmail.com>
parents: 678
diff changeset
1976 +"} "
666
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1977 );
2f449ccf54d2 use lists to assemble source
Franklin Schmidt <fschmidt@gmail.com>
parents: 665
diff changeset
1978 return exp;
665
41f8fdbc3a0a compile modules
Franklin Schmidt <fschmidt@gmail.com>
parents: 664
diff changeset
1979 }
41f8fdbc3a0a compile modules
Franklin Schmidt <fschmidt@gmail.com>
parents: 664
diff changeset
1980
670
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1981 private static String init(List<UpSym> upValueSymbols) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1982 StringBuilder sb = new StringBuilder();
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1983 for( UpSym upSym : upValueSymbols ) {
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1984 sb.append( upSym.init() );
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1985 }
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1986 return sb.toString();
58ebfec6178b all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents: 669
diff changeset
1987 }
663
b438a47196bc finish compiling function blocks
Franklin Schmidt <fschmidt@gmail.com>
parents: 662
diff changeset
1988
5
9ef0fd711101 start LuaParser
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
1989 }