From 58e50ef07eb9f311274f06808b2f5bab34196f6f Mon Sep 17 00:00:00 2001 From: Mattias Gaertner Date: Fri, 7 Dec 2018 07:57:49 +0000 Subject: [PATCH] pastojs: added $i %file% git-svn-id: trunk@40487 - --- packages/pastojs/src/fppas2js.pp | 35 ++++++++++++++++++++++++++-- packages/pastojs/tests/tcmodules.pas | 2 ++ utils/pas2js/docs/translation.html | 4 +++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index 5a11608185..6378e48ba0 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -2054,10 +2054,34 @@ end; function TPas2jsPasScanner.HandleInclude(const Param: String): TToken; - procedure SetStr(const s: string); + procedure SetStr(s: string); + var + i: Integer; + h: String; begin Result:=tkString; - SetCurTokenString(''''+s+''''); + if s='' then + s:='''''' + else + for i:=length(s) downto 1 do + case s[i] of + #0..#31,#127: + begin + h:='#'+IntToStr(ord(s[i])); + if i>1 then h:=''''+h; + if (i'#') then + h:=h+''''; + s:=LeftStr(s,i-1)+h+copy(s,i+1,length(s)); + end; + else + if i=length(s) then + s:=s+''''; + if s[i]='''' then + Insert('''',s,i); + if i=1 then + s:=''''+s; + end; + SetCurTokenString(s); end; procedure SetInteger(const i: TMaxPrecInt); @@ -2076,12 +2100,14 @@ begin case lowercase(Param) of '%date%': begin + // 'Y/M/D' DecodeDate(Now,Year,Month,Day); SetStr(IntToStr(Year)+'/'+IntToStr(Month)+'/'+IntToStr(Day)); exit; end; '%time%': begin + // 'hh:mm:ss' DecodeTime(Now,Hour,Minute,Second,MilliSecond); SetStr(Format('%2d:%2d:%2d',[Hour,Minute,Second])); exit; @@ -2102,6 +2128,11 @@ begin SetStr(CompilerVersion); exit; end; + '%file%': + begin + SetStr(CurFilename); + exit; + end; '%line%': begin SetStr(IntToStr(CurRow)); diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas index 2fa3f28dda..e8ed3a4e81 100644 --- a/packages/pastojs/tests/tcmodules.pas +++ b/packages/pastojs/tests/tcmodules.pas @@ -2274,6 +2274,7 @@ begin ' s:={$I %pas2jstarget%};', ' s:={$I %pas2jstargetos%};', ' s:={$I %pas2jstargetcpu%};', + ' s:={$I %file%};', '']); ConvertProgram; CheckSource('TestIncludeVersion', @@ -2288,6 +2289,7 @@ begin '$mod.s = "Browser";', '$mod.s = "Browser";', '$mod.s = "ECMAScript5";', + '$mod.s = "test1.pp";', ''])); end; diff --git a/utils/pas2js/docs/translation.html b/utils/pas2js/docs/translation.html index 4b0907cc2b..68e0c25d88 100644 --- a/utils/pas2js/docs/translation.html +++ b/utils/pas2js/docs/translation.html @@ -2804,7 +2804,9 @@ End.