Smart pascal source code
type
TMyStream = class
end;
type
TStreamSpecial = (BACKSPACE, CRLF);
function StreamString(s: TMyStream; str: String): TMyStream;
begin
WriteLn(str);
Result := s;
end;
operator << (TMyStream, String): TMyStream uses StreamString;
function StreamSpecial(s: TMyStream; spec: TStreamSpecial): TMyStream;
begin
if spec = BACKSPACE then
s << '<<'
else
s << #13#10;
Result := s;
end;
operator << (TMyStream, TStreamSpecial): TMyStream uses StreamSpecial;
function StreamDummy(s: TMyStream; str: String): TMyStream;
begin
s << 'Dummy ' << str << CRLF;
end;
operator >> (TMyStream, String): TMyStream uses StreamDummy;
var o := new TMyStream;
o << " Hello world ! " << CRLF >> " Hey " << BACKSPACE <<
" Wicked stuff .. ." << CRLF;
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
Hello world!
Dummy Hey
<>>>>>>>>}
var TStreamSpecial = [ "BACKSPACE", "CRLF" ];
var TMyStream = {
$ClassName:"TMyStream",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
,Destroy:TObject.Destroy
};
function StreamString(s, str) {
var Result = null;
WriteLn(str);
Result = s;
return Result
};
function StreamSpecial(s$1, spec) {
var Result = null;
if (!spec) {
StreamString(s$1,"<<");
} else {
StreamString(s$1,"\r\n");
}
Result = s$1;
return Result
};
function StreamDummy(s$2, str$1) {
var Result = null;
StreamSpecial(StreamString(StreamString(s$2,"Dummy "),str$1),1);
return Result
};
var o = null;
/* <<< main JS >>> */
o = TObject.Create($New(TMyStream));
StreamSpecial(StreamString(StreamSpecial(StreamDummy(StreamSpecial(StreamString(o," Hello world ! "),1)," Hey "),0)," Wicked stuff .. ."),1);