Parse one complete value
The example instantiates Flyology_JSON.Parsing with strict duplicate rejection. It constructs a complete Parser_Profile before byte zero. The zero capacities are explicit application choices for this scalar input, not library defaults.
declare
Quick_Profile : constant Profiles.Parser_Profile :=
(Syntax => (Family => Profiles.RFC_8259, Version => 1),
Unicode => (Family => Profiles.Unicode_Scalars, Version => 1),
Compatibility => (Family => Profiles.No_Extensions, Version => 1),
BOM => Profiles.Reject_BOM,
Duplicates => Profiles.Reject_Duplicates,
Top_Level => Profiles.Accept_Any_Value);
Quick_Parser : Parsing.Parser
(Maximum_Depth => 0,
Name_Octet_Capacity => 0,
Name_Capacity => 0);
Input : constant Ada.Streams.Stream_Element_Array :=
[Character'Pos ('n'), Character'Pos ('u'), Character'Pos ('l'), Character'Pos ('l')];
Quick_Events : Parsing.Event_Array (1 .. 4);
Quick_Result : Parsing.Drain_Result;
Quick_Diagnostic : Errors.Diagnostic;
begin
Parsing.Initialize (Quick_Parser, Quick_Profile, Quick_Diagnostic);
if Quick_Diagnostic.Code /= Errors.No_Error then
raise Program_Error with "parser initialization failed";
end if;
Parsing.Drain
(Self => Quick_Parser,
Input => Input,
End_Of_Input => True,
Events => Quick_Events,
Result => Quick_Result);
if Quick_Result.Stop /= Parsing.Drain_Document_Complete then
raise Program_Error with "JSON document was not accepted";
end if;
end;
Build and run the maintained example
Run ./scripts/test-examples.sh from the repository root. The script builds the example project through Alire and executes both parser and writer programs.
Continue with arbitrary chunks
The maintained streaming_parser.adb example advances only by returned consumed and produced counts. It accepts a deliberately awkward string boundary.
Continue with the parsing guide before retaining raw ranges or building an application candidate.
Check the current release
Version 0.1.0-dev is undergoing final publication. See Support for the current indexed-release status.