Skip to content

Commit

Permalink
UC16-011 RegExp parser, Add part of CharacterEscape
Browse files Browse the repository at this point in the history
  • Loading branch information
reznikmm committed Sep 21, 2022
1 parent b2787c1 commit 2cadadf
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GPRINSTALL_FLAGS = --prefix=$(PREFIX) --exec-subdir=$(INSTALL_EXEC_DIR)\
--lib-subdir=$(INSTALL_ALI_DIR) --project-subdir=$(INSTALL_PROJECT_DIR)\
--link-lib-subdir=$(INSTALL_LIBRARY_DIR) --sources-subdir=$(INSTALL_INCLUDE_DIR)

OK_RE_TESTS := 445 # Number of re_tests to be passed
OK_RE_TESTS := 449 # Number of re_tests to be passed

ifeq ($(OS),Windows_NT)
VSS_PS=;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ package body VSS.Regular_Expressions.ECMA_Parser is
procedure Character_Class_Escape
(Value : out Name_Sets.General_Category_Set; Ok : in out Boolean);

procedure Character_Escape
(Value : out VSS.Characters.Virtual_Character; Ok : in out Boolean)
with Pre => Ok;

Next_Group : Positive := 1; -- Group counter

-- Implementations
Expand Down Expand Up @@ -157,13 +161,34 @@ package body VSS.Regular_Expressions.ECMA_Parser is
end Alternative;

procedure Atom_Escape (Value : out Node_Or_Class; Ok : in out Boolean) is
Set : Name_Sets.General_Category_Set;
Set : Name_Sets.General_Category_Set;
Character : VSS.Characters.Virtual_Character;
begin
Character_Class_Escape (Set, Ok);
if not Cursor.Has_Element then
if Error.Is_Empty then
Error := "Unexpected end of string in escape.";
end if;

if Ok then
Value := (Has_Node => False, Category => Set);
Ok := False;
return;
end if;

case Cursor.Element is
when 'p' | 'P' =>
Character_Class_Escape (Set, Ok);

if Ok then
Value := (Has_Node => False, Category => Set);
end if;

when others =>
Character_Escape (Character, Ok);

if Ok then
Value := From_Node (Create_Character (Character));
end if;

end case;
end Atom_Escape;

procedure Atom_Or_Assertion
Expand Down Expand Up @@ -300,6 +325,22 @@ package body VSS.Regular_Expressions.ECMA_Parser is
end if;
end Character_Class_Escape;

procedure Character_Escape
(Value : out VSS.Characters.Virtual_Character; Ok : in out Boolean) is
begin
case Cursor.Element is
when '^' | '$' | '\' | '.' | '*' | '+' | '?' |
'(' | ')' | '[' | ']' | '{' | '}' | '|'
=>

Value := Cursor.Element;
Expect (Cursor.Element, Ok);
when others =>
Ok := False;
Error := "Unsupported escape sequence.";
end case;
end Character_Escape;

procedure Class_Atom
(Value : out Character_Or_Set;
Ok : in out Boolean) is
Expand Down
2 changes: 1 addition & 1 deletion source/regexp/implementation/vss-regular_expressions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ package body VSS.Regular_Expressions is
Index : Natural := 0)
return VSS.Strings.Virtual_String is
begin
if Self.Is_Valid then
if Self.Is_Valid and then Index + 1 in Self.Data.Markers'Range then
return
Self.Data.Get_Owner.Slice
(From => Self.First_Marker (Index),
Expand Down

0 comments on commit 2cadadf

Please sign in to comment.