[vala/switch-to-gir: 26/47] girparser: Support negative integer literals in metadata.



commit 7849fd0115ddaf8972af1d0f7520d88a1acf7e07
Author: Luca Bruno <lucabru src gnome org>
Date:   Fri Dec 24 14:03:39 2010 +0100

    girparser: Support negative integer literals in metadata.

 vala/valagirparser.vala |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index ec5dced..b470721 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -200,9 +200,17 @@ public class Vala.GirParser : CodeVisitor {
 		}
 
 		public int get_integer (ArgumentType arg) {
-			var lit = get_expression (arg) as IntegerLiteral;
-			if (lit != null) {
-				return lit.value.to_int ();
+			var unary = get_expression (arg) as UnaryExpression;
+			if (unary != null && unary.operator == UnaryOperator.MINUS) {
+				var lit = unary.inner as IntegerLiteral;
+				if (lit != null) {
+					return -lit.value.to_int ();
+				}
+			} else {
+				var lit = get_expression (arg) as IntegerLiteral;
+				if (lit != null) {
+					return lit.value.to_int ();
+				}
 			}
 
 			return 0;
@@ -401,6 +409,7 @@ public class Vala.GirParser : CodeVisitor {
 		}
 
 		Expression? parse_expression () {
+			var begin = this.begin;
 			var src = get_current_src ();
 			Expression expr = null;
 			switch (current) {
@@ -413,6 +422,15 @@ public class Vala.GirParser : CodeVisitor {
 			case TokenType.FALSE:
 				expr = new BooleanLiteral (false, src);
 				break;
+			case TokenType.MINUS:
+				next ();
+				var inner = parse_expression ();
+				if (inner == null) {
+					Report.error (src, "expected expression after `-', got `%s'".printf (current.to_string ()));
+				} else {
+					expr = new UnaryExpression (UnaryOperator.MINUS, inner, get_src (begin));
+				}
+				return expr;
 			case TokenType.INTEGER_LITERAL:
 				expr = new IntegerLiteral (get_string (), src);
 				break;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]