Skip to content

Commit

Permalink
Handle ISPP's special bracket notation for include files. Also a mino…
Browse files Browse the repository at this point in the history
…r NeedIspp fix: an inline include wasn't correctly marked as needing ISPP.
  • Loading branch information
martijnlaan committed Dec 10, 2020
1 parent 312c0a4 commit 5aa0061
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
54 changes: 37 additions & 17 deletions Components/ScintStylerInnoSetup.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,26 @@ procedure TInnoSetupStyler.HandleCompilerDirective(const InlineDirective: Boolea
CommitStyleSqPending(stComment);
end;

procedure ConsumeISPPString(const Terminator: AnsiChar; const AllowEscapedTerminator: Boolean);
begin
while True do begin
ConsumeCharsNot([Terminator]);
if not ConsumeChar(Terminator) then begin
{ Non terminated string found }
CommitStyleSqPending(stISPPString);
Break;
end;
{ Terminated string found and consumed. Now check if the terminator is actually escaped by doubling, if allowed }
if not AllowEscapedTerminator or not ConsumeChar(Terminator) then begin
{ Doubling not allowed or no double terminator found, so we're done }
CommitStyle(stISPPString);
Break;
end;
{ The terminator was doubled so we should continue to find the real terminator }
end;

end;

const
ISPPReservedWords: array[0..16] of TScintRawString = (
'private', 'protected', 'public', 'any', 'int',
Expand All @@ -1195,7 +1215,7 @@ procedure TInnoSetupStyler.HandleCompilerDirective(const InlineDirective: Boolea
S: TScintRawString;
StartIndex, I: Integer;
C: AnsiChar;
NeedIspp, ForDirectiveExpressionsNext: Boolean;
NeedIspp, ForDirectiveExpressionsNext, DoIncludeFileNotationCheck: Boolean;
begin
StartIndex := CurIndex;
if InlineDirective then begin
Expand All @@ -1204,19 +1224,25 @@ procedure TInnoSetupStyler.HandleCompilerDirective(const InlineDirective: Boolea
end else
NeedIspp := False; { Might be updated later to True later }
ForDirectiveExpressionsNext := False;
DoIncludeFileNotationCheck := False;
ConsumeChar('#');
CommitStyle(stCompilerDirective);

{ Directive name or shorthand }
SkipWhiteSpace;
C := CurChar;
if ConsumeCharIn(ISPPDirectiveShorthands) then begin
DoIncludeFileNotationCheck := C = '+'; { We need to check the include file notation }
NeedIspp := True;
FinishDirectiveNameOrShorthand(True); { All shorthands require a parameter }
end else begin
S := ConsumeString(ISPPIdentChars);
for I := Low(ISPPDirectives) to High(ISPPDirectives) do
if SameRawText(S, ISPPDirectives[I].Name) then begin
NeedIspp := not SameRawText(S, 'include'); { Built-in preprocessor only supports '#include' }
if SameRawText(S, 'include') then
DoIncludeFileNotationCheck := True { See above }
else
NeedIspp := True; { Built-in preprocessor only supports '#include' }
ForDirectiveExpressionsNext := SameRawText(S, 'for'); { #for uses ';' as an expressions list separator so we need to remember that ';' doesn't start a comment until the list is done }
Inc(OpenCount, ISPPDirectives[I].OpenCountChange);
if OpenCount < 0 then begin
Expand All @@ -1234,9 +1260,15 @@ procedure TInnoSetupStyler.HandleCompilerDirective(const InlineDirective: Boolea

{ Rest of the directive }
SkipWhitespace;
if not NeedIspp then
NeedIspp := CurChar <> '"'; { Built-in preprocessor requires a '"' quoted string after the '#include' and doesn't support anything else }
while not EndOfDirective do begin
if DoIncludeFileNotationCheck then begin
if CurChar <> '"' then begin
NeedIspp := True; { Built-in preprocessor requires a '"' quoted string after the '#include' and doesn't support anything else }
if CurChar = '<' then { Check for ISPP's special bracket notation for include files }
ConsumeISPPString('>', False); { Consume now instead of using regular consumption }
end;
DoIncludeFileNotationCheck := False;
end;
if CurChar in ISPPIdentFirstChars then begin
S := ConsumeString(ISPPIdentChars);
for I := Low(ISPPReservedWords) to High(ISPPReservedWords) do
Expand Down Expand Up @@ -1288,19 +1320,7 @@ procedure TInnoSetupStyler.HandleCompilerDirective(const InlineDirective: Boolea
end;
end;
'''', '"':
begin
while True do begin
ConsumeCharsNot([C]);
if not ConsumeChar(C) then begin
CommitStyleSqPending(stISPPString);
Break;
end;
if not ConsumeChar(C) then begin
CommitStyle(stISPPString);
Break;
end;
end;
end;
ConsumeISPPString(C, True);
else
{ Illegal character }
CommitStyleSq(stSymbol, True);
Expand Down
1 change: 1 addition & 0 deletions whatsnew.htm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
</ul>
</li>
<li>ISPP change: Added new <tt>StrToVersion</tt> support function.</li>
<li>Minor tweaks.</li>
</ul>

<p>Contributions via <a href="https://github.com/jrsoftware/issrc" target="_blank">GitHub</a>: <b>Thanks to Sergii Leonov and Dom Gries for their contributions.</b></p>
Expand Down

0 comments on commit 5aa0061

Please sign in to comment.