Guide · Getting started

Parse a document.

The first program uses strict JSON, strict decoded-name duplicate rejection, caller-selected capacities, and a caller event buffer.

Add the Flyology index and crate

Keep the community index for the compiler and third-party crates. Add the Flyology index ahead of it once, from any directory:

alr index --reset-community
alr index --add=git+https://github.com/flyology-ada/alire-index.git \
  --name=flyology --before=community
alr index --list

Add the reviewed 0.1.0-dev development release to your application:

cd /path/to/your/application
alr with flyology_json=0.1.0-dev
alr build

Alire resolves the indexed release and its compiler constraint. No Git or local path pin is needed.

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
      --  A parser profile is always complete and explicit. This one selects
      --  strict RFC JSON, Unicode scalar validation, and duplicate rejection.
      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);

      --  The input is the scalar `null`, so it opens no containers and has no
      --  member names. Zero is therefore sufficient for all three capacities
      --  in this example; these values are not library defaults.
      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
      --  Initialize validates and freezes the profile before byte zero. It
      --  reports configuration failure through Diagnostic rather than raising.
      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;

      --  Drain consumes the final input chunk and batches provisional events
      --  into caller storage. The result is separate from the event array.
      Parsing.Drain
        (Self         => Quick_Parser,
         Input        => Input,
         End_Of_Input => True,
         Events       => Quick_Events,
         Result       => Quick_Result);

      --  Only Drain_Document_Complete accepts the whole document. An
      --  application can commit its own candidate value after this outcome.
      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.