@@ -328,12 +328,41 @@ package body LSP.GPR_Files is
328
328
end Add_Symbol ;
329
329
330
330
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
+ -- ------------------
333
354
334
355
function Previous_Token
335
356
(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 ;
337
366
338
367
-- -------------------------
339
368
-- Close_Current_Package --
@@ -445,6 +474,26 @@ package body LSP.GPR_Files is
445
474
procedure Parse_Variable (Variable_Token : GPR_Token);
446
475
procedure Parse_Package ;
447
476
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 ;
448
497
449
498
-- -------------------
450
499
-- Parse_Attribute --
@@ -469,6 +518,7 @@ package body LSP.GPR_Files is
469
518
Attribute_Token := Get_GPR_Token (Index);
470
519
if Attribute_Token.Kind /= Gpr_Parser.Common.Gpr_Identifier
471
520
then
521
+ Previous_Token_If_Needed;
472
522
return ;
473
523
end if ;
474
524
else
@@ -533,6 +583,7 @@ package body LSP.GPR_Files is
533
583
(To_Unbounded_String (Image (Name))) & Image (Attr_Index),
534
584
Children => GPC.No_Token);
535
585
end ;
586
+ Previous_Token_If_Needed;
536
587
end Parse_Attribute ;
537
588
538
589
-- -------------
@@ -547,6 +598,8 @@ package body LSP.GPR_Files is
547
598
Token := Get_GPR_Token (Index);
548
599
if Token.Kind = Gpr_Parser.Common.Gpr_Identifier then
549
600
Close_Current_Package (Index);
601
+ elsif Token.Kind /= Gpr_Parser.Common.Gpr_Case then
602
+ Previous_Token_If_Needed;
550
603
end if ;
551
604
end if ;
552
605
end Parse_End ;
@@ -624,6 +677,7 @@ package body LSP.GPR_Files is
624
677
Current_Symbols.Clear;
625
678
end if ;
626
679
else
680
+ Previous_Token_If_Needed;
627
681
return ;
628
682
end if ;
629
683
else
@@ -651,6 +705,7 @@ package body LSP.GPR_Files is
651
705
when others =>
652
706
null ;
653
707
end case ;
708
+ Previous_Token_If_Needed;
654
709
else
655
710
return ;
656
711
end if ;
@@ -686,6 +741,7 @@ package body LSP.GPR_Files is
686
741
end if ;
687
742
Index := Next_Token (Index);
688
743
end if ;
744
+ Previous_Token_If_Needed;
689
745
end if ;
690
746
end Parse_Type ;
691
747
@@ -728,6 +784,7 @@ package body LSP.GPR_Files is
728
784
end case ;
729
785
Index := Next_Token (Index);
730
786
end loop ;
787
+ Previous_Token_If_Needed;
731
788
end Parse_Variable ;
732
789
733
790
Previous_Token : GPR_Token;
@@ -915,6 +972,9 @@ package body LSP.GPR_Files is
915
972
916
973
begin
917
974
975
+ -- Reset project kind to default value.
976
+ File.Kind := GPR2.K_Standard;
977
+
918
978
Search_Paths.Prepend (File.Path.Containing_Directory);
919
979
File.Name := +To_String (Project_Name);
920
980
0 commit comments