OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/regexp/regexp-parser.h" | 5 #include "src/regexp/regexp-parser.h" |
6 | 6 |
7 #include "src/char-predicates-inl.h" | 7 #include "src/char-predicates-inl.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 // * a lookbehind assertion '(?<=' '(?<!' | 693 // * a lookbehind assertion '(?<=' '(?<!' |
694 // * or a named capture '(?<'. | 694 // * or a named capture '(?<'. |
695 // | 695 // |
696 // Of these, only named captures are capturing groups. | 696 // Of these, only named captures are capturing groups. |
697 if (!FLAG_harmony_regexp_named_captures) break; | 697 if (!FLAG_harmony_regexp_named_captures) break; |
698 | 698 |
699 Advance(); | 699 Advance(); |
700 if (current() != '<') break; | 700 if (current() != '<') break; |
701 | 701 |
702 if (FLAG_harmony_regexp_lookbehind) { | 702 if (FLAG_harmony_regexp_lookbehind) { |
703 // TODO(jgruber): To be more future-proof we could test for | |
704 // IdentifierStart here once it becomes clear whether group names | |
705 // allow unicode escapes. | |
706 // https://github.com/tc39/proposal-regexp-named-groups/issues/23 | |
707 Advance(); | 703 Advance(); |
708 if (current() == '=' || current() == '!') break; | 704 if (current() == '=' || current() == '!') break; |
709 } | 705 } |
710 | 706 |
711 // Found a possible named capture. It could turn out to be a syntax | 707 // Found a possible named capture. It could turn out to be a syntax |
712 // error (e.g. an unterminated or invalid name), but that distinction | 708 // error (e.g. an unterminated or invalid name), but that distinction |
713 // does not matter for our purposes. | 709 // does not matter for our purposes. |
714 has_named_captures_ = true; | 710 has_named_captures_ = true; |
715 } | 711 } |
716 capture_count++; | 712 capture_count++; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 const ScanMode scan_mode = ScanMode::FORCE_COMBINE_SURROGATE_PAIRS; | 772 const ScanMode scan_mode = ScanMode::FORCE_COMBINE_SURROGATE_PAIRS; |
777 Advance(scan_mode); | 773 Advance(scan_mode); |
778 | 774 |
779 bool at_start = true; | 775 bool at_start = true; |
780 while (true) { | 776 while (true) { |
781 uc32 c = current(); | 777 uc32 c = current(); |
782 Advance(scan_mode); | 778 Advance(scan_mode); |
783 | 779 |
784 // Convert unicode escapes. | 780 // Convert unicode escapes. |
785 if (c == '\\' && current() == 'u') { | 781 if (c == '\\' && current() == 'u') { |
786 // TODO(jgruber): Reconsider this once the spec has settled. | |
787 // https://github.com/tc39/proposal-regexp-named-groups/issues/23 | |
788 Advance(scan_mode); | 782 Advance(scan_mode); |
789 if (!ParseUnicodeEscape(&c)) { | 783 if (!ParseUnicodeEscape(&c)) { |
790 ReportError(CStrVector("Invalid Unicode escape sequence")); | 784 ReportError(CStrVector("Invalid Unicode escape sequence")); |
791 return nullptr; | 785 return nullptr; |
792 } | 786 } |
793 } | 787 } |
794 | 788 |
795 // The backslash char is misclassified as both ID_Start and ID_Continue. | 789 // The backslash char is misclassified as both ID_Start and ID_Continue. |
796 if (c == '\\') { | 790 if (c == '\\') { |
797 ReportError(CStrVector("Invalid capture group name")); | 791 ReportError(CStrVector("Invalid capture group name")); |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1872 return false; | 1866 return false; |
1873 } | 1867 } |
1874 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), | 1868 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), |
1875 zone()); | 1869 zone()); |
1876 LAST(ADD_TERM); | 1870 LAST(ADD_TERM); |
1877 return true; | 1871 return true; |
1878 } | 1872 } |
1879 | 1873 |
1880 } // namespace internal | 1874 } // namespace internal |
1881 } // namespace v8 | 1875 } // namespace v8 |
OLD | NEW |