[vala] Support newlines in double quoted string literals
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Support newlines in double quoted string literals
- Date: Tue, 29 Jun 2010 20:54:09 +0000 (UTC)
commit 651485173ee809f4a2e75e4a64cec335bd67ec66
Author: Jürg Billeter <j bitron ch>
Date: Tue Jun 29 22:52:54 2010 +0200
Support newlines in double quoted string literals
codegen/valaccodebasemodule.vala | 2 +-
vala/valascanner.vala | 14 ++++++++++----
2 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 6614107..4e54057 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3506,7 +3506,7 @@ public class Vala.CCodeBaseModule : CCodeModule {
}
public override void visit_string_literal (StringLiteral expr) {
- expr.ccodenode = new CCodeConstant.string (expr.value);
+ expr.ccodenode = new CCodeConstant.string (expr.value.replace ("\n", "\\n"));
}
public override void visit_regex_literal (RegexLiteral expr) {
diff --git a/vala/valascanner.vala b/vala/valascanner.vala
index 19b1e09..30f24df 100644
--- a/vala/valascanner.vala
+++ b/vala/valascanner.vala
@@ -706,7 +706,10 @@ public class Vala.Scanner {
break;
}
} else if (current[0] == '\n') {
- break;
+ current++;
+ line++;
+ column = 1;
+ token_length_in_chars = 1;
} else {
unichar u = ((string) current).get_char_validated ((long) (end - current));
if (u != (unichar) (-1)) {
@@ -718,7 +721,7 @@ public class Vala.Scanner {
}
}
}
- if (current >= end || current[0] == '\n') {
+ if (current >= end) {
Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected \"");
state_stack.length--;
return read_token (out token_begin, out token_end);
@@ -1129,7 +1132,10 @@ public class Vala.Scanner {
break;
}
} else if (current[0] == '\n') {
- break;
+ current++;
+ line++;
+ column = 1;
+ token_length_in_chars = 1;
} else {
if (type == TokenType.STRING_LITERAL && source_file.context.profile == Profile.DOVA && current[0] == '$') {
// string template
@@ -1148,7 +1154,7 @@ public class Vala.Scanner {
}
}
}
- if (current < end && current[0] != '\n') {
+ if (current < end) {
current++;
} else {
Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected %c".printf (begin[0]));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]