commit 99a7fb9aa2b70b2fe3e8725bb4ca13b2f0f4c429
parent 15bd18352c4405d2e5095d27ef93386b71763aee
Author: citbl <citbl@citbl.org>
Date: Tue, 9 Jun 2026 22:09:27 +1000
fix pedantic warnings (and bugs by association)
Diffstat:
2 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/src/lexer.adb b/src/lexer.adb
@@ -1,11 +1,10 @@
-with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Handling; use Ada.Characters.Handling;
package body Lexer is
function Init (File_Name : File_Name_Ref; File_Contents : Source_Ref) return Lexer is
- L : Lexer :=
+ L : constant Lexer :=
(Source => File_Contents,
File_Name => File_Name,
Tokens => Token_Vector.Empty_Vector,
@@ -90,7 +89,6 @@ package body Lexer is
-- make ident
function Make_Ident (L : in out Lexer) return Token is
- C : Character;
T : Token;
TK : Token_Kind;
Start : Natural;
@@ -153,15 +151,16 @@ package body Lexer is
-- make number
function Make_Number (L : in out Lexer) return Token is
- T : Token;
- Start : Natural;
- Is_Float : Boolean := false;
- Line : Positive;
- Col : Positive;
+ T : Token;
+ Kind : Token_Kind;
+ Start : Natural;
+ Line : Positive;
+ Col : Positive;
begin
Start := L.Pos;
Line := L.Line;
Col := L.Col;
+ Kind := Int_Literal;
if Peek (L) = '-' then
Nudge (L);
@@ -172,14 +171,15 @@ package body Lexer is
end loop;
if Peek (L) = '.' and Is_Digit (Peek2 (L)) then
- Is_Float := true;
+ Kind := Float_Literal;
Nudge (L);
while Is_Digit (Peek (L)) loop
Nudge (L);
end loop;
end if;
+
T :=
- (Kind => Str_Literal,
+ (Kind => Kind,
Lexeme => To_Unbounded_String (L.Source (Start .. L.Pos - 1)),
Line => Line,
Col => Col);
@@ -222,17 +222,15 @@ package body Lexer is
-- next token
function Next_Token (L : in out Lexer) return Token is
- T : Token;
- TK : Token_Kind;
- Start : Natural;
- C : Character;
- C2 : Character;
- Line : Positive;
- Col : Positive;
+ T : Token;
+ TK : Token_Kind;
+ C : Character;
+ C2 : Character;
+ Line : Positive;
+ Col : Positive;
begin
Handle_Space_Comments (L);
- Start := L.Pos;
Line := L.Line;
Col := L.Col;
@@ -322,7 +320,7 @@ package body Lexer is
procedure Print_Tokens (L : in out Lexer) is
I : Natural := 0;
- Total : Natural := Natural (L.Tokens.Length);
+ Total : constant Natural := Natural (L.Tokens.Length);
begin
Put_Line ("total: " & (L.Tokens.Length'Image) & " tokens");
diff --git a/src/nightshade.adb b/src/nightshade.adb
@@ -1,7 +1,5 @@
-with Ada.Text_IO; use Ada.Text_IO;
-with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
-with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;
-with Ada.Command_Line; use Ada.Command_Line;
+with Ada.Text_IO; use Ada.Text_IO;
+with Ada.Command_Line; use Ada.Command_Line;
with Utils;
with Lexer;
with Parser;
@@ -27,7 +25,7 @@ begin
declare
P : Parser.Parser := Parser.Init (File_Name_Ref, Src_Ref, L.Tokens);
begin
- Parser.Parse(P);
+ Parser.Parse (P);
Parser.Print_AST (P);
end;
end;