Added optional indent attribute to allow spaces to be used in lieu of tabs
authorJamie McCracken <jamiemcc@gnome.org>
Tue, 27 May 2008 04:32:16 +0000 (04:32 +0000)
committerJamie McCracken <jamiemcc@src.gnome.org>
Tue, 27 May 2008 04:32:16 +0000 (04:32 +0000)
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

svn path=/trunk/; revision=1456

ChangeLog
vala/valagenieparser.vala
vala/valageniescanner.vala

index 05a4c37..39db469 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,14 @@
 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 
 
index f58a96e..fa5989c 100644 (file)
@@ -346,6 +346,21 @@ public class Vala.Genie.Parser : CodeVisitor {
                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) {
index 080db74..d7410bb 100644 (file)
@@ -30,6 +30,8 @@ using Gee;
 public class Vala.Genie.Scanner : Object {
        public SourceFile source_file { get; construct; }
 
+       public int indent_spaces { get;set;}
+
        char* begin;
        char* current;
        char* end;
@@ -45,6 +47,8 @@ public class Vala.Genie.Scanner : Object {
        bool parse_started;
 
        string _comment;
+       
+       
 
        public Scanner (SourceFile source_file) {
                this.source_file = source_file;
@@ -56,6 +60,7 @@ public class Vala.Genie.Scanner : Object {
 
                current = begin;
 
+               _indent_spaces = 0;
                line = 1;
                column = 1;
                current_indent_level = 0;
@@ -423,9 +428,11 @@ public class Vala.Genie.Scanner : Object {
                }
 
 
-               /* 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;
@@ -863,14 +870,27 @@ public class Vala.Genie.Scanner : Object {
 
        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 */