text
stringlengths
0
234
begin
Current := Current + 1;
end Ignore;
function Peek return Character is
begin
if Is_At_End then
return NUL;
else
return Source (Current);
end if;
end Peek;
function Peek_Next return Character is
begin
if Current + 1 > Source'Last then
return NUL;
else
return Source (Current + 1);
end if;
end Peek_Next;
procedure Scan_Identifier is
-- use Hashed_Maps;
begin
while Is_Alphanumeric (Peek)
or else Peek = '_' loop
pragma Loop_Invariant (Start <= Current);
pragma Loop_Invariant (Source'First <= Current and then Current <= Source'Last);
pragma Loop_Invariant (Start = Start'Loop_Entry);
pragma Loop_Invariant (Current >= Current'Loop_Entry);
Ignore;
end loop;
declare
Text : constant L_String := L_Strings.To_Bounded_String (Source (Start .. Current - 1));
begin
-- if Contains (Keywords, Text) then
-- Add_Token (Element (Keywords, Text));
if Text = "and" then
Add_Token (T_AND);
elsif Text = "class" then
Add_Token (T_CLASS);
elsif Text = "else" then
Add_Token (T_ELSE);
elsif Text = "false" then
Add_Token (T_FALSE);
elsif Text = "for" then
Add_Token (T_FOR);
elsif Text = "fun" then
Add_Token (T_FUN);
elsif Text = "if" then
Add_Token (T_IF);
elsif Text = "nil" then
Add_Token (T_NIL);
elsif Text = "or" then
Add_Token (T_OR);
elsif Text = "print" then
Add_Token (T_PRINT);
elsif Text = "return" then
Add_Token (T_RETURN);
elsif Text = "super" then
Add_Token (T_SUPER);
elsif Text = "this" then
Add_Token (T_THIS);
elsif Text = "true" then
Add_Token (T_TRUE);
elsif Text = "var" then
Add_Token (T_VAR);
elsif Text = "while" then
Add_Token (T_WHILE);
else
Add_Token (T_IDENTIFIER);
end if;
Function Definition: procedure Sort is new Ada.Containers.Generic_Anonymous_Array_Sort
Function Body: (Index_Type => Natural,
Less => Less,
Swap => Swap);
Text : League.Strings.Universal_String;
ASCII : constant League.Text_Codecs.Text_Codec :=
League.Text_Codecs.Codec (+"USASCII");
begin
for J in Map'Range loop
Map (J) := J;
end loop;
Sort (Map'First, Map'Last);
Text.Append ("{");
for J of Map loop
if Text.Length > 1 then
Text.Append (",");
end if;
Text.Append ('"');
Text.Append (Keys (J));
Text.Append (""":""");
Text.Append (Key.Value (Keys (J)).To_String);