[vala/staging: 2/3] scanner: Accept backreferences \1 through \99 in regex literals



commit de5bd62298cb18b3a5b9d1eca37d27546937535e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed May 16 11:13:19 2018 +0200

    scanner: Accept backreferences \1 through \99 in regex literals
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728574

 tests/Makefile.am           |    1 +
 tests/parser/bug728574.vala |    3 +++
 vala/valageniescanner.vala  |   12 +++++++++++-
 vala/valascanner.vala       |   12 +++++++++++-
 4 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 21e80f9..943e8fe 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -457,6 +457,7 @@ TESTS = \
        parser/unsupported-property-async.test \
        parser/unsupported-property-throws.test \
        parser/yield-method.test \
+       parser/bug728574.vala \
        parser/bug749576.vala \
        semantic/constant-extern.test \
        semantic/constant-value.test \
diff --git a/tests/parser/bug728574.vala b/tests/parser/bug728574.vala
new file mode 100644
index 0000000..01fe545
--- /dev/null
+++ b/tests/parser/bug728574.vala
@@ -0,0 +1,3 @@
+void main () {
+       var r = 
/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
+}
diff --git a/vala/valageniescanner.vala b/vala/valageniescanner.vala
index 5ada03a..5eb15f0 100644
--- a/vala/valageniescanner.vala
+++ b/vala/valageniescanner.vala
@@ -240,7 +240,17 @@ public class Vala.Genie.Scanner {
                                                        }
                                                        break;
                                                default:
-                                                       Report.error (get_source_reference 
(token_length_in_chars), "invalid escape sequence");
+                                                       // back references \1 through \99
+                                                       if (current[0].isdigit ()) {
+                                                               current++;
+                                                               token_length_in_chars++;
+                                                               if (current[0].isdigit ()) {
+                                                                       current++;
+                                                                       token_length_in_chars++;
+                                                               }
+                                                       } else {
+                                                               Report.error (get_source_reference 
(token_length_in_chars), "invalid escape sequence");
+                                                       }
                                                        break;
                                                }
                                        } else if (current[0] == '\n') {
diff --git a/vala/valascanner.vala b/vala/valascanner.vala
index 9af17dc..718b654 100644
--- a/vala/valascanner.vala
+++ b/vala/valascanner.vala
@@ -242,7 +242,17 @@ public class Vala.Scanner {
                                                        }
                                                        break;
                                                default:
-                                                       Report.error (get_source_reference 
(token_length_in_chars), "invalid escape sequence");
+                                                       // back references \1 through \99
+                                                       if (current[0].isdigit ()) {
+                                                               current++;
+                                                               token_length_in_chars++;
+                                                               if (current[0].isdigit ()) {
+                                                                       current++;
+                                                                       token_length_in_chars++;
+                                                               }
+                                                       } else {
+                                                               Report.error (get_source_reference 
(token_length_in_chars), "invalid escape sequence");
+                                                       }
                                                        break;
                                                }
                                        } else if (current[0] == '\n') {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]