diff --git a/src/shared/xparser.pas b/src/shared/xparser.pas
index 3f1d1db5b462a6ed9fc69fa7ff8284029e2270b6..bac4e4a8153feb04faf29362eb0fbfc1295766c1 100644 (file)
--- a/src/shared/xparser.pas
+++ b/src/shared/xparser.pas
TTBegin = 8; // left curly
TTEnd = 9; // right curly
TTDelim = 10; // other delimiters
+ //
+ TTLogAnd = 11; // &&
+ TTLogOr = 12; // ||
+ TTLessEqu = 13; // <=
+ TTGreatEqu = 14; // >=
+ TTNotEqu = 15; // !=
+ TTEqu = 16; // ==
private
mLine, mCol: Integer;
function skipBlanks (): Boolean; // ...and comments; returns `false` on eof
function skipToken (): Boolean; // returns `false` on eof
+ //function skipToken1 (): Boolean;
function expectId (): AnsiString;
procedure expectId (const aid: AnsiString);
function expectStr (allowEmpty: Boolean=false): AnsiString;
function expectInt (): Integer;
+ function expectStrOrId (allowEmpty: Boolean=false): AnsiString;
+
procedure expectTT (ttype: Integer);
function eatTT (ttype: Integer): Boolean;
function expectDelim (const ch: AnsiChar): AnsiChar;
function eatDelim (const ch: AnsiChar): Boolean;
+ public
+ property allowSignedNumbers: Boolean read mAllowSignedNumbers write mAllowSignedNumbers;
+
public
property col: Integer read mCol;
property line: Integer read mLine;
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.skipToken (): Boolean;
+begin
+ writeln('getting token...');
+ result := skipToken1();
+ writeln(' got token: ', mTokType, ' <', mTokStr, '> : <', mTokChar, '>');
+end;
+}
+
+
function TTextParser.skipToken (): Boolean;
procedure parseInt ();
if (curChar = '_') or ((curChar >= 'A') and (curChar <= 'Z')) or ((curChar >= 'a') and (curChar <= 'z')) or (curChar >= #128) then begin parseId(); exit; end;
// known delimiters?
- case curChar of
+ mTokChar := curChar;
+ mTokType := TTDelim;
+ skipChar();
+ if (curChar = '=') then
+ begin
+ case mTokChar of
+ '<': begin mTokType := TTLessEqu; mTokStr := '<='; skipChar(); exit; end;
+ '>': begin mTokType := TTGreatEqu; mTokStr := '>='; skipChar(); exit; end;
+ '!': begin mTokType := TTNotEqu; mTokStr := '!='; skipChar(); exit; end;
+ '=': begin mTokType := TTEqu; mTokStr := '=='; skipChar(); exit; end;
+ end;
+ end;
+ case mTokChar of
',': mTokType := TTComma;
':': mTokType := TTColon;
';': mTokType := TTSemi;
'{': mTokType := TTBegin;
'}': mTokType := TTEnd;
- else mTokType := TTDelim;
+ '&': if (curChar = '&') then begin mTokType := TTLogAnd; mTokStr := '&&'; skipChar(); exit; end;
+ '|': if (curChar = '|') then begin mTokType := TTLogOr; mTokStr := '||'; skipChar(); exit; end;
end;
- mTokChar := curChar;
- skipChar();
end;
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.