diff src/luan/interp/LuaParser.java @ 42:786699c78837

implement try-catch git-svn-id: https://luan-java.googlecode.com/svn/trunk@43 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 23 Dec 2012 06:36:56 +0000
parents e3624b7cd603
children 57054fa43189
line wrap: on
line diff
--- a/src/luan/interp/LuaParser.java	Fri Dec 21 19:34:50 2012 +0000
+++ b/src/luan/interp/LuaParser.java	Sun Dec 23 06:36:56 2012 +0000
@@ -223,6 +223,7 @@
 					BreakStmt(),
 					GenericForStmt(),
 					NumericForStmt(),
+					TryStmt(),
 					DoStmt(),
 					WhileStmt(),
 					RepeatStmt(),
@@ -316,6 +317,16 @@
 		);
 	}
 
+	Rule TryStmt() {
+		return Sequence(
+			Keyword("try"), Block(),
+			Keyword("catch"), Name(), addSymbol( (String)pop() ),
+			Keyword("do"), Block(), Keyword("end"),
+			push( new TryStmt( (Stmt)pop(1), symbolsSize()-1, (Stmt)pop() ) ),
+			popSymbols(1)
+		);
+	}
+
 	Rule DoStmt() {
 		return Sequence(
 			Keyword("do"), Block(), Keyword("end")
@@ -827,6 +838,7 @@
 	static final Set<String> keywords = new HashSet<String>(Arrays.asList(
 		"and",
 		"break",
+		"catch",
 		"do",
 		"else",
 		"elseif",
@@ -847,6 +859,7 @@
 		"then",
 		"to",
 		"true",
+		"try",
 		"until",
 		"while"
 	));