[vala] dova: Add support for object literals
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] dova: Add support for object literals
- Date: Sat, 3 Jul 2010 11:10:39 +0000 (UTC)
commit a222e923b82fc00fcac1a66ca1ebab41d7165bce
Author: Jürg Billeter <j bitron ch>
Date: Sat Jul 3 09:23:08 2010 +0200
dova: Add support for object literals
vala/valaparser.vala | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 4c767ee..b5b85cf 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -636,6 +636,14 @@ public class Vala.Parser : CodeVisitor {
case TokenType.OPEN_BRACKET:
expr = parse_element_access (begin, expr);
break;
+ case TokenType.OPEN_BRACE:
+ var ma = expr as MemberAccess;
+ if (context.profile == Profile.DOVA && ma != null) {
+ expr = parse_object_literal (begin, ma);
+ } else {
+ found = false;
+ }
+ break;
case TokenType.OP_INC:
expr = parse_post_increment_expression (begin, expr);
break;
@@ -851,6 +859,27 @@ public class Vala.Parser : CodeVisitor {
return expr;
}
+ Expression parse_object_literal (SourceLocation begin, MemberAccess member) throws ParseError {
+ member.creation_member = true;
+
+ var expr = new ObjectCreationExpression (member, get_src (begin));
+
+ expect (TokenType.OPEN_BRACE);
+
+ do {
+ var member_begin = get_location ();
+ string id = parse_identifier ();
+ expect (TokenType.COLON);
+ var member_expr = parse_expression ();
+
+ expr.add_member_initializer (new MemberInitializer (id, member_expr, get_src (member_begin)));
+ } while (accept (TokenType.COMMA));
+
+ expect (TokenType.CLOSE_BRACE);
+
+ return expr;
+ }
+
Expression parse_array_creation_expression (SourceLocation begin, MemberAccess member) throws ParseError {
bool size_specified = false;
List<Expression> size_specifier_list = null;
@@ -3391,6 +3420,7 @@ public class Vala.Parser : CodeVisitor {
case TokenType.OPEN_PARENS:
case TokenType.CLOSE_PARENS:
case TokenType.CLOSE_BRACKET:
+ case TokenType.OPEN_BRACE:
case TokenType.COLON:
case TokenType.SEMICOLON:
case TokenType.COMMA:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]