2008-05-27 Jamie McCracken <jamiemcc@gnome.org>
* vala/valagenieparser.vala:
+ * vala/valageniescanner.vala:
+
+ Added optional indent attribute to allow spaces to be used in lieu of tabs for indents
+
+
+2008-05-27 Jamie McCracken <jamiemcc@gnome.org>
+
+ * vala/valagenieparser.vala:
Made GLib using directive optional
next ();
try {
+ var begin = get_location ();
+ /* see if there is an indent attribute */
+ if (accept (TokenType.OPEN_BRACKET)) {
+ var id = parse_identifier ();
+ if (id == "indent") {
+ expect (TokenType.ASSIGN);
+ expect (TokenType.INTEGER_LITERAL);
+ scanner.indent_spaces = get_last_string().to_int();
+ expect (TokenType.CLOSE_BRACKET);
+ expect (TokenType.EOL);
+ } else {
+ rollback (begin);
+ }
+ }
+
parse_using_directives ();
parse_declarations (context.root, true);
} catch (ParseError e) {
public class Vala.Genie.Scanner : Object {
public SourceFile source_file { get; construct; }
+ public int indent_spaces { get;set;}
+
char* begin;
char* current;
char* end;
bool parse_started;
string _comment;
+
+
public Scanner (SourceFile source_file) {
this.source_file = source_file;
current = begin;
+ _indent_spaces = 0;
line = 1;
column = 1;
current_indent_level = 0;
}
- /* scrub whitespace (excluding newlines) and comments */
- space ();
-
+ if ((_indent_spaces == 0 ) || (last_token != TokenType.EOL)) {
+ /* scrub whitespace (excluding newlines) and comments */
+ space ();
+ }
+
/* handle line continuation */
while (current < end && current[0] == '\\' && current[1] == '\n') {
current += 2;
int count_tabs ()
{
+
int tab_count = 0;
- while (current < end && current[0] == '\t') {
- current++;
- column++;
- tab_count++;
- }
+ if (_indent_spaces == 0) {
+ while (current < end && current[0] == '\t') {
+ current++;
+ column++;
+ tab_count++;
+ }
+ } else {
+ int space_count = 0;
+ while (current < end && current[0] == ' ') {
+ current++;
+ column++;
+ space_count++;
+ }
+
+ tab_count = space_count / _indent_spaces;
+
+ }
/* ignore comments and whitspace and other lines that contain no code */