@@ -328,12 +328,41 @@ package body LSP.GPR_Files is
328328 end Add_Symbol ;
329329
330330 function Next_Token
331- (Ref : GPC.Token_Reference) return GPC.Token_Reference
332- is (Next (Ref, True));
331+ (Ref : GPC.Token_Reference) return GPC.Token_Reference;
332+
333+ function Previous_Token
334+ (Ref : GPC.Token_Reference) return GPC.Token_Reference;
335+
336+ -- --------------
337+ -- Next_Token --
338+ -- --------------
339+
340+ function Next_Token
341+ (Ref : GPC.Token_Reference) return GPC.Token_Reference is
342+ Result : constant GPC.Token_Reference := Next (Ref, True);
343+ begin
344+ if Result = GPC.No_Token then
345+ return File.Unit.Last_Token;
346+ else
347+ return Result;
348+ end if ;
349+ end Next_Token ;
350+
351+ -- ------------------
352+ -- Previous_Token --
353+ -- ------------------
333354
334355 function Previous_Token
335356 (Ref : GPC.Token_Reference) return GPC.Token_Reference
336- is (Previous (Ref, True));
357+ is
358+ Result : constant GPC.Token_Reference := Previous (Ref, True);
359+ begin
360+ if Result = GPC.No_Token then
361+ return File.Unit.First_Token;
362+ else
363+ return Result;
364+ end if ;
365+ end Previous_Token ;
337366
338367 -- -------------------------
339368 -- Close_Current_Package --
@@ -445,6 +474,26 @@ package body LSP.GPR_Files is
445474 procedure Parse_Variable (Variable_Token : GPR_Token);
446475 procedure Parse_Package ;
447476 procedure Parse_End ;
477+ procedure Previous_Token_If_Needed ;
478+
479+ -- ----------------------------
480+ -- Previous_Token_If_Needed --
481+ -- ----------------------------
482+
483+ procedure Previous_Token_If_Needed is
484+ Token : constant GPR_Token := Get_GPR_Token (Index);
485+ begin
486+ if Token.Kind in
487+ Gpr_Parser.Common.Gpr_Package
488+ | Gpr_Parser.Common.Gpr_Type
489+ | Gpr_Parser.Common.Gpr_For
490+ | Gpr_Parser.Common.Gpr_End
491+ | Gpr_Parser.Common.Gpr_Case
492+ | Gpr_Parser.Common.Gpr_When
493+ then
494+ Index := Previous_Token (Index);
495+ end if ;
496+ end Previous_Token_If_Needed ;
448497
449498 -- -------------------
450499 -- Parse_Attribute --
@@ -469,6 +518,7 @@ package body LSP.GPR_Files is
469518 Attribute_Token := Get_GPR_Token (Index);
470519 if Attribute_Token.Kind /= Gpr_Parser.Common.Gpr_Identifier
471520 then
521+ Previous_Token_If_Needed;
472522 return ;
473523 end if ;
474524 else
@@ -533,6 +583,7 @@ package body LSP.GPR_Files is
533583 (To_Unbounded_String (Image (Name))) & Image (Attr_Index),
534584 Children => GPC.No_Token);
535585 end ;
586+ Previous_Token_If_Needed;
536587 end Parse_Attribute ;
537588
538589 -- -------------
@@ -547,6 +598,8 @@ package body LSP.GPR_Files is
547598 Token := Get_GPR_Token (Index);
548599 if Token.Kind = Gpr_Parser.Common.Gpr_Identifier then
549600 Close_Current_Package (Index);
601+ elsif Token.Kind /= Gpr_Parser.Common.Gpr_Case then
602+ Previous_Token_If_Needed;
550603 end if ;
551604 end if ;
552605 end Parse_End ;
@@ -624,6 +677,7 @@ package body LSP.GPR_Files is
624677 Current_Symbols.Clear;
625678 end if ;
626679 else
680+ Previous_Token_If_Needed;
627681 return ;
628682 end if ;
629683 else
@@ -651,6 +705,7 @@ package body LSP.GPR_Files is
651705 when others =>
652706 null ;
653707 end case ;
708+ Previous_Token_If_Needed;
654709 else
655710 return ;
656711 end if ;
@@ -686,6 +741,7 @@ package body LSP.GPR_Files is
686741 end if ;
687742 Index := Next_Token (Index);
688743 end if ;
744+ Previous_Token_If_Needed;
689745 end if ;
690746 end Parse_Type ;
691747
@@ -728,6 +784,7 @@ package body LSP.GPR_Files is
728784 end case ;
729785 Index := Next_Token (Index);
730786 end loop ;
787+ Previous_Token_If_Needed;
731788 end Parse_Variable ;
732789
733790 Previous_Token : GPR_Token;
@@ -915,6 +972,9 @@ package body LSP.GPR_Files is
915972
916973 begin
917974
975+ -- Reset project kind to default value.
976+ File.Kind := GPR2.K_Standard;
977+
918978 Search_Paths.Prepend (File.Path.Containing_Directory);
919979 File.Name := +To_String (Project_Name);
920980
0 commit comments