Add support for python-like comments
Submitted by pancake
Link to original bug (#589475)
Description
I wrote this patch to make Genie support comments like in python (starting with '#'). The problem is that compiler directives are also using this syntax, should we try to find a way to workaround the difference between compiler directives and comments.
I push the patch here, somebody can be interested on it.
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;