Allow \ as an "other character" preprocessing token.

This still has a few issues. A \ token may not be followed by u or U (because this triggers UCN processing). We should scan through the whole possible UCN until we can confirm whether it is actually a UCN, but that would require more lookahead. Also, \ is not handled correctly in stringization (it should form escape sequences).
This commit is contained in:
Stephen Heumann 2022-11-08 20:46:48 -06:00
parent 9cc72c8845
commit ab368d442a

View File

@ -4871,7 +4871,7 @@ procedure NextToken;
{ Read the next token from the file. } { Read the next token from the file. }
label 1,2,3,4,5,6,7; label 1,2,3,4,5,6,7,8;
type type
three = (s100,s1000,sMAX); {these declarations are used for a} three = (s100,s1000,sMAX); {these declarations are used for a}
@ -5644,8 +5644,8 @@ case charKinds[ord(ch)] of
while charKinds[ord(ch)] in [letter,digit,ch_backslash] do begin while charKinds[ord(ch)] in [letter,digit,ch_backslash] do begin
i := i+1; i := i+1;
if ch = '\' then begin if ch = '\' then begin
if PeekCh in ['u','U'] then begin
NextCh; NextCh;
if ch in ['u','U'] then begin
codePoint := UniversalCharacterName; codePoint := UniversalCharacterName;
if not ValidUCNForIdentifier(codePoint, i=1) then if not ValidUCNForIdentifier(codePoint, i=1) then
Error(149); Error(149);
@ -5659,8 +5659,8 @@ case charKinds[ord(ch)] of
end; {else} end; {else}
end {if} end {if}
else begin else begin
Error(1); i := i-1;
workString[i] := '?'; goto 8;
end; {else} end; {else}
end {if} end {if}
else begin else begin
@ -5668,7 +5668,7 @@ case charKinds[ord(ch)] of
NextCh; NextCh;
end; {if} end; {if}
end; {while} end; {while}
workString[0] := chr(i); 8: workString[0] := chr(i);
if i = 1 then begin {detect prefixed char/string literal} if i = 1 then begin {detect prefixed char/string literal}
if charKinds[ord(ch)] in [ch_char,ch_string] then begin if charKinds[ord(ch)] in [ch_char,ch_string] then begin
if workString[1] in ['L','u','U'] then begin if workString[1] in ['L','u','U'] then begin
@ -5688,6 +5688,13 @@ case charKinds[ord(ch)] of
charStrPrefix := prefix_u8; charStrPrefix := prefix_u8;
goto 6; goto 6;
end; {if} end; {if}
if i = 0 then begin {\ preprocessing token}
token.kind := otherch;
token.class := otherCharacter;
token.ch := ch;
NextCh;
end {if}
else
CheckIdentifier; CheckIdentifier;
end; end;