diff --git a/src/shared/xparser.pas b/src/shared/xparser.pas
index 3f1d1db5b462a6ed9fc69fa7ff8284029e2270b6..f539536ce0ffe98da543820f560365b6de8a8279 100644 (file)
--- a/src/shared/xparser.pas
+++ b/src/shared/xparser.pas
function expectStr (allowEmpty: Boolean=false): AnsiString;
function expectInt (): Integer;
+ function expectStrOrId (allowEmpty: Boolean=false): AnsiString;
+
procedure expectTT (ttype: Integer);
function eatTT (ttype: Integer): Boolean;
procedure putIndent ();
procedure indent ();
procedure unindent ();
+
+ public
+ property curIndent: Integer read mIndent;
end;
procedure flush (); override;
end;
+ TStrTextWriter = class(TTextWriter)
+ private
+ mStr: AnsiString;
+
+ protected
+ procedure putBuf (constref buf; len: SizeUInt); override;
+
+ public
+ constructor Create ();
+ destructor Destroy (); override;
+
+ property str: AnsiString read mStr;
+ end;
+
implementation
end;
+function TTextParser.expectStrOrId (allowEmpty: Boolean=false): AnsiString;
+begin
+ case mTokType of
+ TTStr:
+ if (not allowEmpty) and (Length(mTokStr) = 0) then raise Exception.Create('non-empty string expected');
+ TTId:
+ begin end;
+ else
+ raise Exception.Create('string or identifier expected');
+ end;
+ result := mTokStr;
+ skipToken();
+end;
+
+
function TTextParser.expectInt (): Integer;
begin
if (mTokType <> TTInt) then raise Exception.Create('string expected');
end;
+// ////////////////////////////////////////////////////////////////////////// //
+constructor TStrTextWriter.Create ();
+begin
+ mStr := '';
+end;
+
+
+destructor TStrTextWriter.Destroy ();
+begin
+ mStr := '';
+ inherited;
+end;
+
+
+procedure TStrTextWriter.putBuf (constref buf; len: SizeUInt);
+var
+ st: AnsiString = '';
+begin
+ if (len > 0) then
+ begin
+ SetLength(st, Integer(len));
+ Move(buf, PChar(st)^, Integer(len));
+ mStr += st;
+ st := '';
+ end;
+end;
+
+
end.