Changeset 26


Ignore:
Timestamp:
Jun 3, 2014, 3:29:44 AM (7 years ago)
Author:
vadim.godunko
Message:

Extend parser to be able to register nested block parsers.

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

Legend:

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

    r23 r26  
    4040--  $Revision$ $Date$
    4141------------------------------------------------------------------------------
     42with Ada.Text_IO; use Ada.Text_IO;
     43
     44with Forge.Wiki.Block_Parsers.Paragraphs;
    4245with Forge.Wiki.Parsers;
    4346
     
    5962   ---------------
    6063
    61    overriding procedure End_Block
    62     (Self : not null access List_Block_Parser) is
     64   overriding function End_Block
     65    (Self : not null access List_Block_Parser;
     66     Next : access Abstract_Block_Parser'Class) return End_Block_Action is
    6367   begin
    64       null;
     68      return Continue;
    6569   end End_Block;
    6670
     
    7377     Text : League.Strings.Universal_String) is
    7478   begin
    75       null;
     79      --  List block element parser never receives text information, it creates
     80      --  nested paragraph block element parser to handle text.
     81
     82      raise Program_Error;
    7683   end Line;
    7784
     
    95102   -----------------
    96103
    97    overriding procedure Start_Block
    98     (Self : not null access List_Block_Parser) is
     104   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
    99108   begin
    100       null;
     109      Put_Line ("<ul>");
     110      Put_Line ("  <li>");
     111
     112      return new Forge.Wiki.Block_Parsers.Paragraphs.Paragraph_Block_Parser;
    101113   end Start_Block;
    102114
  • trunk/forge/source/wiki/forge-wiki-block_parsers-lists.ads

    r20 r26  
    4848     new Forge.Wiki.Block_Parsers.Abstract_Block_Parser with null record;
    4949
    50    overriding procedure Start_Block
    51     (Self : not null access List_Block_Parser);
     50   overriding function Start_Block
     51    (Self    : not null access List_Block_Parser;
     52     Previos : access Abstract_Block_Parser'Class) return Block_Parser_Access;
    5253
    53    overriding procedure End_Block
    54     (Self : not null access List_Block_Parser);
     54   overriding function End_Block
     55    (Self : not null access List_Block_Parser;
     56     Next : access Abstract_Block_Parser'Class) return End_Block_Action;
    5557
    5658   overriding procedure Line
  • trunk/forge/source/wiki/forge-wiki-block_parsers-paragraphs.adb

    r20 r26  
    6161   ---------------
    6262
    63    overriding procedure End_Block
    64     (Self : not null access Paragraph_Block_Parser) is
     63   overriding function End_Block
     64    (Self : not null access Paragraph_Block_Parser;
     65     Next : access Abstract_Block_Parser'Class) return End_Block_Action is
    6566   begin
    6667      Put_Line ("</p>");
     68
     69      return Continue;
    6770   end End_Block;
    6871
     
    9699   -----------------
    97100
    98    overriding procedure Start_Block
    99     (Self : not null access Paragraph_Block_Parser) is
     101   overriding function Start_Block
     102    (Self    : not null access Paragraph_Block_Parser;
     103     Previos : access Abstract_Block_Parser'Class)
     104       return Block_Parser_Access is
    100105   begin
    101106      Put_Line ("<p>");
     107
     108      return null;
    102109   end Start_Block;
    103110
  • trunk/forge/source/wiki/forge-wiki-block_parsers-paragraphs.ads

    r20 r26  
    4848     new Forge.Wiki.Block_Parsers.Abstract_Block_Parser with null record;
    4949
    50    overriding procedure Start_Block
    51     (Self : not null access Paragraph_Block_Parser);
     50   overriding function Start_Block
     51    (Self    : not null access Paragraph_Block_Parser;
     52     Previos : access Abstract_Block_Parser'Class) return Block_Parser_Access;
    5253
    53    overriding procedure End_Block
    54     (Self : not null access Paragraph_Block_Parser);
     54   overriding function End_Block
     55    (Self : not null access Paragraph_Block_Parser;
     56     Next : access Abstract_Block_Parser'Class) return End_Block_Action;
    5557
    5658   overriding procedure Line
  • trunk/forge/source/wiki/forge-wiki-block_parsers.ads

    r24 r26  
    5252   end record;
    5353
     54   type End_Block_Action is
     55    (Continue); -- Replace current block parser by new one.
     56
    5457   type Abstract_Block_Parser is abstract tagged limited null record;
    5558
    56    not overriding procedure Start_Block
    57     (Self : not null access Abstract_Block_Parser) is abstract;
     59   type Block_Parser_Access is access all Abstract_Block_Parser'Class;
     60
     61   not overriding function Start_Block
     62    (Self    : not null access Abstract_Block_Parser;
     63     Previos : access Abstract_Block_Parser'Class)
     64       return Block_Parser_Access is abstract;
    5865   --  Called when start of block element is detected.
    5966
    60    not overriding procedure End_Block
    61     (Self : not null access Abstract_Block_Parser) is abstract;
     67   not overriding function End_Block
     68    (Self : not null access Abstract_Block_Parser;
     69     Next : access Abstract_Block_Parser'Class)
     70       return End_Block_Action is abstract;
    6271   --  Called when end of block element is detected.
    6372
  • trunk/forge/source/wiki/forge-wiki-parsers.adb

    r25 r26  
    5656     new Ada.Unchecked_Deallocation
    5757          (Forge.Wiki.Block_Parsers.Abstract_Block_Parser'Class,
    58            Block_Parser_Access);
     58           Forge.Wiki.Block_Parsers.Block_Parser_Access);
    5959
    6060   function Create_Block_Parser
     
    6262     Markup        : League.Strings.Universal_String;
    6363     Markup_Offset : Natural;
    64      Text_Offset   : Positive) return not null Block_Parser_Access;
     64     Text_Offset   : Positive)
     65       return not null Forge.Wiki.Block_Parsers.Block_Parser_Access;
    6566   --  Constructor to create block parser.
    6667
     
    9293     Markup        : League.Strings.Universal_String;
    9394     Markup_Offset : Natural;
    94      Text_Offset   : Positive) return not null Block_Parser_Access
     95     Text_Offset   : Positive)
     96       return not null Forge.Wiki.Block_Parsers.Block_Parser_Access
    9597   is
    9698      function Create is
     
    170172    (Self : in out Wiki_Parser'Class; Data : League.Strings.Universal_String)
    171173   is
    172       Lines       : constant League.String_Vectors.Universal_String_Vector
     174      use type Forge.Wiki.Block_Parsers.Block_Parser_Access;
     175
     176      Lines          : constant League.String_Vectors.Universal_String_Vector
    173177        := Data.Split (League.Characters.Latin.Line_Feed);
    174       Line        : Positive := 1;
    175       Match       : League.Regexps.Regexp_Match;
    176       Text_Offset : Natural;
    177       Found       : Boolean;
    178       Next_Block  : Block_Parser_Access;
     178      Line           : Positive := 1;
     179      Match          : League.Regexps.Regexp_Match;
     180      Text_Offset    : Natural;
     181      Found          : Boolean;
     182      Previous_Block : Forge.Wiki.Block_Parsers.Block_Parser_Access;
     183      Next_Block     : Forge.Wiki.Block_Parsers.Block_Parser_Access;
     184      Nested_Block   : Forge.Wiki.Block_Parsers.Block_Parser_Access;
    179185
    180186   begin
     
    200206                  Put_Line (Standard_Error, ">>> new block parser created <<<");
    201207                  Put_Line (Standard_Error, Ada.Tags.External_Tag (Item.Parser_Tag));
     208
     209                  Previous_Block := Self.Block_State;
    202210                  Next_Block :=
    203211                    Create_Block_Parser
     
    209217                         then 0 else Match.First_Index (Item.Markup_Group)),
    210218                      Text_Offset);
    211 
    212                   if Self.Block_State /= null then
    213                      Self.Block_State.End_Block (Next_Block);
     219                  Self.Block_State := null;
     220
     221                  if Previous_Block /= null then
     222                     case Previous_Block.End_Block (Next_Block) is
     223                        when Forge.Wiki.Block_Parsers.Continue =>
     224                           null;
     225                     end case;
    214226                  end if;
    215227
    216                   Free (Self.Block_State);
    217                   Self.Block_State := Next_Block;
    218                   Next_Block := null;
    219 
    220                   Self.Block_State.Start_Block;
     228                  Nested_Block := Next_Block.Start_Block (Previous_Block);
     229
     230                  if Nested_Block /= null then
     231                     Self.Block_Stack.Append (Next_Block);
     232                     Self.Block_State := Nested_Block;
     233
     234                  else
     235                     Self.Block_State := Next_Block;
     236                  end if;
     237
     238                  Free (Previous_Block);
    221239               end if;
    222240
     
    240258
    241259      if Self.Block_State /= null then
    242          Self.Block_State.End_Block (null);
     260         case Self.Block_State.End_Block (null) is
     261            when Forge.Wiki.Block_Parsers.Continue =>
     262               null;
     263         end case;
    243264      end if;
    244265   end Parse;
  • trunk/forge/source/wiki/forge-wiki-parsers.ads

    r25 r26  
    129129     new Ada.Containers.Vectors (Positive, Block_Expression_Item);
    130130
    131 --   type Initial_Block_Parser is new Abstract_Block_Parser with null record;
    132 
    133    type Block_Parser_Access is
    134      access all Forge.Wiki.Block_Parsers.Abstract_Block_Parser'Class;
    135 
    136131   package Block_Parser_Vectors is
    137      new Ada.Containers.Vectors (Positive, Block_Parser_Access);
     132     new Ada.Containers.Vectors
     133          (Positive,
     134           Forge.Wiki.Block_Parsers.Block_Parser_Access,
     135           Forge.Wiki.Block_Parsers."=");
    138136
    139137   type Wiki_Parser is tagged limited record
     
    141139      Block_Info      : Block_Expression_Vectors.Vector;
    142140      Separator_Group : Positive;
    143       Block_State     : Block_Parser_Access;
     141      Block_State     : Forge.Wiki.Block_Parsers.Block_Parser_Access;
    144142      Block_Stack     : Block_Parser_Vectors.Vector;
    145143      Is_Separated    : Boolean;
Note: See TracChangeset for help on using the changeset viewer.