Add stack

This commit is contained in:
2018-11-22 12:28:37 +02:00
parent 2e07350571
commit b837d46736

View File

@@ -44,18 +44,25 @@ type
property Pos:TAGTokenizerPos read GetPos write SetPos; property Pos:TAGTokenizerPos read GetPos write SetPos;
end; end;
{PasTokenizerStack = class {$IFNDEF FPC}
private TAGPasTokenizerStack=class
stack: TStack<integer>; strict protected
// _pop type
procedure _get_with_comments(); GetCall=reference to function(Tokenizer:TAGPasTokenizer):TAGToken;
procedure _get_without_comments(); var
Stack:TStack<TAGToken>;
Tokenizer:TAGPasTokenizer;
Get:GetCall;
function GetLast():TAGToken;
function IsEnded():Boolean;
public public
procedure push(s: string); constructor Create(input:TStrings;GetComments:boolean=True);
procedure pop(); procedure Push(t:TAGToken);
procedure read_last(); function Pop():TAGToken;
procedure is_ended(); property Last:TAGToken read GetLast write Push;
end;} property Ended:Boolean read IsEnded;
end;
{$ENDIF}
function IsComment(s: string): boolean; function IsComment(s: string): boolean;
function IsName(s: string): boolean; function IsName(s: string): boolean;
@@ -235,7 +242,8 @@ begin
begin begin
ss:=now_sym; ss:=now_sym;
inc(x); inc(x);
if SYMS2.{$IFDEF FPC} if SYMS2.
{$IFDEF FPC}
IndexOf(now_sym+next_sym)<>-1 IndexOf(now_sym+next_sym)<>-1
{$ELSE} {$ELSE}
Contains(now_sym+next_sym) Contains(now_sym+next_sym)
@@ -322,6 +330,61 @@ begin
SkipSpaces; SkipSpaces;
end; end;
{$IFNDEF FPC}
{TAGPasTokenizerStack}
function TAGPasTokenizerStack.GetLast():TAGToken;
begin
if Stack.Count<>0 then
Result:=Stack.Peek
else
begin
Result:=Get;
Stack.Push(Result);
end;
end;
function TAGPasTokenizerStack.IsEnded():Boolean;
begin
end;
constructor TAGPasTokenizerStack.Create(input:TStrings;GetComments:boolean=True);
begin
Stack:=TStack<TAGToken>.Create();
Tokenizer:=TAGPasTokenizer.Create(input);
if GetComments then
Get:=function(Tokenizer:TAGPasTokenizer):TAGToken
begin
Result:=Tokenizer.GetNext;
end
else
Get:=function(Tokenizer:TAGPasTokenizer):TAGToken
begin
while True do
begin
Result:=Tokenizer.GetNext;
if Result.ended or not IsComment(Result.Text) then
break;
end;
end;
end;
procedure TAGPasTokenizerStack.Push(t:TAGToken);
begin
Stack.Push(t);
end;
function TAGPasTokenizerStack.Pop():TAGToken;
begin
if Stack.Count<>0 then
Result:=Stack.Pop
else
Result:=Get;
end;
{$ENDIF}
initialization initialization
SYMS2 := {$IFDEF FPC}TStringList{$ELSE}TList<string>{$ENDIF}.Create(); SYMS2 := {$IFDEF FPC}TStringList{$ELSE}TList<string>{$ENDIF}.Create();
SYMS2.Add('>='); SYMS2.Add('>=');