From: Jamie McCracken Date: Tue, 5 Jan 2010 23:25:03 +0000 (-0500) Subject: Genie: support automatic line continuations X-Git-Tag: 0.7.10~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2cb6ff6a3be10be012a3ed7baaf5bab8601e679;p=thirdparty%2Fvala.git Genie: support automatic line continuations --- diff --git a/vala/valageniescanner.vala b/vala/valageniescanner.vala index b9b023824..4bcdb5bf0 100644 --- a/vala/valageniescanner.vala +++ b/vala/valageniescanner.vala @@ -41,6 +41,10 @@ public class Vala.Genie.Scanner { int current_indent_level; int indent_level; int pending_dedents; + + /* track open parens and braces for automatic line continuations */ + int open_parens_count; + int open_brace_count; TokenType last_token; bool parse_started; @@ -69,6 +73,9 @@ public class Vala.Genie.Scanner { current_indent_level = 0; indent_level = 0; pending_dedents = 0; + + open_parens_count = 0; + open_brace_count = 0; parse_started = false; last_token = TokenType.NONE; @@ -482,12 +489,21 @@ public class Vala.Genie.Scanner { space (); } - /* handle line continuation (lines ending with \) */ + + /* handle explicit line continuation (lines ending with "\") */ while (current < end && current[0] == '\\' && current[1] == '\n') { current += 2; line++; skip_space_tabs (); } + + /* handle automatic line continuations (when inside parens or braces) */ + while (current < end && current[0] == '\n' && (open_parens_count > 0 || open_brace_count > 0)) { + current++; + line++; + skip_space_tabs (); + } + /* handle non-consecutive new line once parsing is underway - EOL */ if (newline () && parse_started && last_token != TokenType.EOL && last_token != TokenType.SEMICOLON) { @@ -638,18 +654,22 @@ public class Vala.Genie.Scanner { switch (current[0]) { case '{': type = TokenType.OPEN_BRACE; + open_brace_count++; current++; break; case '}': type = TokenType.CLOSE_BRACE; + open_brace_count--; current++; break; case '(': type = TokenType.OPEN_PARENS; + open_parens_count++; current++; break; case ')': type = TokenType.CLOSE_PARENS; + open_parens_count--; current++; break; case '[':