nightshade

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

lexer.ads (1239B)


      1 with Ada.Containers.Vectors;
      2 with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
      3 
      4 package Lexer is
      5 
      6    type Source_Ref is not null access constant String;
      7    type File_Name_Ref is not null access constant String;
      8 
      9    type Token_Kind is
     10      (Ident,
     11       Float_Literal,
     12       Int_Literal,
     13       Str_Literal,
     14       Bool_Literal,
     15       L_Paren,
     16       R_Paren,
     17       L_Bracket,
     18       R_Bracket,
     19       L_Brace,
     20       R_Brace,
     21       ColonColon,
     22       Colon,
     23       Comma,
     24       Separator,
     25       Keyword,
     26       Unknown,
     27       EOF);
     28 
     29    type Token is record
     30       Kind      : Token_Kind;
     31       Lexeme    : Unbounded_String;
     32       Line, Col : Positive;
     33    end record;
     34 
     35    package Token_Vector is new
     36      Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Token);
     37 
     38    type Lexer is record
     39       Source    : Source_Ref;
     40       File_Name : File_Name_Ref;
     41       Tokens    : Token_Vector.Vector;
     42       Pos       : Positive;
     43       Line      : Positive;
     44       Col       : Positive;
     45    end record;
     46 
     47    function Init
     48      (File_Name : File_Name_Ref; File_Contents : Source_Ref) return Lexer;
     49 
     50    procedure Add_Token (L : in out Lexer; T : Token);
     51    procedure Print_Tokens (L : in out Lexer);
     52 
     53    procedure Lex (L : in out Lexer);
     54 end Lexer;