enhanced rune.hawk with the string conversion feature
This commit is contained in:
parent
483ee39dac
commit
db230f8807
@ -1,6 +1,8 @@
|
|||||||
with ada.text_io;
|
with ada.text_io;
|
||||||
|
|
||||||
package body H3.Compilers is
|
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
|
procedure Set_Lexer_State (C: in out Compiler; State: in Lexer_State) is
|
||||||
begin
|
begin
|
||||||
C.Lx.State := State;
|
C.Lx.State := State;
|
||||||
@ -26,7 +28,14 @@ package body H3.Compilers is
|
|||||||
-- null;
|
-- null;
|
||||||
--end case;
|
--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
|
case C.Tk.Id is
|
||||||
when TK_BSTR =>
|
when TK_BSTR =>
|
||||||
null;
|
null;
|
||||||
@ -123,7 +132,7 @@ ada.text_io.put_line (C.Tk.Id'Img);
|
|||||||
case C.Lx.State is
|
case C.Lx.State is
|
||||||
when LX_START =>
|
when LX_START =>
|
||||||
if R.Is_Eof(Code) then
|
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);
|
End_Token (C, TK_EOF);
|
||||||
-- this procedure doesn't prevent you from feeding more
|
-- this procedure doesn't prevent you from feeding more
|
||||||
-- after EOF. but it's not desirable to feed more after EOF.
|
-- 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
|
procedure End_Feed (C: in out Compiler) is
|
||||||
begin
|
begin
|
||||||
Feed_Char_Code (C, R.EOF);
|
Feed_Char_Code (C, R.P.EOF);
|
||||||
end End_Feed;
|
end End_Feed;
|
||||||
|
|
||||||
end H3.Compilers;
|
end H3.Compilers;
|
||||||
|
@ -169,7 +169,7 @@ package body H3.Runes is
|
|||||||
|
|
||||||
function Is_Eof (C: in Code) return Boolean is
|
function Is_Eof (C: in Code) return Boolean is
|
||||||
begin
|
begin
|
||||||
return C = EOF;
|
return C = P.EOF;
|
||||||
end Is_Eof;
|
end Is_Eof;
|
||||||
|
|
||||||
function Is_Code (V: in Rune; C: in Code) return Boolean is
|
function Is_Code (V: in Rune; C: in Code) return Boolean is
|
||||||
|
@ -10,137 +10,138 @@ package H3.Runes is
|
|||||||
type Code is range -1 .. 16#7FFF_FFFF#;
|
type Code is range -1 .. 16#7FFF_FFFF#;
|
||||||
|
|
||||||
-- virtual code to indicate end of input
|
-- virtual code to indicate end of input
|
||||||
EOF: constant Code := Code'First;
|
--EOF: constant Code := Code'First;
|
||||||
|
|
||||||
package P is
|
package P is
|
||||||
NUL : constant := 0;
|
EOF : constant Code := -1; -- Code'First
|
||||||
SOH : constant := 1;
|
NUL : constant Code := 0;
|
||||||
STX : constant := 2;
|
SOH : constant Code := 1;
|
||||||
ETX : constant := 3;
|
STX : constant Code := 2;
|
||||||
EOT : constant := 4;
|
ETX : constant Code := 3;
|
||||||
ENQ : constant := 5;
|
EOT : constant Code := 4;
|
||||||
ACK : constant := 6;
|
ENQ : constant Code := 5;
|
||||||
BEL : constant := 7;
|
ACK : constant Code := 6;
|
||||||
BS : constant := 8;
|
BEL : constant Code := 7;
|
||||||
HT : constant := 9;
|
BS : constant Code := 8;
|
||||||
LF : constant := 10;
|
HT : constant Code := 9;
|
||||||
VT : constant := 11;
|
LF : constant Code := 10;
|
||||||
FF : constant := 12;
|
VT : constant Code := 11;
|
||||||
CR : constant := 13;
|
FF : constant Code := 12;
|
||||||
SO : constant := 14;
|
CR : constant Code := 13;
|
||||||
SI : constant := 15;
|
SO : constant Code := 14;
|
||||||
DLE : constant := 16;
|
SI : constant Code := 15;
|
||||||
DC1 : constant := 17;
|
DLE : constant Code := 16;
|
||||||
DC2 : constant := 18;
|
DC1 : constant Code := 17;
|
||||||
DC3 : constant := 19;
|
DC2 : constant Code := 18;
|
||||||
DC4 : constant := 20;
|
DC3 : constant Code := 19;
|
||||||
NAK : constant := 21;
|
DC4 : constant Code := 20;
|
||||||
SYN : constant := 22;
|
NAK : constant Code := 21;
|
||||||
ETB : constant := 23;
|
SYN : constant Code := 22;
|
||||||
CAN : constant := 24;
|
ETB : constant Code := 23;
|
||||||
EM : constant := 25;
|
CAN : constant Code := 24;
|
||||||
SUB : constant := 26;
|
EM : constant Code := 25;
|
||||||
ESC : constant := 27;
|
SUB : constant Code := 26;
|
||||||
FS : constant := 28;
|
ESC : constant Code := 27;
|
||||||
GS : constant := 29;
|
FS : constant Code := 28;
|
||||||
RS : constant := 30;
|
GS : constant Code := 29;
|
||||||
US : constant := 31;
|
RS : constant Code := 30;
|
||||||
Space : constant := 32; --
|
US : constant Code := 31;
|
||||||
Exclamation : constant := 33; -- !
|
Space : constant Code := 32; --
|
||||||
Quotation : constant := 34; -- "
|
Exclamation : constant Code := 33; -- !
|
||||||
Number_Sign : constant := 35; -- #
|
Quotation : constant Code := 34; -- "
|
||||||
Dollar_Sign : constant := 36; -- $
|
Number_Sign : constant Code := 35; -- #
|
||||||
Percent_Sign : constant := 37; -- %
|
Dollar_Sign : constant Code := 36; -- $
|
||||||
Ampersand : constant := 38; -- &
|
Percent_Sign : constant Code := 37; -- %
|
||||||
Apostrophe : constant := 39; -- '
|
Ampersand : constant Code := 38; -- &
|
||||||
Left_Parenthesis : constant := 40; -- (
|
Apostrophe : constant Code := 39; -- '
|
||||||
Right_Parenthesis : constant := 41; -- )
|
Left_Parenthesis : constant Code := 40; -- (
|
||||||
Asterisk : constant := 42; -- *
|
Right_Parenthesis : constant Code := 41; -- )
|
||||||
Plus_Sign : constant := 43; -- +
|
Asterisk : constant Code := 42; -- *
|
||||||
Comma : constant := 44; -- ,
|
Plus_Sign : constant Code := 43; -- +
|
||||||
Minus_Sign : constant := 45; -- -
|
Comma : constant Code := 44; -- ,
|
||||||
Period : constant := 46; -- .
|
Minus_Sign : constant Code := 45; -- -
|
||||||
Slash : constant := 47; -- /
|
Period : constant Code := 46; -- .
|
||||||
Zero : constant := 48; -- 0
|
Slash : constant Code := 47; -- /
|
||||||
One : constant := 49; -- 1
|
Zero : constant Code := 48; -- 0
|
||||||
Two : constant := 50; -- 2
|
One : constant Code := 49; -- 1
|
||||||
Three : constant := 51; -- 3
|
Two : constant Code := 50; -- 2
|
||||||
Four : constant := 52; -- 4
|
Three : constant Code := 51; -- 3
|
||||||
Five : constant := 53; -- 5
|
Four : constant Code := 52; -- 4
|
||||||
Six : constant := 54; -- 6
|
Five : constant Code := 53; -- 5
|
||||||
Seven : constant := 55; -- 7
|
Six : constant Code := 54; -- 6
|
||||||
Eight : constant := 56; -- 8
|
Seven : constant Code := 55; -- 7
|
||||||
Nine : constant := 57; -- 9
|
Eight : constant Code := 56; -- 8
|
||||||
Colon : constant := 58; -- :
|
Nine : constant Code := 57; -- 9
|
||||||
Semicolon : constant := 59; -- ;
|
Colon : constant Code := 58; -- :
|
||||||
Left_Arrow : constant := 60; -- <
|
Semicolon : constant Code := 59; -- ;
|
||||||
Equal_Sign : constant := 61; -- =
|
Left_Arrow : constant Code := 60; -- <
|
||||||
Right_Arrow : constant := 62; -- >
|
Equal_Sign : constant Code := 61; -- =
|
||||||
Question : constant := 63; -- ?
|
Right_Arrow : constant Code := 62; -- >
|
||||||
Commercial_At : constant := 64; -- @
|
Question : constant Code := 63; -- ?
|
||||||
UC_A : constant := 65; -- A
|
Commercial_At : constant Code := 64; -- @
|
||||||
UC_B : constant := 66; -- B
|
UC_A : constant Code := 65; -- A
|
||||||
UC_C : constant := 67; -- C
|
UC_B : constant Code := 66; -- B
|
||||||
UC_D : constant := 68; -- D
|
UC_C : constant Code := 67; -- C
|
||||||
UC_E : constant := 69; -- E
|
UC_D : constant Code := 68; -- D
|
||||||
UC_F : constant := 70; -- F
|
UC_E : constant Code := 69; -- E
|
||||||
UC_G : constant := 71; -- G
|
UC_F : constant Code := 70; -- F
|
||||||
UC_H : constant := 72; -- H
|
UC_G : constant Code := 71; -- G
|
||||||
UC_I : constant := 73; -- I
|
UC_H : constant Code := 72; -- H
|
||||||
UC_J : constant := 74; -- J
|
UC_I : constant Code := 73; -- I
|
||||||
UC_K : constant := 75; -- K
|
UC_J : constant Code := 74; -- J
|
||||||
UC_L : constant := 76; -- L
|
UC_K : constant Code := 75; -- K
|
||||||
UC_M : constant := 77; -- M
|
UC_L : constant Code := 76; -- L
|
||||||
UC_N : constant := 78; -- N
|
UC_M : constant Code := 77; -- M
|
||||||
UC_O : constant := 79; -- O
|
UC_N : constant Code := 78; -- N
|
||||||
UC_P : constant := 80; -- P
|
UC_O : constant Code := 79; -- O
|
||||||
UC_Q : constant := 81; -- Q
|
UC_P : constant Code := 80; -- P
|
||||||
UC_R : constant := 82; -- R
|
UC_Q : constant Code := 81; -- Q
|
||||||
UC_S : constant := 83; -- S
|
UC_R : constant Code := 82; -- R
|
||||||
UC_T : constant := 84; -- T
|
UC_S : constant Code := 83; -- S
|
||||||
UC_U : constant := 85; -- U
|
UC_T : constant Code := 84; -- T
|
||||||
UC_V : constant := 86; -- V
|
UC_U : constant Code := 85; -- U
|
||||||
UC_W : constant := 87; -- W
|
UC_V : constant Code := 86; -- V
|
||||||
UC_X : constant := 88; -- X
|
UC_W : constant Code := 87; -- W
|
||||||
UC_Y : constant := 89; -- Y
|
UC_X : constant Code := 88; -- X
|
||||||
UC_Z : constant := 90; -- Z
|
UC_Y : constant Code := 89; -- Y
|
||||||
Left_Square_Bracket : constant := 91; -- [
|
UC_Z : constant Code := 90; -- Z
|
||||||
Backslash : constant := 92; -- \
|
Left_Square_Bracket : constant Code := 91; -- [
|
||||||
Right_Square_Bracket: constant := 93; -- ]
|
Backslash : constant Code := 92; -- \
|
||||||
Circumflex : constant := 94; -- ^
|
Right_Square_Bracket: constant Code := 93; -- ]
|
||||||
Underline : constant := 95; -- _
|
Circumflex : constant Code := 94; -- ^
|
||||||
Grave : constant := 96; -- `
|
Underline : constant Code := 95; -- _
|
||||||
LC_A : constant := 97; -- a
|
Grave : constant Code := 96; -- `
|
||||||
LC_B : constant := 98; -- b
|
LC_A : constant Code := 97; -- a
|
||||||
LC_C : constant := 99; -- c
|
LC_B : constant Code := 98; -- b
|
||||||
LC_D : constant := 100; -- d
|
LC_C : constant Code := 99; -- c
|
||||||
LC_E : constant := 101; -- e
|
LC_D : constant Code := 100; -- d
|
||||||
LC_F : constant := 102; -- f
|
LC_E : constant Code := 101; -- e
|
||||||
LC_G : constant := 103; -- g
|
LC_F : constant Code := 102; -- f
|
||||||
LC_H : constant := 104; -- h
|
LC_G : constant Code := 103; -- g
|
||||||
LC_I : constant := 105; -- i
|
LC_H : constant Code := 104; -- h
|
||||||
LC_J : constant := 106; -- j
|
LC_I : constant Code := 105; -- i
|
||||||
LC_K : constant := 107; -- k
|
LC_J : constant Code := 106; -- j
|
||||||
LC_L : constant := 108; -- l
|
LC_K : constant Code := 107; -- k
|
||||||
LC_M : constant := 109; -- m
|
LC_L : constant Code := 108; -- l
|
||||||
LC_N : constant := 110; -- n
|
LC_M : constant Code := 109; -- m
|
||||||
LC_O : constant := 111; -- o
|
LC_N : constant Code := 110; -- n
|
||||||
LC_P : constant := 112; -- p
|
LC_O : constant Code := 111; -- o
|
||||||
LC_Q : constant := 113; -- q
|
LC_P : constant Code := 112; -- p
|
||||||
LC_R : constant := 114; -- r
|
LC_Q : constant Code := 113; -- q
|
||||||
LC_S : constant := 115; -- s
|
LC_R : constant Code := 114; -- r
|
||||||
LC_T : constant := 116; -- t
|
LC_S : constant Code := 115; -- s
|
||||||
LC_U : constant := 117; -- u
|
LC_T : constant Code := 116; -- t
|
||||||
LC_V : constant := 118; -- v
|
LC_U : constant Code := 117; -- u
|
||||||
LC_W : constant := 119; -- w
|
LC_V : constant Code := 118; -- v
|
||||||
LC_X : constant := 120; -- x
|
LC_W : constant Code := 119; -- w
|
||||||
LC_Y : constant := 121; -- y
|
LC_X : constant Code := 120; -- x
|
||||||
LC_Z : constant := 122; -- z
|
LC_Y : constant Code := 121; -- y
|
||||||
Left_Curly_Bracket : constant := 123; -- {
|
LC_Z : constant Code := 122; -- z
|
||||||
Vertical_Line : constant := 124; -- |
|
Left_Curly_Bracket : constant Code := 123; -- {
|
||||||
Right_Curly_Bracket : constant := 125; -- }
|
Vertical_Line : constant Code := 124; -- |
|
||||||
Tilde : constant := 126; -- ~
|
Right_Curly_Bracket : constant Code := 125; -- }
|
||||||
DEL : constant := 127;
|
Tilde : constant Code := 126; -- ~
|
||||||
|
DEL : constant Code := 127;
|
||||||
end P;
|
end P;
|
||||||
|
|
||||||
package V is
|
package V is
|
||||||
|
@ -3,6 +3,17 @@ package body H3.Strings is
|
|||||||
procedure Append (Obj: in out Elastic_String; V: in Rune_Array) is
|
procedure Append (Obj: in out Elastic_String; V: in Rune_Array) is
|
||||||
begin
|
begin
|
||||||
P.Append (P.Elastic_Array(Obj), V);
|
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;
|
end H3.Strings;
|
||||||
|
@ -18,6 +18,9 @@ package H3.Strings is
|
|||||||
null;
|
null;
|
||||||
end record;
|
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);
|
overriding procedure Append (Obj: in out Elastic_String; V: in Rune_Array);
|
||||||
|
|
||||||
end H3.Strings;
|
end H3.Strings;
|
||||||
|
@ -8,13 +8,14 @@ BEGIN {
|
|||||||
printf ("package H2.Runes is\n\n");
|
printf ("package H2.Runes is\n\n");
|
||||||
#printf ("\tpragma Preelaborate (Runes);\n\n");
|
#printf ("\tpragma Preelaborate (Runes);\n\n");
|
||||||
printf ("\tpackage P is\n");
|
printf ("\tpackage P is\n");
|
||||||
|
printf ("\t\t\%-20s: constant Code := %d; -- Code'First\n", "EOF", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
t = sprintf ("%c", NR - 1);
|
t = sprintf ("%c", NR - 1);
|
||||||
if (str::isprint(t)) t = " -- " t;
|
if (str::isprint(t)) t = " -- " t;
|
||||||
else 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;
|
X[NR - 1] = $1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,4 +32,19 @@ END {
|
|||||||
printf ("\n");
|
printf ("\n");
|
||||||
|
|
||||||
printf ("\nend H2.Runes;\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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user