commit 7c72e44ab79f728eb9c77b34df8eb788c15df3fd
parent f5940714e6810f25fcfd37432cd877323f65957e
Author: citbl <citbl@citbl.org>
Date: Mon, 1 Jun 2026 20:01:39 +1000
print tokens
Diffstat:
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/src/lexer.adb b/src/lexer.adb
@@ -186,8 +186,8 @@ package body Lexer is
C : Character;
T : Token;
Start : Natural;
- Line : Positive;
- Col : Positive;
+ Line : Positive;
+ Col : Positive;
begin
Start := L.Pos;
Line := L.Line;
@@ -202,9 +202,6 @@ package body Lexer is
Nudge (L);
end loop;
- -- Put_Line("made string of " & Integer'Image(L.Pos-Start));
- -- Put_Line (L.Source (Start .. L.Pos));
-
T :=
(Kind => Str_Literal,
Lexeme => To_Unbounded_String (L.Source (Start .. L.Pos)),
@@ -280,4 +277,24 @@ package body Lexer is
end Lex;
+ procedure Print_Tokens (L : in out Lexer) is
+ I : Natural := 0;
+ Total : Natural := Natural (L.Tokens.Length);
+ begin
+ Put_Line ("total: " & (L.Tokens.Length'Image));
+
+ while I < Total loop
+ Put_Line
+ (Integer'Image (L.Tokens (I).Line)
+ & ":"
+ & Integer'Image (L.Tokens (I).Col)
+ & ": "
+ & Token_Kind'Image (L.Tokens (I).Kind)
+ & ": "
+ & To_String (L.Tokens (I).Lexeme)
+ & " at line");
+ I := I + 1;
+ end loop;
+ end;
+
end Lexer;
diff --git a/src/lexer.ads b/src/lexer.ads
@@ -32,5 +32,7 @@ package Lexer is
function Init (File_Name : String; File_Contents : String) return Lexer;
+ procedure Print_Tokens(L : in out Lexer);
+
procedure Lex (L : in out Lexer);
end Lexer;
diff --git a/src/nightshade.adb b/src/nightshade.adb
@@ -18,6 +18,7 @@ begin
L : Lexer.Lexer := Lexer.Init (File_Name, File_Contents);
begin
Lexer.Lex (L);
+ Lexer.Print_Tokens(L);
Put_Line ("");
Put_Line ("done");
end;