Changeset 27


Ignore:
Timestamp:
Jun 3, 2014, 4:14:49 AM (7 years ago)
Author:
vadim.godunko
Message:

Add handling of lists.

Location:
trunk/forge/source/wiki
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/forge/source/wiki/forge-wiki-block_parsers-lists.adb

    r26 r27  
    5555       return List_Block_Parser is
    5656   begin
    57       return List_Block_Parser'(others => <>);
     57      return
     58        List_Block_Parser'
     59         (Offset      => Parameters.Markup_Offset,
     60          Text_Offset => Parameters.Text_Offset);
    5861   end Create;
    5962
     
    6669     Next : access Abstract_Block_Parser'Class) return End_Block_Action is
    6770   begin
     71      Put_Line (" </li>");
     72
     73      if Next /= null then
     74         if Next.Offset < Self.Offset then
     75            Put_Line ("</ul>");
     76
     77            return Unwind;
     78
     79         elsif Next.Offset = Self.Offset
     80           and Next.all in List_Block_Parser'Class
     81         then
     82            return Continue;
     83         end if;
     84
     85      else
     86         Put_Line ("</ul>");
     87
     88         return Unwind;
     89      end if;
     90
    6891      return Continue;
    6992   end End_Block;
     
    103126
    104127   overriding function Start_Block
    105     (Self    : not null access List_Block_Parser;
    106      Previos : access Abstract_Block_Parser'Class)
    107        return Block_Parser_Access is
     128    (Self     : not null access List_Block_Parser;
     129     Previous : access Abstract_Block_Parser'Class) return Block_Parser_Access
     130   is
     131      Parameters : aliased Constructor_Parameters
     132        := (Markup        => League.Strings.Empty_Universal_String,
     133            Markup_Offset => 0,
     134            Text_Offset   => Self.Text_Offset);
     135
    108136   begin
    109       Put_Line ("<ul>");
     137      if Previous /= null
     138        and then Previous.all not in List_Block_Parser'Class
     139      then
     140         Put_Line ("<ul>");
     141      end if;
     142
    110143      Put_Line ("  <li>");
    111144
    112       return new Forge.Wiki.Block_Parsers.Paragraphs.Paragraph_Block_Parser;
     145      return
     146        new Forge.Wiki.Block_Parsers.Paragraphs.Paragraph_Block_Parser'
     147             (Forge.Wiki.Block_Parsers.Paragraphs.Create (Parameters'Access));
    113148   end Start_Block;
    114149
  • trunk/forge/source/wiki/forge-wiki-block_parsers-lists.ads

    r26 r27  
    4646
    4747   type List_Block_Parser is
    48      new Forge.Wiki.Block_Parsers.Abstract_Block_Parser with null record;
     48     new Forge.Wiki.Block_Parsers.Abstract_Block_Parser with record
     49      Text_Offset : Positive;
     50   end record;
    4951
    5052   overriding function Start_Block
    51     (Self    : not null access List_Block_Parser;
    52      Previos : access Abstract_Block_Parser'Class) return Block_Parser_Access;
     53    (Self     : not null access List_Block_Parser;
     54     Previous : access Abstract_Block_Parser'Class) return Block_Parser_Access;
    5355
    5456   overriding function End_Block
  • trunk/forge/source/wiki/forge-wiki-block_parsers-paragraphs.adb

    r26 r27  
    5454       return Paragraph_Block_Parser is
    5555   begin
    56       return Paragraph_Block_Parser'(others => <>);
     56      return Paragraph_Block_Parser'(Offset => Parameters.Text_Offset);
    5757   end Create;
    5858
     
    6666   begin
    6767      Put_Line ("</p>");
     68
     69      if Next /= null then
     70         if Next.Offset < Self.Offset then
     71            return Unwind;
     72         end if;
     73
     74      else
     75         return Unwind;
     76      end if;
    6877
    6978      return Continue;
     
    100109
    101110   overriding function Start_Block
    102     (Self    : not null access Paragraph_Block_Parser;
    103      Previos : access Abstract_Block_Parser'Class)
     111    (Self     : not null access Paragraph_Block_Parser;
     112     Previous : access Abstract_Block_Parser'Class)
    104113       return Block_Parser_Access is
    105114   begin
  • trunk/forge/source/wiki/forge-wiki-block_parsers-paragraphs.ads

    r26 r27  
    4949
    5050   overriding function Start_Block
    51     (Self    : not null access Paragraph_Block_Parser;
    52      Previos : access Abstract_Block_Parser'Class) return Block_Parser_Access;
     51    (Self     : not null access Paragraph_Block_Parser;
     52     Previous : access Abstract_Block_Parser'Class) return Block_Parser_Access;
    5353
    5454   overriding function End_Block
  • trunk/forge/source/wiki/forge-wiki-block_parsers.ads

    r26 r27  
    5353
    5454   type End_Block_Action is
    55     (Continue); -- Replace current block parser by new one.
     55    (Continue, --  Replace current block parser by new one.
     56     Unwind);  --  Unwind block parsers stack and check with next block parser.
    5657
    57    type Abstract_Block_Parser is abstract tagged limited null record;
     58   type Abstract_Block_Parser is abstract tagged limited record
     59      Offset : Positive;
     60   end record;
    5861
    5962   type Block_Parser_Access is access all Abstract_Block_Parser'Class;
    6063
    6164   not overriding function Start_Block
    62     (Self    : not null access Abstract_Block_Parser;
    63      Previos : access Abstract_Block_Parser'Class)
     65    (Self     : not null access Abstract_Block_Parser;
     66     Previous : access Abstract_Block_Parser'Class)
    6467       return Block_Parser_Access is abstract;
    6568   --  Called when start of block element is detected.
  • trunk/forge/source/wiki/forge-wiki-parsers.adb

    r26 r27  
    146146            Markup_Group =>
    147147              (if Block.Markup_Group = 0 then 0
    148                  else Group + Block.Offset_Group),
     148                 else Group + Block.Markup_Group),
    149149            Offset_Group => Group + Block.Offset_Group,
    150150            Is_Start     => Is_Start,
     
    183183      Next_Block     : Forge.Wiki.Block_Parsers.Block_Parser_Access;
    184184      Nested_Block   : Forge.Wiki.Block_Parsers.Block_Parser_Access;
     185      Aux            : Forge.Wiki.Block_Parsers.Block_Parser_Access;
    185186
    186187   begin
     
    204205               then
    205206                  Self.Is_Separated := False;
    206                   Put_Line (Standard_Error, ">>> new block parser created <<<");
    207                   Put_Line (Standard_Error, Ada.Tags.External_Tag (Item.Parser_Tag));
    208 
    209                   Previous_Block := Self.Block_State;
     207
    210208                  Next_Block :=
    211209                    Create_Block_Parser
     
    217215                         then 0 else Match.First_Index (Item.Markup_Group)),
    218216                      Text_Offset);
     217
     218                  Previous_Block := Self.Block_State;
    219219                  Self.Block_State := null;
    220220
    221                   if Previous_Block /= null then
     221                  while Previous_Block /= null loop
    222222                     case Previous_Block.End_Block (Next_Block) is
    223223                        when Forge.Wiki.Block_Parsers.Continue =>
    224                            null;
     224                           exit;
     225
     226                        when Forge.Wiki.Block_Parsers.Unwind =>
     227                           Free (Previous_Block);
     228
     229                           if not Self.Block_Stack.Is_Empty then
     230                              Previous_Block := Self.Block_Stack.Last_Element;
     231                              Self.Block_Stack.Delete_Last;
     232
     233                           else
     234                              Previous_Block := null;
     235                           end if;
    225236                     end case;
    226                   end if;
     237                  end loop;
    227238
    228239                  Nested_Block := Next_Block.Start_Block (Previous_Block);
     
    231242                     Self.Block_Stack.Append (Next_Block);
    232243                     Self.Block_State := Nested_Block;
     244                     Aux := Nested_Block.Start_Block (null);
    233245
    234246                  else
     
    257269      end loop;
    258270
    259       if Self.Block_State /= null then
     271      while Self.Block_State /= null loop
    260272         case Self.Block_State.End_Block (null) is
    261273            when Forge.Wiki.Block_Parsers.Continue =>
    262                null;
     274               raise Program_Error;
     275
     276            when Forge.Wiki.Block_Parsers.Unwind =>
     277               if not Self.Block_Stack.Is_Empty then
     278                  Self.Block_State := Self.Block_Stack.Last_Element;
     279                  Self.Block_Stack.Delete_Last;
     280
     281               else
     282                  Self.Block_State := null;
     283               end if;
    263284         end case;
    264       end if;
     285      end loop;
    265286   end Parse;
    266287
Note: See TracChangeset for help on using the changeset viewer.