nightshade

The nightshade programming language, compiler and tools (WIP)
Log | Files | Refs

commit 97eebbc7d3893d46deaf5e720cce897a70731789
parent cdd0ac0625fd932e49a286653eea31f797fa28bd
Author: citbl <citbl@citbl.org>
Date:   Fri, 29 May 2026 23:04:54 +1000

lexer wip

Diffstat:
Msrc/lexer.adb | 23+++++++++++++++++++++--
Msrc/lexer.ads | 14+++++++++-----
Msrc/nightshade.adb | 6+++++-
3 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/src/lexer.adb b/src/lexer.adb @@ -1,7 +1,26 @@ -package Lexer is - procedure Lex (L : in out Lexer) is +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 : String; File_Contents : String) return Lexer is + L : Lexer := + (Source => To_Unbounded_String (File_Contents), + File_Name => To_Unbounded_String (File_Name), + Tokens => Token_Vectors.Empty_Vector); begin + return L; + end Init; + + procedure Lex (L : in out Lexer) is + SRC : constant String := To_String (L.Source); + begin + Put_Line (Natural'Image (Length (L.Source))); + for C of SRC loop + Put_Line (C'Image); + end loop; end; end Lexer; diff --git a/src/lexer.ads b/src/lexer.ads @@ -1,4 +1,5 @@ -with Ada.Containers.Vectors; use Ada.Containers.Vectors; +with Ada.Containers.Vectors; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package Lexer is @@ -7,17 +8,20 @@ package Lexer is type Token is record Kind : Token_Type; - Lexeme : String; + Lexeme : Unbounded_String; Line, Col : Positive; end record; package Token_Vectors is new - Vectors (Index_Type => Natural, Element_Type => Token); + Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Token); type Lexer is record - Source : String; - File_Name : String; + Source : Unbounded_String; + File_Name : Unbounded_String; Tokens : Token_Vectors.Vector; end record; + + function Init (File_Name : String; File_Contents : String) return Lexer; + procedure Lex (L : in out Lexer); end Lexer; diff --git a/src/nightshade.adb b/src/nightshade.adb @@ -1,5 +1,6 @@ with Ada.Text_IO; use Ada.Text_IO; with Utils; use Utils; +with Lexer; 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; @@ -14,7 +15,10 @@ begin declare File_Name : constant String := Argument (1); File_Contents : constant String := Utils.Load_Contents (File_Name); + L : Lexer.Lexer := Lexer.Init (File_Name, File_Contents); begin - Put_Line (File_Contents); + -- Put_Line (File_Contents); + Lexer.Lex (L); + Put_Line ("done?"); end; end Nightshade;