comparison src/luan/interp/LuaParser.java @ 24:7ee247560db5

add VarArgs git-svn-id: https://luan-java.googlecode.com/svn/trunk@25 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 06 Dec 2012 04:40:54 +0000
parents c93d8c781853
children 0e406bd9ac7b
comparison
equal deleted inserted replaced
23:2446c1755d9b 24:7ee247560db5
26 static final class Frame { 26 static final class Frame {
27 final Frame parent; 27 final Frame parent;
28 final List<String> symbols = new ArrayList<String>(); 28 final List<String> symbols = new ArrayList<String>();
29 int stackSize = 0; 29 int stackSize = 0;
30 int loops = 0; 30 int loops = 0;
31 boolean isVarArg = false;
31 32
32 Frame(Frame parent) { 33 Frame(Frame parent) {
33 this.parent = parent; 34 this.parent = parent;
34 } 35 }
35 } 36 }
103 FirstOf( 104 FirstOf(
104 Sequence( ExpList(), EOI ), 105 Sequence( ExpList(), EOI ),
105 Sequence( 106 Sequence(
106 Block(), 107 Block(),
107 EOI, 108 EOI,
108 push( new Chunk( (Stmt)pop(), frame.stackSize, 0 ) ) 109 push( new Chunk( (Stmt)pop(), frame.stackSize, 0, false ) )
109 ) 110 )
110 ) 111 )
111 ); 112 );
112 } 113 }
113 114
389 } 390 }
390 return true; 391 return true;
391 } 392 }
392 393
393 Rule Expr() { 394 Rule Expr() {
394 return OrExpr(); 395 return FirstOf(
396 VarArgs(),
397 OrExpr()
398 );
395 } 399 }
396 400
397 Rule OrExpr() { 401 Rule OrExpr() {
398 return Sequence( 402 return Sequence(
399 AndExpr(), 403 AndExpr(),
486 } 490 }
487 491
488 Rule Function() { 492 Rule Function() {
489 return Sequence( 493 return Sequence(
490 action( frame = new Frame(frame) ), 494 action( frame = new Frame(frame) ),
491 '(', incParens(), Spaces(), Optional(NameList()), ')', decParens(), Spaces(), Block(), Keyword("end"), 495 '(', incParens(), Spaces(),
492 push( new Chunk( (Stmt)pop(), frame.stackSize, symbolsSize() ) ), 496 Optional(
497 FirstOf(
498 Sequence( NameList(), Optional( ',', Spaces(), VarArgName() ) ),
499 VarArgName()
500 )
501 ),
502 ')', decParens(), Spaces(), Block(), Keyword("end"),
503 push( new Chunk( (Stmt)pop(), frame.stackSize, symbolsSize(), frame.isVarArg ) ),
493 action( frame = frame.parent ) 504 action( frame = frame.parent )
505 );
506 }
507
508 Rule VarArgName() {
509 return Sequence(
510 "...", Spaces(),
511 action( frame.isVarArg = true )
512 );
513 }
514
515 Rule VarArgs() {
516 return Sequence(
517 "...", Spaces(),
518 frame.isVarArg,
519 push( VarArgs.INSTANCE )
494 ); 520 );
495 } 521 }
496 522
497 Rule TableExpr() { 523 Rule TableExpr() {
498 return Sequence( 524 return Sequence(