From c319bc8947f699f8e0c73a8983d4c3897d4da7ed Mon Sep 17 00:00:00 2001 From: juha Date: Fri, 13 Nov 2020 09:37:02 +0000 Subject: [PATCH] =?UTF-8?q?Jedi=20Code=20Format:=20Support=20escaped=20ide?= =?UTF-8?q?ntifiers=20(&identifier).=20Issue=20#38067,=20patch=20from=20Do?= =?UTF-8?q?mingo=20Galm=C3=A9s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: trunk@64131 - --- components/jcf2/Parse/BuildParseTree.pas | 86 ++++++++++++++---------- components/jcf2/Parse/BuildTokenList.pas | 52 ++++++++++---- 2 files changed, 92 insertions(+), 46 deletions(-) diff --git a/components/jcf2/Parse/BuildParseTree.pas b/components/jcf2/Parse/BuildParseTree.pas index 51a5705faf..1a9f13f39b 100644 --- a/components/jcf2/Parse/BuildParseTree.pas +++ b/components/jcf2/Parse/BuildParseTree.pas @@ -1218,41 +1218,50 @@ begin Recognise(ttEquals); - //Recognise type helper (for fpc) - if (fcTokenList.FirstSolidTokenType in [ttType,ttRecord]) and - (fcTokenList.SolidToken(2).TokenType=ttHelper) then - begin - RecogniseTypeHelper; - end else + repeat - // type or restricted type - if (fcTokenList.FirstSolidTokenType in [ttObject, ttClass, ttInterface, - ttDispInterface]) then - RecogniseRestrictedType - else - RecogniseType; + //Recognise type helper (for fpc) + if (fcTokenList.FirstSolidTokenType in [ttType,ttRecord]) and + (fcTokenList.SolidToken(2).TokenType=ttHelper) then + begin + RecogniseTypeHelper; + end else - if fcTokenList.FirstSolidTokenType = ttLessThan then - begin - RecogniseGenericType; - end; - if fcTokenList.FirstSolidTokenType = ttIs then - begin - Recognise(ttIs); - Recognise(ttNested); - end; + // type or restricted type + if (fcTokenList.FirstSolidTokenType in [ttObject, ttClass, ttInterface, + ttDispInterface]) then + RecogniseRestrictedType + else + RecogniseType; - // the type can be deprecated - if fcTokenList.FirstSolidTokenType = ttDeprecated then - Recognise(ttDeprecated); + if fcTokenList.FirstSolidTokenType = ttLessThan then + begin + RecogniseGenericType; + end; + if fcTokenList.FirstSolidTokenType = ttIs then + begin + Recognise(ttIs); + Recognise(ttNested); + end; + + // the type can be deprecated + if fcTokenList.FirstSolidTokenType = ttDeprecated then + Recognise(ttDeprecated); + + if fcTokenList.FirstSolidTokenType <> ttDot then + break; + Recognise(ttDot); + + until false; Recognise(ttSemicolon); PopNode; end; + function TBuildParseTree.GenericAhead: boolean; var liTokenIndex: integer; @@ -5000,22 +5009,26 @@ begin Recognise(IdentiferTokens); { tokens can be qualified by a unit name } + { can be nested types } if pbCanHaveUnitQualifier and (fcTokenList.FirstSolidTokenType = ttDot) then begin - Recognise(ttDot); + while fcTokenList.FirstSolidTokenType = ttDot do + begin + Recognise(ttDot); - { delphi.net can preface the identifier with an '&' - in order to do something obscure with it - make it a literal or something + { delphi.net can preface the identifier with an '&' + in order to do something obscure with it - make it a literal or something - e.g. "WebRequest.&Create" is not a constructor, - but a C# method called "Create", which is not a reserved word in C# - } + e.g. "WebRequest.&Create" is not a constructor, + but a C# method called "Create", which is not a reserved word in C# + } - RecognisePossiblyAmpdIdentifier; + RecognisePossiblyAmpdIdentifier; + end; end; PopNode; -end; +end; { the name of a procedure/function/constructor can be a plain name or classname.methodname @@ -5125,9 +5138,14 @@ begin // a use not a decl RecogniseGenericType; end; - + if fcTokenList.FirstSolidTokenType = ttDot then + begin + Recognise(ttDot); + RecogniseTypeId; + end; end; + procedure TBuildParseTree.RecogniseAsmBlock; begin PushNode(nAsm); @@ -5432,7 +5450,7 @@ begin begin lcLastChar := lcNext.SourceCode[Length(lcNext.SourceCode)]; - if (lcLastChar = 'h') then + if ((lcLastChar = 'h') or (lcLastChar = 'H')) then begin Recognise(ttIdentifier); end; diff --git a/components/jcf2/Parse/BuildTokenList.pas b/components/jcf2/Parse/BuildTokenList.pas index 773c22430d..e2e0fbce9f 100644 --- a/components/jcf2/Parse/BuildTokenList.pas +++ b/components/jcf2/Parse/BuildTokenList.pas @@ -124,6 +124,13 @@ begin Result := IsMultiByte(pcChar); end; +function CharIsOctDigit(const c: Char): Boolean; +const + OctDigits: set of Char = [ '0', '1', '2', '3', '4', '5', '6', '7']; +begin + Result := (c in OctDigits); +end; + { TBuildTokenList } constructor TBuildTokenList.Create; @@ -468,14 +475,32 @@ end; function TBuildTokenList.TryWord(const pcToken: TSourceToken): boolean; + begin Result := False; - if not CharIsWordChar(Current) then - exit; - - pcToken.SourceCode := Current; - Consume; + // support reserved words as identifiers + // example. + // var &type:integer; + if Current='&' then + begin + if CharIsOctDigit(ForwardChar(1)) then + Exit; + pcToken.SourceCode := Current; + Consume; + if not CharIsWordChar(Current) then + begin + pcToken.TokenType := ttAmpersand; + exit; + end; + end + else + begin + if not CharIsWordChar(Current) then + exit; + pcToken.SourceCode := Current; + Consume; + end; { concat any subsequent word chars } while CharIsWordChar(Current) or CharIsDigit(Current) do @@ -691,13 +716,6 @@ end; { ~pktb 2017.05.19 - Oct numbers are prefixed with & } function TBuildTokenList.TryOctNumber(const pcToken: TSourceToken): boolean; -function CharIsOctDigit(const c: Char): Boolean; -const - OctDigits: set of AnsiChar = [ - '0', '1', '2', '3', '4', '5', '6', '7']; -begin - Result := (c in OctDigits); -end; begin Result := False; @@ -705,6 +723,16 @@ begin if Current <> '&' then exit; + //ISN'T A Octal Number. + if not CharIsOctDigit(ForwardChar(1)) then + begin + pcToken.TokenType := ttAmpersand; + pcToken.SourceCode := Current; + Consume; + result:=true; + exit; + end; + pcToken.TokenType := ttNumber; pcToken.SourceCode := Current; Consume;