Skip to content

Commit

Permalink
Remove use of TRegex to identify identifiers. Using IsValidIdent inst…
Browse files Browse the repository at this point in the history
…ead. #205
  • Loading branch information
darnocian committed Sep 22, 2024
1 parent f4645e1 commit c6abdb5
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/Sempare.Template.Lexer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ TPair = record
Eof: Boolean;
constructor Create(const AInput: char; const AEof: Boolean);
end;
private
class var FIDRegex: TRegEx;
class constructor Create; overload;
private
FReader: TStreamReader;
FNextToken: TQueue<ITemplateSymbol>;
Expand Down Expand Up @@ -193,11 +190,6 @@ constructor TTemplateLexer.Create(const AContext: ITemplateContext; const AStrea
FAccumulator := TStringBuilder.Create;
end;

class constructor TTemplateLexer.Create;
begin
FIDRegex := TRegEx.Create('^[a-zA-Z_][a-zA-Z_0-9]*$');
end;

destructor TTemplateLexer.Destroy;
begin
FNextToken.Free;
Expand Down Expand Up @@ -267,19 +259,14 @@ function TTemplateLexer.GetScriptToken: ITemplateSymbol;
GetInput;
end;

function IsValidId(const AId: string): Boolean;
begin
exit(FIDRegex.IsMatch(AId));
end;

function ValueToken(const ASymbol: TTemplateSymbol): ITemplateSymbol;
var
LId: string;
LPosition: IPosition;
begin
LId := FAccumulator.ToString;
LPosition := MakePosition;
if (ASymbol = vsID) and not IsValidId(LId) then
if (ASymbol = vsID) and not IsValidIdent(LId) then
begin
RaiseErrorRes(LPosition, @SInvalidCharacterDetected);
end;
Expand Down

0 comments on commit c6abdb5

Please sign in to comment.