]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Genie: Support array and string slices
authorJamie McCracken <jamie.mccrack gmail com>
Mon, 24 May 2010 18:21:18 +0000 (14:21 -0400)
committerJamie McCracken <jamie.mccrack gmail com>
Mon, 24 May 2010 19:26:23 +0000 (15:26 -0400)
vala/valagenieparser.vala

index 3a25d6b3885f3542f8296d194e337f2668b8fe3a..76e057ecf7629d7dff7f26bae89846569d425cb9 100644 (file)
@@ -897,13 +897,22 @@ public class Vala.Genie.Parser : CodeVisitor {
        Expression parse_element_access (SourceLocation begin, Expression inner) throws ParseError {
                expect (TokenType.OPEN_BRACKET);
                var index_list = parse_expression_list ();
+               Expression? stop = null;
+               if (index_list.size == 1 && accept (TokenType.COLON)) {
+                       // slice expression
+                       stop = parse_expression ();
+               }
                expect (TokenType.CLOSE_BRACKET);
 
-               var expr = new ElementAccess (inner, get_src (begin));
-               foreach (Expression index in index_list) {
-                       expr.append_index (index);
+               if (stop == null) {
+                       var expr = new ElementAccess (inner, get_src (begin));
+                       foreach (Expression index in index_list) {
+                               expr.append_index (index);
+                       }
+                       return expr;
+               } else {
+                       return new SliceExpression (inner, index_list[0], stop, get_src (begin));
                }
-               return expr;
        }
 
        List<Expression> parse_expression_list () throws ParseError {