[Vala] genie # comments



I have written my first patch for the vala compiler... well, to be exact
it is only for the genie syntax parser.

The attached patch adds support for python-like comments for the Genie
compiler. This way it is possible to do things like that:

$ cat vala/test.gs
# Here is another comment
init  # in the middle of foo
       # This is a comment
       print "Hello World"

Can somebody review the patch? I think that '#'-like comments looks better
for a syntax like Genie, than using // and /*/*/. My patch just adds support
for this new kind of comments (does not removes the support for // or /*)

--pancake
diff --git a/vala/valageniescanner.vala b/vala/valageniescanner.vala
index d28ff76..f008c76 100644
--- a/vala/valageniescanner.vala
+++ b/vala/valageniescanner.vala
@@ -459,7 +459,6 @@ public class Vala.Genie.Scanner {
                        pending_dedents--;
                        indent_level--;
 
-
                        token_begin.pos = current;
                        token_begin.line = line;
                        token_begin.column = column;
@@ -946,10 +945,9 @@ public class Vala.Genie.Scanner {
 
        int count_tabs ()
        {
-               
                int tab_count = 0;
 
-
+               comment();
                if (_indent_spaces == 0) {
                        while (current < end && current[0] == '\t') {
                                current++;
@@ -963,13 +961,10 @@ public class Vala.Genie.Scanner {
                                column++;
                                space_count++;
                        }
-                       
                        tab_count = space_count / _indent_spaces;
-               
                }
 
                /* ignore comments and whitspace and other lines that contain no code */
-
                space ();
 
                if ((current < end) && (current[0] == '\n')) return -1;
@@ -1030,8 +1025,15 @@ public class Vala.Genie.Scanner {
        }
 
        bool comment () {
+               // check for python-like single line comments
+               if (current[0]=='#') {
+                       while (current < end && current[0] != '\n') {
+                               current++;
+                       }
+                       return false;
+               }
                if (current > end - 2
-                   || current[0] != '/'
+                               || current[0] != '/'
                    || (current[1] != '/' && current[1] != '*')) {
                        return false;
                }
@@ -1057,14 +1059,12 @@ public class Vala.Genie.Scanner {
                        current += 2;
                        char* begin = current;
                        int begin_line = line;
-                       while (current < end - 1
-                              && (current[0] != '*' || current[1] != '/')) {
+                       while (current < end - 1 && (current[0] != '*' || current[1] != '/')) {
                                if (current[0] == '\n') {
                                        line++;
-                                       column = 0;
-                               }
+                                       column = 1;
+                               } else column++;
                                current++;
-                               column++;
                        }
                        if (current == end - 1) {
                                Report.error (new SourceReference (source_file, line, column, line, column), 
"syntax error, expected */");
@@ -1100,9 +1100,6 @@ public class Vala.Genie.Scanner {
                }
        }
 
-
-
-
        void push_comment (string comment_item, bool file_comment) {
                if (_comment == null) {
                        _comment = comment_item;
@@ -1136,7 +1133,7 @@ public class Vala.Genie.Scanner {
                return result_builder.str;
        }
        
-               bool pp_whitespace () {
+       bool pp_whitespace () {
                bool found = false;
                while (current < end && current[0].isspace () && current[0] != '\n') {
                        found = true;


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