comparison src/luan/interp/LuanParser.java @ 54:f5b27ef14d73

add OutputStmt git-svn-id: https://luan-java.googlecode.com/svn/trunk@55 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 31 Dec 2012 19:45:06 +0000
parents 28dfd91a816c
children 9381b23ea9e1
comparison
equal deleted inserted replaced
53:54a61d1dc070 54:f5b27ef14d73
219 Rule Stmt(Var<List<Stmt>> stmts) { 219 Rule Stmt(Var<List<Stmt>> stmts) {
220 return FirstOf( 220 return FirstOf(
221 LocalStmt(stmts), 221 LocalStmt(stmts),
222 Sequence( 222 Sequence(
223 FirstOf( 223 FirstOf(
224 OutputStmt(),
224 ReturnStmt(), 225 ReturnStmt(),
225 FunctionStmt(), 226 FunctionStmt(),
226 LocalFunctionStmt(), 227 LocalFunctionStmt(),
227 BreakStmt(), 228 BreakStmt(),
228 GenericForStmt(), 229 GenericForStmt(),
235 SetStmt(), 236 SetStmt(),
236 ExpressionsStmt() 237 ExpressionsStmt()
237 ), 238 ),
238 stmts.get().add( (Stmt)pop() ) 239 stmts.get().add( (Stmt)pop() )
239 ) 240 )
241 );
242 }
243
244 Rule OutputStmt() {
245 Var<Integer> start = new Var<Integer>();
246 Var<ExpList.Builder> builder = new Var<ExpList.Builder>(new ExpList.Builder());
247 return Sequence(
248 start.set(currentIndex()),
249 "%>", Optional( EndOfLine() ),
250 ZeroOrMore(
251 FirstOf(
252 Sequence(
253 OneOrMore(
254 TestNot("<%"),
255 ANY
256 ),
257 addToExpList(builder.get(),new ConstExpr(match()))
258 ),
259 Sequence(
260 "<%=", Spaces(),
261 Expr(),
262 addToExpList(builder.get()),
263 "%>"
264 )
265 )
266 ),
267 "<%", Spaces(),
268 push( new OutputStmt( se(start.get()), builder.get().build() ) )
240 ); 269 );
241 } 270 }
242 271
243 Rule ReturnStmt() { 272 Rule ReturnStmt() {
244 Var<Integer> start = new Var<Integer>(); 273 Var<Integer> start = new Var<Integer>();
791 if( obj instanceof Expressions ) { 820 if( obj instanceof Expressions ) {
792 bld.add( (Expressions)obj ); 821 bld.add( (Expressions)obj );
793 } else { 822 } else {
794 bld.add( (Expr)obj ); 823 bld.add( (Expr)obj );
795 } 824 }
825 return true;
826 }
827
828 boolean addToExpList(ExpList.Builder bld, Expr expr) {
829 bld.add(expr);
796 return true; 830 return true;
797 } 831 }
798 832
799 Rule SubExpr() { 833 Rule SubExpr() {
800 return Sequence( '[', incParens(), Spaces(), Expr(), ']', decParens(), Spaces() ); 834 return Sequence( '[', incParens(), Spaces(), Expr(), ']', decParens(), Spaces() );