Files
bds.mr.dpg/src.lib/dpglib.BlockContext.pas
T
2026-01-03 18:33:48 +01:00

58 lines
2.0 KiB
ObjectPascal

// ================================================================================================
// BlockContext stores the information needed when creating an alternative (list of elements).
// Entering a subrule requires that we save this state as each block of alternatives requires
// state such as "tail of current alternative."
// ================================================================================================
unit dpglib.BlockContext;
interface
uses
dpglib.types;
type
TBlockContext = class(TObject)
private
fAltNum : integer;
fBlock : IAlternativeBlock;
fBlockEnd : IBlockEndElem;
public
procedure AddAlternativeElem( pElem: IAlternativeElem); virtual;
function CurrentAlt : IAlternative;
function CurrentElem : IAlternativeElem;
public
property AltNum : integer read fAltNum write fAltNum;
property Block : IAlternativeBlock read fBlock write fBlock;
property BlockEnd : IBlockEndElem read fBlockEnd write fBlockEnd;
end;
implementation
// ----------------------------------------------------------------------------
// CurrentAlt
// ----------------------------------------------------------------------------
function TBlockContext.CurrentAlt: IAlternative;
begin
fBlock.Alternatives.Items[fAltNum].QueryInterface( IAlternative, result);
end;
// ----------------------------------------------------------------------------
// CurrentElem
// ----------------------------------------------------------------------------
function TBlockContext.CurrentElem: IAlternativeElem;
begin
result := CurrentAlt.Tail;
end;
// ----------------------------------------------------------------------------
// AddAlternativeElem
// ----------------------------------------------------------------------------
procedure TBlockContext.AddAlternativeElem(pElem: IAlternativeElem);
begin
CurrentAlt.AddElem( pElem);
end;
end.