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;
end;
{PasTokenizerStack = class
private
stack: TStack<integer>;
// _pop
procedure _get_with_comments();
procedure _get_without_comments();
{$IFNDEF FPC}
TAGPasTokenizerStack=class
strict protected
type
GetCall=reference to function(Tokenizer:TAGPasTokenizer):TAGToken;
var
Stack:TStack<TAGToken>;
Tokenizer:TAGPasTokenizer;
Get:GetCall;
function GetLast():TAGToken;
function IsEnded():Boolean;
public
procedure push(s: string);
procedure pop();
procedure read_last();
procedure is_ended();
end;}
constructor Create(input:TStrings;GetComments:boolean=True);
procedure Push(t:TAGToken);
function Pop():TAGToken;
property Last:TAGToken read GetLast write Push;
property Ended:Boolean read IsEnded;
end;
{$ENDIF}
function IsComment(s: string): boolean;
function IsName(s: string): boolean;
@@ -235,7 +242,8 @@ begin
begin
ss:=now_sym;
inc(x);
if SYMS2.{$IFDEF FPC}
if SYMS2.
{$IFDEF FPC}
IndexOf(now_sym+next_sym)<>-1
{$ELSE}
Contains(now_sym+next_sym)
@@ -322,6 +330,61 @@ begin
SkipSpaces;
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
SYMS2 := {$IFDEF FPC}TStringList{$ELSE}TList<string>{$ENDIF}.Create();
SYMS2.Add('>=');