]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Accept numbers with characters as identifiers where possible
authorJürg Billeter <j@bitron.ch>
Thu, 15 Jan 2009 09:18:37 +0000 (09:18 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 15 Jan 2009 09:18:37 +0000 (09:18 +0000)
2009-01-15  Jürg Billeter  <j@bitron.ch>

* vala/valaparser.vala:

Accept numbers with characters as identifiers where possible

svn path=/trunk/; revision=2341

ChangeLog
vala/valaparser.vala

index b4c02f0e82f7578354b5b6c800b2f4445e4c15aa..90af4f2449f681dfc65ec4baef56426a002ac8b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-01-15  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaparser.vala:
+
+       Accept numbers with characters as identifiers where possible
+
 2009-01-14  Jürg Billeter  <j@bitron.ch>
 
        * vala/valacodewriter.vala:
index c5bed7fe9d96e8e7b2848f83f3046c326a61e736..d2e85282ae0d86361286d6c057a5aa01e6c95106 100644 (file)
@@ -131,6 +131,10 @@ public class Vala.Parser : CodeVisitor {
                return tokens[index].begin;
        }
 
+       string get_current_string () {
+               return ((string) tokens[index].begin.pos).ndup ((tokens[index].end.pos - tokens[index].begin.pos));
+       }
+
        string get_last_string () {
                int last_index = (index + BUFFER_SIZE - 1) % BUFFER_SIZE;
                return ((string) tokens[last_index].begin.pos).ndup ((tokens[last_index].end.pos - tokens[last_index].begin.pos));
@@ -239,9 +243,21 @@ public class Vala.Parser : CodeVisitor {
                case TokenType.YIELDS:
                        next ();
                        return;
-               default:
-                       throw new ParseError.SYNTAX (get_error ("expected identifier"));
+               case TokenType.INTEGER_LITERAL:
+               case TokenType.REAL_LITERAL:
+                       // also accept integer and real literals
+                       // as long as they contain at least one character
+                       // and no decimal point
+                       // for example, 2D and 3D
+                       string id = get_current_string ();
+                       if (id[id.length - 1].isalpha () && !("." in id)) {
+                               next ();
+                               return;
+                       }
+                       break;
                }
+
+               throw new ParseError.SYNTAX (get_error ("expected identifier"));
        }
 
        string parse_identifier () throws ParseError {
@@ -249,7 +265,7 @@ public class Vala.Parser : CodeVisitor {
                return get_last_string ();
        }
 
-               Expression parse_literal () throws ParseError {
+       Expression parse_literal () throws ParseError {
                var begin = get_location ();
 
                switch (current ()) {