DEADSOFTWARE

map records and fields can have optional tooltips ("tip") and help ("help") in mapdef...
[d2df-sdl.git] / src / shared / xparser.pas
index 3f1d1db5b462a6ed9fc69fa7ff8284029e2270b6..f539536ce0ffe98da543820f560365b6de8a8279 100644 (file)
@@ -75,6 +75,8 @@ type
     function expectStr (allowEmpty: Boolean=false): AnsiString;
     function expectInt (): Integer;
 
+    function expectStrOrId (allowEmpty: Boolean=false): AnsiString;
+
     procedure expectTT (ttype: Integer);
     function eatTT (ttype: Integer): Boolean;
 
@@ -156,6 +158,9 @@ type
     procedure putIndent ();
     procedure indent ();
     procedure unindent ();
+
+  public
+    property curIndent: Integer read mIndent;
   end;
 
 
@@ -182,6 +187,20 @@ type
     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
 
@@ -530,6 +549,21 @@ begin
 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');
@@ -732,4 +766,32 @@ begin
 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.