Skip to content

Commit 2cadadf

Browse files
committed
UC16-011 RegExp parser, Add part of CharacterEscape
1 parent b2787c1 commit 2cadadf

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ GPRINSTALL_FLAGS = --prefix=$(PREFIX) --exec-subdir=$(INSTALL_EXEC_DIR)\
1616
--lib-subdir=$(INSTALL_ALI_DIR) --project-subdir=$(INSTALL_PROJECT_DIR)\
1717
--link-lib-subdir=$(INSTALL_LIBRARY_DIR) --sources-subdir=$(INSTALL_INCLUDE_DIR)
1818

19-
OK_RE_TESTS := 445 # Number of re_tests to be passed
19+
OK_RE_TESTS := 449 # Number of re_tests to be passed
2020

2121
ifeq ($(OS),Windows_NT)
2222
VSS_PS=;

source/regexp/implementation/vss-regular_expressions-ecma_parser.adb

+45-4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ package body VSS.Regular_Expressions.ECMA_Parser is
103103
procedure Character_Class_Escape
104104
(Value : out Name_Sets.General_Category_Set; Ok : in out Boolean);
105105

106+
procedure Character_Escape
107+
(Value : out VSS.Characters.Virtual_Character; Ok : in out Boolean)
108+
with Pre => Ok;
109+
106110
Next_Group : Positive := 1; -- Group counter
107111

108112
-- Implementations
@@ -157,13 +161,34 @@ package body VSS.Regular_Expressions.ECMA_Parser is
157161
end Alternative;
158162

159163
procedure Atom_Escape (Value : out Node_Or_Class; Ok : in out Boolean) is
160-
Set : Name_Sets.General_Category_Set;
164+
Set : Name_Sets.General_Category_Set;
165+
Character : VSS.Characters.Virtual_Character;
161166
begin
162-
Character_Class_Escape (Set, Ok);
167+
if not Cursor.Has_Element then
168+
if Error.Is_Empty then
169+
Error := "Unexpected end of string in escape.";
170+
end if;
163171

164-
if Ok then
165-
Value := (Has_Node => False, Category => Set);
172+
Ok := False;
173+
return;
166174
end if;
175+
176+
case Cursor.Element is
177+
when 'p' | 'P' =>
178+
Character_Class_Escape (Set, Ok);
179+
180+
if Ok then
181+
Value := (Has_Node => False, Category => Set);
182+
end if;
183+
184+
when others =>
185+
Character_Escape (Character, Ok);
186+
187+
if Ok then
188+
Value := From_Node (Create_Character (Character));
189+
end if;
190+
191+
end case;
167192
end Atom_Escape;
168193

169194
procedure Atom_Or_Assertion
@@ -300,6 +325,22 @@ package body VSS.Regular_Expressions.ECMA_Parser is
300325
end if;
301326
end Character_Class_Escape;
302327

328+
procedure Character_Escape
329+
(Value : out VSS.Characters.Virtual_Character; Ok : in out Boolean) is
330+
begin
331+
case Cursor.Element is
332+
when '^' | '$' | '\' | '.' | '*' | '+' | '?' |
333+
'(' | ')' | '[' | ']' | '{' | '}' | '|'
334+
=>
335+
336+
Value := Cursor.Element;
337+
Expect (Cursor.Element, Ok);
338+
when others =>
339+
Ok := False;
340+
Error := "Unsupported escape sequence.";
341+
end case;
342+
end Character_Escape;
343+
303344
procedure Class_Atom
304345
(Value : out Character_Or_Set;
305346
Ok : in out Boolean) is

source/regexp/implementation/vss-regular_expressions.adb

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ package body VSS.Regular_Expressions is
101101
Index : Natural := 0)
102102
return VSS.Strings.Virtual_String is
103103
begin
104-
if Self.Is_Valid then
104+
if Self.Is_Valid and then Index + 1 in Self.Data.Markers'Range then
105105
return
106106
Self.Data.Get_Owner.Slice
107107
(From => Self.First_Marker (Index),

0 commit comments

Comments
 (0)