enhanced rune.hawk with the string conversion feature

This commit is contained in:
hyung-hwan 2021-10-31 16:03:11 +00:00
parent 483ee39dac
commit db230f8807
6 changed files with 175 additions and 135 deletions

View File

@ -1,6 +1,8 @@
with ada.text_io;
package body H3.Compilers is
LB_EOF: constant S.Rune_Array := (R.V.Left_Arrow,R.V.UC_E,R.V.UC_O,R.V.UC_F,R.V.Right_Arrow); -- <EOF>
procedure Set_Lexer_State (C: in out Compiler; State: in Lexer_State) is
begin
C.Lx.State := State;
@ -26,7 +28,14 @@ package body H3.Compilers is
-- null;
--end case;
ada.text_io.put_line (C.Tk.Id'Img);
ada.text_io.put (C.Tk.Id'Img);
ada.text_io.put (" ");
for i in C.Tk.Buf.Get_First_Index .. C.Tk.Buf.Get_Last_Index loop
ada.text_io.put (standard.character'val(S.Rune'Pos(C.Tk.Buf.Get_Item(i))));
end loop;
ada.text_io.put_line("");
case C.Tk.Id is
when TK_BSTR =>
null;
@ -123,7 +132,7 @@ ada.text_io.put_line (C.Tk.Id'Img);
case C.Lx.State is
when LX_START =>
if R.Is_Eof(Code) then
Start_Token (C, S.Rune_Array'(R.V.Left_Arrow, R.V.UC_E, R.V.UC_O, R.V.UC_F, R.V.Right_Arrow));
Start_Token (C, LB_EOF);
End_Token (C, TK_EOF);
-- this procedure doesn't prevent you from feeding more
-- after EOF. but it's not desirable to feed more after EOF.
@ -191,7 +200,7 @@ ada.text_io.put_line (C.Tk.Id'Img);
procedure End_Feed (C: in out Compiler) is
begin
Feed_Char_Code (C, R.EOF);
Feed_Char_Code (C, R.P.EOF);
end End_Feed;
end H3.Compilers;

View File

@ -169,7 +169,7 @@ package body H3.Runes is
function Is_Eof (C: in Code) return Boolean is
begin
return C = EOF;
return C = P.EOF;
end Is_Eof;
function Is_Code (V: in Rune; C: in Code) return Boolean is

View File

@ -10,137 +10,138 @@ package H3.Runes is
type Code is range -1 .. 16#7FFF_FFFF#;
-- virtual code to indicate end of input
EOF: constant Code := Code'First;
--EOF: constant Code := Code'First;
package P is
NUL : constant := 0;
SOH : constant := 1;
STX : constant := 2;
ETX : constant := 3;
EOT : constant := 4;
ENQ : constant := 5;
ACK : constant := 6;
BEL : constant := 7;
BS : constant := 8;
HT : constant := 9;
LF : constant := 10;
VT : constant := 11;
FF : constant := 12;
CR : constant := 13;
SO : constant := 14;
SI : constant := 15;
DLE : constant := 16;
DC1 : constant := 17;
DC2 : constant := 18;
DC3 : constant := 19;
DC4 : constant := 20;
NAK : constant := 21;
SYN : constant := 22;
ETB : constant := 23;
CAN : constant := 24;
EM : constant := 25;
SUB : constant := 26;
ESC : constant := 27;
FS : constant := 28;
GS : constant := 29;
RS : constant := 30;
US : constant := 31;
Space : constant := 32; --
Exclamation : constant := 33; -- !
Quotation : constant := 34; -- "
Number_Sign : constant := 35; -- #
Dollar_Sign : constant := 36; -- $
Percent_Sign : constant := 37; -- %
Ampersand : constant := 38; -- &
Apostrophe : constant := 39; -- '
Left_Parenthesis : constant := 40; -- (
Right_Parenthesis : constant := 41; -- )
Asterisk : constant := 42; -- *
Plus_Sign : constant := 43; -- +
Comma : constant := 44; -- ,
Minus_Sign : constant := 45; -- -
Period : constant := 46; -- .
Slash : constant := 47; -- /
Zero : constant := 48; -- 0
One : constant := 49; -- 1
Two : constant := 50; -- 2
Three : constant := 51; -- 3
Four : constant := 52; -- 4
Five : constant := 53; -- 5
Six : constant := 54; -- 6
Seven : constant := 55; -- 7
Eight : constant := 56; -- 8
Nine : constant := 57; -- 9
Colon : constant := 58; -- :
Semicolon : constant := 59; -- ;
Left_Arrow : constant := 60; -- <
Equal_Sign : constant := 61; -- =
Right_Arrow : constant := 62; -- >
Question : constant := 63; -- ?
Commercial_At : constant := 64; -- @
UC_A : constant := 65; -- A
UC_B : constant := 66; -- B
UC_C : constant := 67; -- C
UC_D : constant := 68; -- D
UC_E : constant := 69; -- E
UC_F : constant := 70; -- F
UC_G : constant := 71; -- G
UC_H : constant := 72; -- H
UC_I : constant := 73; -- I
UC_J : constant := 74; -- J
UC_K : constant := 75; -- K
UC_L : constant := 76; -- L
UC_M : constant := 77; -- M
UC_N : constant := 78; -- N
UC_O : constant := 79; -- O
UC_P : constant := 80; -- P
UC_Q : constant := 81; -- Q
UC_R : constant := 82; -- R
UC_S : constant := 83; -- S
UC_T : constant := 84; -- T
UC_U : constant := 85; -- U
UC_V : constant := 86; -- V
UC_W : constant := 87; -- W
UC_X : constant := 88; -- X
UC_Y : constant := 89; -- Y
UC_Z : constant := 90; -- Z
Left_Square_Bracket : constant := 91; -- [
Backslash : constant := 92; -- \
Right_Square_Bracket: constant := 93; -- ]
Circumflex : constant := 94; -- ^
Underline : constant := 95; -- _
Grave : constant := 96; -- `
LC_A : constant := 97; -- a
LC_B : constant := 98; -- b
LC_C : constant := 99; -- c
LC_D : constant := 100; -- d
LC_E : constant := 101; -- e
LC_F : constant := 102; -- f
LC_G : constant := 103; -- g
LC_H : constant := 104; -- h
LC_I : constant := 105; -- i
LC_J : constant := 106; -- j
LC_K : constant := 107; -- k
LC_L : constant := 108; -- l
LC_M : constant := 109; -- m
LC_N : constant := 110; -- n
LC_O : constant := 111; -- o
LC_P : constant := 112; -- p
LC_Q : constant := 113; -- q
LC_R : constant := 114; -- r
LC_S : constant := 115; -- s
LC_T : constant := 116; -- t
LC_U : constant := 117; -- u
LC_V : constant := 118; -- v
LC_W : constant := 119; -- w
LC_X : constant := 120; -- x
LC_Y : constant := 121; -- y
LC_Z : constant := 122; -- z
Left_Curly_Bracket : constant := 123; -- {
Vertical_Line : constant := 124; -- |
Right_Curly_Bracket : constant := 125; -- }
Tilde : constant := 126; -- ~
DEL : constant := 127;
EOF : constant Code := -1; -- Code'First
NUL : constant Code := 0;
SOH : constant Code := 1;
STX : constant Code := 2;
ETX : constant Code := 3;
EOT : constant Code := 4;
ENQ : constant Code := 5;
ACK : constant Code := 6;
BEL : constant Code := 7;
BS : constant Code := 8;
HT : constant Code := 9;
LF : constant Code := 10;
VT : constant Code := 11;
FF : constant Code := 12;
CR : constant Code := 13;
SO : constant Code := 14;
SI : constant Code := 15;
DLE : constant Code := 16;
DC1 : constant Code := 17;
DC2 : constant Code := 18;
DC3 : constant Code := 19;
DC4 : constant Code := 20;
NAK : constant Code := 21;
SYN : constant Code := 22;
ETB : constant Code := 23;
CAN : constant Code := 24;
EM : constant Code := 25;
SUB : constant Code := 26;
ESC : constant Code := 27;
FS : constant Code := 28;
GS : constant Code := 29;
RS : constant Code := 30;
US : constant Code := 31;
Space : constant Code := 32; --
Exclamation : constant Code := 33; -- !
Quotation : constant Code := 34; -- "
Number_Sign : constant Code := 35; -- #
Dollar_Sign : constant Code := 36; -- $
Percent_Sign : constant Code := 37; -- %
Ampersand : constant Code := 38; -- &
Apostrophe : constant Code := 39; -- '
Left_Parenthesis : constant Code := 40; -- (
Right_Parenthesis : constant Code := 41; -- )
Asterisk : constant Code := 42; -- *
Plus_Sign : constant Code := 43; -- +
Comma : constant Code := 44; -- ,
Minus_Sign : constant Code := 45; -- -
Period : constant Code := 46; -- .
Slash : constant Code := 47; -- /
Zero : constant Code := 48; -- 0
One : constant Code := 49; -- 1
Two : constant Code := 50; -- 2
Three : constant Code := 51; -- 3
Four : constant Code := 52; -- 4
Five : constant Code := 53; -- 5
Six : constant Code := 54; -- 6
Seven : constant Code := 55; -- 7
Eight : constant Code := 56; -- 8
Nine : constant Code := 57; -- 9
Colon : constant Code := 58; -- :
Semicolon : constant Code := 59; -- ;
Left_Arrow : constant Code := 60; -- <
Equal_Sign : constant Code := 61; -- =
Right_Arrow : constant Code := 62; -- >
Question : constant Code := 63; -- ?
Commercial_At : constant Code := 64; -- @
UC_A : constant Code := 65; -- A
UC_B : constant Code := 66; -- B
UC_C : constant Code := 67; -- C
UC_D : constant Code := 68; -- D
UC_E : constant Code := 69; -- E
UC_F : constant Code := 70; -- F
UC_G : constant Code := 71; -- G
UC_H : constant Code := 72; -- H
UC_I : constant Code := 73; -- I
UC_J : constant Code := 74; -- J
UC_K : constant Code := 75; -- K
UC_L : constant Code := 76; -- L
UC_M : constant Code := 77; -- M
UC_N : constant Code := 78; -- N
UC_O : constant Code := 79; -- O
UC_P : constant Code := 80; -- P
UC_Q : constant Code := 81; -- Q
UC_R : constant Code := 82; -- R
UC_S : constant Code := 83; -- S
UC_T : constant Code := 84; -- T
UC_U : constant Code := 85; -- U
UC_V : constant Code := 86; -- V
UC_W : constant Code := 87; -- W
UC_X : constant Code := 88; -- X
UC_Y : constant Code := 89; -- Y
UC_Z : constant Code := 90; -- Z
Left_Square_Bracket : constant Code := 91; -- [
Backslash : constant Code := 92; -- \
Right_Square_Bracket: constant Code := 93; -- ]
Circumflex : constant Code := 94; -- ^
Underline : constant Code := 95; -- _
Grave : constant Code := 96; -- `
LC_A : constant Code := 97; -- a
LC_B : constant Code := 98; -- b
LC_C : constant Code := 99; -- c
LC_D : constant Code := 100; -- d
LC_E : constant Code := 101; -- e
LC_F : constant Code := 102; -- f
LC_G : constant Code := 103; -- g
LC_H : constant Code := 104; -- h
LC_I : constant Code := 105; -- i
LC_J : constant Code := 106; -- j
LC_K : constant Code := 107; -- k
LC_L : constant Code := 108; -- l
LC_M : constant Code := 109; -- m
LC_N : constant Code := 110; -- n
LC_O : constant Code := 111; -- o
LC_P : constant Code := 112; -- p
LC_Q : constant Code := 113; -- q
LC_R : constant Code := 114; -- r
LC_S : constant Code := 115; -- s
LC_T : constant Code := 116; -- t
LC_U : constant Code := 117; -- u
LC_V : constant Code := 118; -- v
LC_W : constant Code := 119; -- w
LC_X : constant Code := 120; -- x
LC_Y : constant Code := 121; -- y
LC_Z : constant Code := 122; -- z
Left_Curly_Bracket : constant Code := 123; -- {
Vertical_Line : constant Code := 124; -- |
Right_Curly_Bracket : constant Code := 125; -- }
Tilde : constant Code := 126; -- ~
DEL : constant Code := 127;
end P;
package V is

View File

@ -3,6 +3,17 @@ package body H3.Strings is
procedure Append (Obj: in out Elastic_String; V: in Rune_Array) is
begin
P.Append (P.Elastic_Array(Obj), V);
end;
end Append;
function Get_Rune (Obj: in Elastic_String; Pos: in System_Index) return Rune is
begin
return P.Get_Item(P.Elastic_Array(Obj), Pos);
end Get_Rune;
function To_Rune_Array (Obj: in Elastic_String) return Rune_Array is
begin
return P.To_Item_Array(P.Elastic_Array(Obj));
end To_Rune_Array;
end H3.Strings;

View File

@ -18,6 +18,9 @@ package H3.Strings is
null;
end record;
function Get_Rune (Obj: in Elastic_String; Pos: in System_Index) return Rune;
function To_Rune_Array (Obj: in Elastic_String) return Rune_Array;
overriding procedure Append (Obj: in out Elastic_String; V: in Rune_Array);
end H3.Strings;

View File

@ -8,13 +8,14 @@ BEGIN {
printf ("package H2.Runes is\n\n");
#printf ("\tpragma Preelaborate (Runes);\n\n");
printf ("\tpackage P is\n");
printf ("\t\t\%-20s: constant Code := %d; -- Code'First\n", "EOF", -1);
}
{
t = sprintf ("%c", NR - 1);
if (str::isprint(t)) t = " -- " t;
else t="";
printf ("\t\t%-20s: constant := %d;%s\n", $1, NR-1, t);
printf ("\t\t%-20s: constant Code := %d;%s\n", $1, NR-1, t);
X[NR - 1] = $1;
}
@ -31,4 +32,19 @@ END {
printf ("\n");
printf ("\nend H2.Runes;\n");
if (STR !== @nil)
{
printf ("(");
for (j = 1; j <= length(STR); j++)
{
tmp = substr(STR, j, 1);
if (j > 1) printf (",");
printf ("R.V.%s", X[str::tocharcode(tmp)]);
}
printf (") -- %s", STR);
}
}