Initial check in lib
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
unit dpglib.GrammarAtom;
|
||||
|
||||
interface
|
||||
uses
|
||||
dpgrtl.types,
|
||||
dpglib.types,
|
||||
dpglib.AlternativeElem;
|
||||
|
||||
type
|
||||
// =========================================================================
|
||||
// Class TGrammarAtom declaration
|
||||
// =========================================================================
|
||||
TGrammarAtom = class( TAlternativeElem,
|
||||
IGrammarAtom,
|
||||
IAlternativeElem,
|
||||
IGrammarElem)
|
||||
protected
|
||||
// ------------------------------------------------------------
|
||||
// Members
|
||||
// ------------------------------------------------------------
|
||||
fLabel : AnsiString;
|
||||
fAtomText : AnsiString;
|
||||
fTokenType : integer;
|
||||
fNot : boolean;
|
||||
fASTNodeType : AnsiString;
|
||||
|
||||
public
|
||||
// ------------------------------------------------------------
|
||||
// Constructor/destructor
|
||||
// ------------------------------------------------------------
|
||||
constructor Create( pGrammar : IGrammar;
|
||||
pToken : IToken;
|
||||
pAutoGenType: integer);
|
||||
|
||||
protected
|
||||
// ------------------------------------------------------------
|
||||
// IGrammarElem methods
|
||||
// ------------------------------------------------------------
|
||||
function AsString : AnsiString;
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// IAlternativeElem methods
|
||||
// ------------------------------------------------------------
|
||||
function GetLabel : AnsiString;
|
||||
procedure SetLabel(pLabel: AnsiString);
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// IGrammarAtom methods
|
||||
// ------------------------------------------------------------
|
||||
function GetAtomText : AnsiString;
|
||||
function GetASTNodeType: AnsiString;
|
||||
function GetTokenType : integer;
|
||||
function GetIsNot : boolean;
|
||||
|
||||
procedure SetASTNodeType( pASTNodeType : AnsiString);
|
||||
|
||||
procedure SetOption( pKey: IToken; pValue: IToken);
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
uses
|
||||
dpglib.GrammarElem;
|
||||
|
||||
// ****************************************************************************
|
||||
// Constructor/destructor
|
||||
// ****************************************************************************
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// ----------------------------------------------------------------------------
|
||||
constructor TGrammarAtom.Create( pGrammar : IGrammar;
|
||||
pToken : IToken;
|
||||
pAutoGenType: integer);
|
||||
begin
|
||||
inherited Create( pGrammar, pToken, pAutoGenType);
|
||||
|
||||
fAtomText := pToken.TokenText;
|
||||
fTokenType := TT_INVALID;
|
||||
fNot := false;
|
||||
end;
|
||||
|
||||
// ****************************************************************************
|
||||
// IGrammarElem implementation
|
||||
// ****************************************************************************
|
||||
// ----------------------------------------------------------------------------
|
||||
// ToString
|
||||
// ----------------------------------------------------------------------------
|
||||
function TGrammarAtom.AsString: AnsiString;
|
||||
begin
|
||||
result := '';
|
||||
if fLabel <> '' then result := result + fLabel + ':';
|
||||
if fNot = true then result := result + '~';
|
||||
|
||||
result := result + fAtomtext;
|
||||
end;
|
||||
|
||||
// ****************************************************************************
|
||||
// IAlternativeElem implementation
|
||||
// ****************************************************************************
|
||||
// ----------------------------------------------------------------------------
|
||||
// GetLabel
|
||||
// ----------------------------------------------------------------------------
|
||||
function TGrammarAtom.GetLabel: AnsiString;
|
||||
begin
|
||||
result := fLabel;
|
||||
end;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SetLabel
|
||||
// ----------------------------------------------------------------------------
|
||||
procedure TGrammarAtom.SetLabel(pLabel: AnsiString);
|
||||
begin
|
||||
fLabel := pLabel;
|
||||
end;
|
||||
|
||||
// ****************************************************************************
|
||||
// IGrammarAtom implementation
|
||||
// ****************************************************************************
|
||||
// ----------------------------------------------------------------------------
|
||||
// GetText
|
||||
// ----------------------------------------------------------------------------
|
||||
function TGrammarAtom.GetAtomText: AnsiString;
|
||||
begin
|
||||
result := fAtomText;
|
||||
end;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// GetType
|
||||
// ----------------------------------------------------------------------------
|
||||
function TGrammarAtom.GetTokenType: integer;
|
||||
begin
|
||||
result := fTokenType;
|
||||
end;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// GetIsNot
|
||||
// ----------------------------------------------------------------------------
|
||||
function TGrammarAtom.GetIsNot: boolean;
|
||||
begin
|
||||
result := fNot;
|
||||
end;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// GetASTNodeType;
|
||||
// ----------------------------------------------------------------------------
|
||||
function TGrammarAtom.GetASTNodeType: AnsiString;
|
||||
begin
|
||||
result := fASTNodeType;
|
||||
end;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SetASTNodeType
|
||||
// ----------------------------------------------------------------------------
|
||||
procedure TGrammarAtom.SetASTNodeType(pASTNodeType: AnsiString);
|
||||
begin
|
||||
fASTNodeType := pASTNodeType;
|
||||
end;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SetOption
|
||||
// ----------------------------------------------------------------------------
|
||||
procedure TGrammarAtom.SetOption(pKey: IToken; pValue: IToken);
|
||||
begin
|
||||
if pKey.TokenText = 'AST' then
|
||||
SetASTNodeType( pValue.TokenText)
|
||||
|
||||
else
|
||||
fGrammar.Tool.Error( 'Invalid element option: ' + String(pKey.TokenText),
|
||||
fGrammar.GrammarFile,
|
||||
pKey.TokenLine,
|
||||
pKey.TokenColumn);
|
||||
|
||||
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user