27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
with Natools.S_Expressions.Atom_Buffers;
with Natools.S_Expressions.Lockable;
package Natools.S_Expressions.Parsers is
pragma Preelaborate (Natools.S_Expressions.Parsers);
type Parser is tagged private;
function Current_Event (P : in Parser) return Events.Event;
function Current_Atom (P : in Parser) return Atom;
function Current_Level (P : in Parser) return Natural;
procedure Query_Atom
(P : in Parser;
Process : not null access procedure (Data : in Atom));
procedure Read_Atom
(P : in Parser;
Data : out Atom;
Length : out Count);
procedure Next_Event
(P : in out Parser;
Input : not null access Ada.Streams.Root_Stream_Type'Class);
type Subparser
(Backend : access Parser;
Input : access Ada.Streams.Root_Stream_Type'Class)
is new Lockable.Descriptor with private;
overriding function Current_Event (P : in Subparser) return Events.Event;
overriding function Current_Atom (P : in Subparser) return Atom;
overriding function Current_Level (P : in Subparser) return Natural;
overriding procedure Query_Atom
(P : in Subparser;
Process : not null access procedure (Data : in Atom));
overriding procedure Read_Atom
(P : in Subparser;
Data : out Atom;
Length : out Count);
overriding procedure Next (P : in out Subparser; Event : out Events.Event);
overriding procedure Lock
(Object : in out Subparser;
State : out Lockable.Lock_State);
overriding procedure Unlock
(Object : in out Subparser;
State : in out Lockable.Lock_State;
Finish : in Boolean := True);
procedure Finish (P : in out Subparser);
-- Read enough data to exhaust intial nesting level
private
type Internal_State is
(Waiting, -- waiting for a marker
Base64_Atom, -- reading an atom encoded in base 64
Base64_Expr, -- reading an expression encoded in base 64
|
<
|
<
<
<
<
<
<
<
|
|
|
<
|
<
|
<
|
<
|
<
<
>
|
|
|
|
|
|
|
<
|
|
|
|
>
>
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
with Natools.S_Expressions.Atom_Buffers;
with Natools.S_Expressions.Lockable;
package Natools.S_Expressions.Parsers is
pragma Preelaborate (Natools.S_Expressions.Parsers);
type Parser is abstract limited new Lockable.Descriptor with private;
procedure Read_More
(Self : in out Parser;
Buffer : out Atom_Buffers.Atom_Buffer)
is abstract;
-- Read data to be parsed.
-- Leaving the buffer empty signals end of input stream.
procedure Reset (Self : in out Parser; Hard : in Boolean := False);
-- Reset internal state, and free internal memory if Hard
overriding function Current_Event (Self : Parser) return Events.Event;
overriding function Current_Atom (Self : Parser) return Atom;
overriding function Current_Level (Self : Parser) return Natural;
overriding procedure Query_Atom
(Self : in Parser;
Process : not null access procedure (Data : in Atom));
overriding procedure Read_Atom
(Self : in Parser;
Data : out Atom;
Length : out Count);
overriding procedure Next (Self : in out Parser; Event : out Events.Event);
overriding procedure Lock
(Self : in out Parser;
State : out Lockable.Lock_State);
overriding procedure Unlock
(Self : in out Parser;
State : in out Lockable.Lock_State;
Finish : in Boolean := True);
type Stream_Parser (Input : access Ada.Streams.Root_Stream_Type'Class) is
limited new Lockable.Descriptor with private;
private
type Internal_State is
(Waiting, -- waiting for a marker
Base64_Atom, -- reading an atom encoded in base 64
Base64_Expr, -- reading an expression encoded in base 64
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
when Quoted_Atom =>
Escape : Read_Buffer;
when Verbatim_Atom =>
Size : Count;
end case;
end record;
type Parser is tagged record
Internal : State_Data;
Pending : Events.Event := Events.End_Of_Input;
Override : Atom_Buffers.Atom_Buffer;
Latest : Events.Event := Events.Error;
Buffer : Atom_Buffers.Atom_Buffer;
Level : Natural := 0;
end record;
type Subparser
(Backend : access Parser;
Input : access Ada.Streams.Root_Stream_Type'Class)
is new Lockable.Descriptor with record
Levels : Lockable.Lock_Stack;
Initialized : Boolean := False;
Terminated : Boolean := False;
end record;
end Natools.S_Expressions.Parsers;
|
|
|
<
>
>
>
<
<
|
|
|
|
|
|
|
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
when Quoted_Atom =>
Escape : Read_Buffer;
when Verbatim_Atom =>
Size : Count;
end case;
end record;
type Parser is abstract limited new Lockable.Descriptor with record
Internal : State_Data;
Next_Event : Events.Event := Events.End_Of_Input;
Latest : Events.Event := Events.Error;
Pending : Atom_Buffers.Atom_Buffer;
Buffer : Atom_Buffers.Atom_Buffer;
Level : Natural := 0;
Lock_Stack : Lockable.Lock_Stack;
Locked : Boolean := False;
end record;
type Stream_Parser (Input : access Ada.Streams.Root_Stream_Type'Class) is
new Parser with null record;
overriding procedure Read_More
(Self : in out Stream_Parser;
Buffer : out Atom_Buffers.Atom_Buffer);
end Natools.S_Expressions.Parsers;
|