LazEdit: update TRegExpr

This commit is contained in:
Martin 2023-11-20 23:54:24 +01:00
parent 3692c658ae
commit f6743b5cd7

View File

@ -6077,11 +6077,6 @@ begin
OP_BRANCH: OP_BRANCH:
begin begin
if (next^ <> OP_BRANCH) // No next choice in group
then
next := scan + REOpSz + RENextOffSz + REBranchArgSz // Avoid recursion
else
begin
repeat repeat
save := regInput; save := regInput;
Result := MatchPrim(scan + REOpSz + RENextOffSz + REBranchArgSz); Result := MatchPrim(scan + REOpSz + RENextOffSz + REBranchArgSz);
@ -6099,7 +6094,6 @@ begin
until False; until False;
next := scan + REOpSz + RENextOffSz + REBranchArgSz; // Avoid recursion next := scan + REOpSz + RENextOffSz + REBranchArgSz; // Avoid recursion
end; end;
end;
OP_GBRANCH, OP_GBRANCH_EX, OP_GBRANCH_EX_CI: OP_GBRANCH, OP_GBRANCH_EX, OP_GBRANCH_EX_CI:
begin begin
@ -7081,7 +7075,7 @@ var
{$IFDEF UseLineSep} {$IFDEF UseLineSep}
i: integer; i: integer;
{$ENDIF} {$ENDIF}
TempSet: TRegExprCharset; TempSet, TmpFirstCharSet: TRegExprCharset;
begin begin
TempSet := []; TempSet := [];
scan := prog; scan := prog;
@ -7268,34 +7262,57 @@ begin
Exit; Exit;
end; end;
OP_LOOKAHEAD, OP_LOOKAHEAD_NEG, OP_LOOKAHEAD:
OP_LOOKBEHIND, OP_LOOKBEHIND_NEG, begin
opnd := PRegExprChar(AlignToPtr(Next + 1)) + RENextOffSz;
Next := regNextQuick(Next);
FillFirstCharSet(Next);
if opnd^ = OP_LOOKAROUND_OPTIONAL then
Exit;
Next := PRegExprChar(AlignToPtr(scan + 1)) + RENextOffSz;
TmpFirstCharSet := FirstCharSet;
FirstCharSet := [];
FillFirstCharSet(Next);
if TmpFirstCharSet = [] then
exit;
if FirstCharSet = [] then
FirstCharSet := TmpFirstCharSet
else
FirstCharSet := FirstCharSet * TmpFirstCharSet;
exit;
end;
OP_LOOKAHEAD_NEG,
OP_LOOKBEHIND, OP_LOOKBEHIND_NEG:
begin
Next := PRegExprChar(AlignToPtr(Next + 1)) + RENextOffSz;
end;
OP_LOOKAHEAD_END, OP_LOOKBEHIND_END: OP_LOOKAHEAD_END, OP_LOOKBEHIND_END:
begin begin
FillFirstCharSet(Next); // skip to the end
Exit; Exit;
end; end;
OP_LOOKAROUND_OPTIONAL: OP_LOOKAROUND_OPTIONAL:
; begin
Next := PRegExprChar(AlignToPtr(scan + 1)) + RENextOffSz;
end;
OP_BRANCH, OP_GBRANCH, OP_GBRANCH_EX, OP_GBRANCH_EX_CI: OP_BRANCH, OP_GBRANCH, OP_GBRANCH_EX, OP_GBRANCH_EX_CI:
begin
if (PREOp(Next)^ <> OP_BRANCH) and (PREOp(Next)^ <> OP_GBRANCH) and
(PREOp(Next)^ <> OP_GBRANCH_EX) and (PREOp(Next)^ <> OP_GBRANCH_EX_CI) // No choice.
then
Next := scan + REOpSz + RENextOffSz + REBranchArgSz // Avoid recursion.
else
begin begin
repeat repeat
TmpFirstCharSet := FirstCharSet;
FirstCharSet := [];
FillFirstCharSet(scan + REOpSz + RENextOffSz + REBranchArgSz); FillFirstCharSet(scan + REOpSz + RENextOffSz + REBranchArgSz);
FirstCharSet := FirstCharSet + TmpFirstCharSet;
scan := regNextQuick(scan); scan := regNextQuick(scan);
until (scan = nil) or until (scan = nil) or
( (PREOp(scan)^ <> OP_BRANCH) and (PREOp(Next)^ <> OP_GBRANCH) and ( (PREOp(scan)^ <> OP_BRANCH) and (PREOp(Next)^ <> OP_GBRANCH) and
(PREOp(scan)^ <> OP_GBRANCH_EX) and (PREOp(scan)^ <> OP_GBRANCH_EX_CI) ); (PREOp(scan)^ <> OP_GBRANCH_EX) and (PREOp(scan)^ <> OP_GBRANCH_EX_CI) );
Exit; Exit;
end; end;
end;
{$IFDEF ComplexBraces} {$IFDEF ComplexBraces}
OP_LOOPENTRY: OP_LOOPENTRY:
@ -8001,7 +8018,6 @@ begin
OP_BRANCH, OP_GBRANCH, OP_GBRANCH_EX, OP_GBRANCH_EX_CI: OP_BRANCH, OP_GBRANCH, OP_GBRANCH_EX, OP_GBRANCH_EX_CI:
begin begin
if (next^ = OP_BRANCH) or (PREOp(Next)^ = OP_GBRANCH) or (next^ = OP_GBRANCH_EX) or (next^ = OP_GBRANCH_EX_CI) then begin
s := s + REBranchArgSz; s := s + REBranchArgSz;
if not IsPartFixedLength(s, op, ABranchLen, ABranchMaxLen, OP_EEND, next, []) then if not IsPartFixedLength(s, op, ABranchLen, ABranchMaxLen, OP_EEND, next, []) then
begin begin
@ -8035,9 +8051,6 @@ begin
(next^ <> OP_GBRANCH_EX) and (next^ <> OP_GBRANCH_EX_CI); (next^ <> OP_GBRANCH_EX) and (next^ <> OP_GBRANCH_EX_CI);
AMinLen := AMinLen + ABranchLen; AMinLen := AMinLen + ABranchLen;
IncMaxLen(FndMaxLen, ABranchMaxLen); IncMaxLen(FndMaxLen, ABranchMaxLen);
end
else
s := s + REBranchArgSz;
end; end;
OP_OPEN: OP_OPEN: