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 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 // * a lookbehind assertion '(?<=' '(?<!' | 696 // * a lookbehind assertion '(?<=' '(?<!' |
697 // * or a named capture '(?<'. | 697 // * or a named capture '(?<'. |
698 // | 698 // |
699 // Of these, only named captures are capturing groups. | 699 // Of these, only named captures are capturing groups. |
700 if (!FLAG_harmony_regexp_named_captures) break; | 700 if (!FLAG_harmony_regexp_named_captures) break; |
701 | 701 |
702 Advance(); | 702 Advance(); |
703 if (current() != '<') break; | 703 if (current() != '<') break; |
704 | 704 |
705 if (FLAG_harmony_regexp_lookbehind) { | 705 if (FLAG_harmony_regexp_lookbehind) { |
706 // TODO(jgruber): To be more future-proof we could test for | |
707 // IdentifierStart here once it becomes clear whether group names | |
708 // allow unicode escapes. | |
709 // https://github.com/tc39/proposal-regexp-named-groups/issues/23 | |
710 Advance(); | 706 Advance(); |
711 if (current() == '=' || current() == '!') break; | 707 if (current() == '=' || current() == '!') break; |
712 } | 708 } |
713 | 709 |
714 // Found a possible named capture. It could turn out to be a syntax | 710 // Found a possible named capture. It could turn out to be a syntax |
715 // error (e.g. an unterminated or invalid name), but that distinction | 711 // error (e.g. an unterminated or invalid name), but that distinction |
716 // does not matter for our purposes. | 712 // does not matter for our purposes. |
717 has_named_captures_ = true; | 713 has_named_captures_ = true; |
718 } | 714 } |
719 capture_count++; | 715 capture_count++; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 ZoneVector<uc16>* name = | 769 ZoneVector<uc16>* name = |
774 new (zone()->New(sizeof(ZoneVector<uc16>))) ZoneVector<uc16>(zone()); | 770 new (zone()->New(sizeof(ZoneVector<uc16>))) ZoneVector<uc16>(zone()); |
775 | 771 |
776 bool at_start = true; | 772 bool at_start = true; |
777 while (true) { | 773 while (true) { |
778 uc32 c = current(); | 774 uc32 c = current(); |
779 Advance(); | 775 Advance(); |
780 | 776 |
781 // Convert unicode escapes. | 777 // Convert unicode escapes. |
782 if (c == '\\' && current() == 'u') { | 778 if (c == '\\' && current() == 'u') { |
783 // TODO(jgruber): Reconsider this once the spec has settled. | |
784 // https://github.com/tc39/proposal-regexp-named-groups/issues/23 | |
785 Advance(); | 779 Advance(); |
786 if (!ParseUnicodeEscape(&c)) { | 780 if (!ParseUnicodeEscape(&c)) { |
787 ReportError(CStrVector("Invalid Unicode escape sequence")); | 781 ReportError(CStrVector("Invalid Unicode escape sequence")); |
788 return nullptr; | 782 return nullptr; |
789 } | 783 } |
790 } | 784 } |
791 | 785 |
792 if (at_start) { | 786 if (at_start) { |
793 if (!IdentifierStart::Is(c)) { | 787 if (!IdentifierStart::Is(c)) { |
794 ReportError(CStrVector("Invalid capture group name")); | 788 ReportError(CStrVector("Invalid capture group name")); |
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 return false; | 1858 return false; |
1865 } | 1859 } |
1866 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), | 1860 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), |
1867 zone()); | 1861 zone()); |
1868 LAST(ADD_TERM); | 1862 LAST(ADD_TERM); |
1869 return true; | 1863 return true; |
1870 } | 1864 } |
1871 | 1865 |
1872 } // namespace internal | 1866 } // namespace internal |
1873 } // namespace v8 | 1867 } // namespace v8 |
OLD | NEW |