markdown_24.0.0_70ffe37b/source/parser/markdown-blocks-lists.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
--
--  Copyright (C) 2021-2023, AdaCore
--
--  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--

--  Markdown list of items

with Ada.Iterator_Interfaces;

with Markdown.List_Items;
private with Markdown.Implementation.Lists;

package Markdown.Blocks.Lists is
   pragma Preelaborate;

   type List is tagged private
     with
       Constant_Indexing => Element,
       Default_Iterator  => Iterate,
       Iterator_Element  => Markdown.List_Items.List_Item;
   --  List contains list items

   function Is_Ordered (Self : List'Class) return Boolean;
   --  Return True if list has an ordered list markers.

   function Start (Self : List'Class) return Natural
     with Pre => Self.Is_Ordered;
   --  An integer to start counting from for the list items.

   function Length (Self : List) return Natural;
   --  Return number of list items in the list

   function Element
     (Self  : List;
      Index : Positive) return Markdown.List_Items.List_Item;
   --  Return a list item with given index

   function To_Block (Self : List) return Markdown.Blocks.Block;
   --  Convert to Block type

   function From_Block (Self : Markdown.Blocks.Block) return List;
   --  Convert the Block to List

   --  Syntax sugar for Ada 2012 user-defined iterator.
   --  This allows iteration in form of
   --
   --     for Item of The_List loop
   --        ...
   --     end loop;

   type Cursor is private;

   function Element
     (Self     : List;
      Position : Cursor) return Markdown.List_Items.List_Item;

   function Has_Element (Self : Cursor) return Boolean
     with Inline;

   package Iterator_Interfaces is new Ada.Iterator_Interfaces
     (Cursor, Has_Element);

   type Reversible_Iterator is
     limited new Iterator_Interfaces.Reversible_Iterator with private;

   overriding function First (Self : Reversible_Iterator) return Cursor;

   overriding function Next
     (Self     : Reversible_Iterator;
      Position : Cursor) return Cursor
        with Inline;

   overriding function Last (Self : Reversible_Iterator) return Cursor;

   overriding function Previous
     (Self     : Reversible_Iterator;
      Position : Cursor) return Cursor
        with Inline;

   function Iterate (Self : List'Class) return Reversible_Iterator;
   --  Return an iterator over each element in the vector

private

   type List_Access is access all
     Markdown.Implementation.Lists.List;

   type List is new Ada.Finalization.Controlled with record
      Data : List_Access;
   end record;

   overriding procedure Adjust (Self : in out List);
   overriding procedure Finalize (Self : in out List);

   type Cursor is record
      Index : Natural;
   end record;

   function Has_Element (Self : Cursor) return Boolean is (Self.Index > 0);

   function To_Index (Self : Cursor) return Natural is (Self.Index);

   type Reversible_Iterator is
     limited new Iterator_Interfaces.Reversible_Iterator with
   record
      Last : Natural;
   end record;

end Markdown.Blocks.Lists;