89 lines
3.1 KiB
ObjectPascal
89 lines
3.1 KiB
ObjectPascal
unit dpglib.CharLiteralElem;
|
|
|
|
interface
|
|
uses
|
|
dpgrtl.types,
|
|
dpglib.types,
|
|
dpglib.GrammarAtom;
|
|
|
|
type
|
|
// =========================================================================
|
|
// Class TCharLiteralElem declaration
|
|
// =========================================================================
|
|
TCharLiteralElem = class( TGrammarAtom,
|
|
ICharLiteralElem,
|
|
IGrammarAtom,
|
|
IAlternativeElem,
|
|
IGrammarElem)
|
|
public
|
|
// ------------------------------------------------------------
|
|
// Constructor/destructor
|
|
// ------------------------------------------------------------
|
|
constructor Create( pGrammar : IGrammar;
|
|
pToken : IToken;
|
|
pInverted : boolean;
|
|
pAutoGenType: integer);
|
|
|
|
public
|
|
// ------------------------------------------------------------
|
|
// IGrammarElem methods
|
|
// ------------------------------------------------------------
|
|
procedure Generate;
|
|
function Look( pK: integer): ILookahead;
|
|
end;
|
|
|
|
implementation
|
|
// ****************************************************************************
|
|
// Constructor/destructor
|
|
// ****************************************************************************
|
|
// ----------------------------------------------------------------------------
|
|
// Constructor
|
|
// ----------------------------------------------------------------------------
|
|
constructor TCharLiteralElem.Create( pGrammar : IGrammar;
|
|
pToken : IToken;
|
|
pInverted : boolean;
|
|
pAutoGenType: integer);
|
|
begin
|
|
inherited Create( pGrammar, pToken, AUTOGEN_NONE);
|
|
|
|
{ TODO 1 -omiki -ctoken : Fix for TokenTypeForCharLiteral }
|
|
if pToken.TokenText = '' then
|
|
begin
|
|
fLine := 1;
|
|
exit;
|
|
end;
|
|
|
|
fTokenType := ord(pToken.TokenText[1]);
|
|
// token_type = ANTLRLexer.tokentypeforcharliteral(pToken.TokenText);
|
|
// pGrammar.charVocabulary.add fTokenType;
|
|
|
|
fLine := pToken.TokenLine;
|
|
fNot := pInverted;
|
|
fAutoGenType:= pAutoGenType;
|
|
end;
|
|
|
|
// ****************************************************************************
|
|
// IGrammarElem implementation
|
|
// ****************************************************************************
|
|
// ----------------------------------------------------------------------------
|
|
// Generate
|
|
// ----------------------------------------------------------------------------
|
|
procedure TCharLiteralElem.Generate;
|
|
var
|
|
elem: ICharLiteralElem;
|
|
|
|
begin
|
|
elem := self;
|
|
fGrammar.Generator.Gen(elem);
|
|
end;
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Look
|
|
// ----------------------------------------------------------------------------
|
|
function TCharLiteralElem.Look(pK: integer): ILookahead;
|
|
begin
|
|
result := fGrammar.LLkAnalyzer.Look( pK, self);
|
|
end;
|
|
|
|
end.
|