Changeset 20


Ignore:
Timestamp:
May 31, 2014, 2:21:55 PM (7 years ago)
Author:
vadim.godunko
Message:

Add stub for list block parser.

Use dispatching constructor to create block parsers.

Add registry for block parsers.

Remove direct dependency of base parser from paragraph block parser.

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

Legend:

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

    r19 r20  
    4343package Forge.Wiki.Block_Parsers.Lists is
    4444
     45--   pragma Preelaborate;
     46
     47   type List_Block_Parser is
     48     new Forge.Wiki.Block_Parsers.Abstract_Block_Parser with null record;
     49
     50   overriding procedure Start_Block
     51    (Self : not null access List_Block_Parser);
     52
     53   overriding procedure End_Block
     54    (Self : not null access List_Block_Parser);
     55
     56   overriding procedure Line
     57    (Self : not null access List_Block_Parser;
     58     Text : League.Strings.Universal_String);
     59
     60   overriding function Create
     61    (Parameters : not null access Constructor_Parameters)
     62       return List_Block_Parser;
     63
     64   procedure Register;
     65   --  Registers block parser to handle lists.
     66
    4567end Forge.Wiki.Block_Parsers.Lists;
  • trunk/forge/source/wiki/forge-wiki-block_parsers-paragraphs.adb

    r19 r20  
    4242with Ada.Text_IO; use Ada.Text_IO;
    4343
     44with Forge.Wiki.Parsers;
     45
    4446package body Forge.Wiki.Block_Parsers.Paragraphs is
     47
     48   ------------
     49   -- Create --
     50   ------------
     51
     52   overriding function Create
     53    (Parameters : not null access Constructor_Parameters)
     54       return Paragraph_Block_Parser is
     55   begin
     56      return Paragraph_Block_Parser'(others => <>);
     57   end Create;
    4558
    4659   ---------------
     
    6578   end Line;
    6679
     80   --------------
     81   -- Register --
     82   --------------
     83
     84   procedure Register is
     85   begin
     86      Forge.Wiki.Parsers.Register_Paragraph_Block_Parser
     87       (League.Strings.To_Universal_String
     88         ("^\p{White_Space}*(\P{White_Space})"),
     89        1,
     90        1,
     91        Paragraph_Block_Parser'Tag);
     92   end Register;
     93
    6794   -----------------
    6895   -- Start_Block --
  • trunk/forge/source/wiki/forge-wiki-block_parsers-paragraphs.ads

    r19 r20  
    5858     Text : League.Strings.Universal_String);
    5959
     60   overriding function Create
     61    (Parameters : not null access Constructor_Parameters)
     62       return Paragraph_Block_Parser;
     63
     64   procedure Register;
     65   --  Registers block parser to handle paragraphs.
     66
    6067end Forge.Wiki.Block_Parsers.Paragraphs;
  • trunk/forge/source/wiki/forge-wiki-block_parsers.ads

    r19 r20  
    4646   pragma Preelaborate;
    4747
     48   type Constructor_Parameters is null record;
     49
    4850   type Abstract_Block_Parser is abstract tagged limited null record;
    4951
    5052   not overriding procedure Start_Block
    5153    (Self : not null access Abstract_Block_Parser) is abstract;
     54   --  Called when start of block element is detected.
    5255
    5356   not overriding procedure End_Block
    5457    (Self : not null access Abstract_Block_Parser) is abstract;
     58   --  Called when end of block element is detected.
    5559
    5660   not overriding procedure Line
    5761    (Self : not null access Abstract_Block_Parser;
    5862     Text : League.Strings.Universal_String) is abstract;
     63   --  Called to process single line of text in processed block element.
    5964
     65   not overriding function Create
     66    (Parameters : not null access Constructor_Parameters)
     67       return Abstract_Block_Parser is abstract;
     68   --  Dispatching constructor to create instance of block element parser.
    6069
    6170end Forge.Wiki.Block_Parsers;
  • trunk/forge/source/wiki/forge-wiki-parsers.adb

    r19 r20  
    4242with Ada.Text_IO; use Ada.Text_IO;
    4343
     44with Ada.Tags.Generic_Dispatching_Constructor;
    4445with Ada.Unchecked_Deallocation;
    4546
    4647with League.Characters.Latin;
    4748with League.String_Vectors;
    48 
    49 with Forge.Wiki.Block_Parsers.Paragraphs;
    5049
    5150package body Forge.Wiki.Parsers is
     
    5857          (Forge.Wiki.Block_Parsers.Abstract_Block_Parser'Class,
    5958           Block_Parser_Access);
     59
     60   function Create_Block_Parser
     61    (Tag : Ada.Tags.Tag) return not null Block_Parser_Access;
     62   --  Constructor to create block parser.
     63
     64   type Block_Parser_Information is record
     65      Regexp_String : League.Strings.Universal_String;
     66      Total_Groups  : Positive;
     67      Offset_Group  : Positive;
     68--      Match_Index   : Positive;
     69      Parser_Tag    : Ada.Tags.Tag;
     70   end record;
     71
     72   package Block_Parser_Information_Vectors is
     73     new Ada.Containers.Vectors (Positive, Block_Parser_Information);
     74
     75   Block_Registry     : Block_Parser_Information_Vectors.Vector;
     76   Paragraph_Registry : Block_Parser_Information;
    6077
    6178   Base_Expression       : constant League.Strings.Universal_String
     
    6986   --  continuation line and block separator line.
    7087
     88   -------------------------
     89   -- Create_Block_Parser --
     90   -------------------------
     91
     92   function Create_Block_Parser
     93    (Tag : Ada.Tags.Tag) return not null Block_Parser_Access
     94   is
     95      function Create is
     96        new Ada.Tags.Generic_Dispatching_Constructor
     97             (Forge.Wiki.Block_Parsers.Abstract_Block_Parser,
     98              Forge.Wiki.Block_Parsers.Constructor_Parameters,
     99              Forge.Wiki.Block_Parsers.Create);
     100
     101      Parameters : aliased Forge.Wiki.Block_Parsers.Constructor_Parameters;
     102
     103   begin
     104      return
     105        new Forge.Wiki.Block_Parsers.Abstract_Block_Parser'Class'
     106             (Create (Tag, Parameters'Access));
     107   end Create_Block_Parser;
     108
    71109   -----------------------------
    72110   -- Initialize_Block_Regexp --
     
    98136         Match := Self.Block_Regexp.Find_Match (Lines (Line));
    99137
    100          Put_Line (Integer'Image (Match.Capture_Count) & ' ' & Boolean'Image (Match.Is_Matched));
    101 
    102          for C in 1 .. Match.Capture_Count loop
    103             Put_Line (Integer'Image (Match.First_Index (C)) & " .." & Integer'Image (Match.Last_Index (C)));
    104          end loop;
     138--         Put_Line (Integer'Image (Match.Capture_Count) & ' ' & Boolean'Image (Match.Is_Matched));
     139--
     140--         for C in 1 .. Match.Capture_Count loop
     141--            Put_Line (Integer'Image (Match.First_Index (C)) & " .." & Integer'Image (Match.Last_Index (C)));
     142--         end loop;
    105143
    106144         if Match.First_Index (Para_Block_Match)
     
    110148
    111149            if Self.Block_State = null then
    112                Put_Line ("  paragraph started");
     150--               Put_Line ("  paragraph started");
    113151
    114152               Self.Block_State :=
    115                  new Forge.Wiki.Block_Parsers.Paragraphs.Paragraph_Block_Parser;
     153                 Create_Block_Parser (Paragraph_Registry.Parser_Tag);
    116154               Self.Block_State.Start_Block;
    117155               Self.Block_State.Line (Lines (Line).Tail_From (Offset));
    118156
    119157            else
    120                Put_Line ("  paragraph matched");
     158--               Put_Line ("  paragraph matched");
    121159               Self.Block_State.Line (Lines (Line).Tail_From (Offset));
    122160            end if;
    123161
    124162         else
    125             Put_Line ("  block separator matched");
     163--            Put_Line ("  block separator matched");
    126164            Self.Block_State.End_Block;
    127165            Free (Self.Block_State);
     
    137175   end Parse;
    138176
     177   -------------------------------------
     178   -- Register_Paragraph_Block_Parser --
     179   -------------------------------------
     180
     181   procedure Register_Paragraph_Block_Parser
     182    (Regexp_String : League.Strings.Universal_String;
     183     Total_Groups  : Positive;
     184     Offset_Group  : Positive;
     185     Tag           : Ada.Tags.Tag) is
     186   begin
     187      Paragraph_Registry := (Regexp_String, Total_Groups, Offset_Group, Tag);
     188   end Register_Paragraph_Block_Parser;
     189
     190   ---------------------------
     191   -- Register_Block_Parser --
     192   ---------------------------
     193
     194   procedure Register_Block_Parser
     195    (Regexp_String : League.Strings.Universal_String;
     196     Total_Groups  : Positive;
     197     Offset_Group  : Positive;
     198     Tag           : Ada.Tags.Tag) is
     199   begin
     200      Block_Registry.Append ((Regexp_String, Total_Groups, Offset_Group, Tag));
     201      Put_Line ("Register: " & Ada.Tags.External_Tag (Tag));
     202   end Register_Block_Parser;
     203
    139204end Forge.Wiki.Parsers;
  • trunk/forge/source/wiki/forge-wiki-parsers.ads

    r19 r20  
    4141------------------------------------------------------------------------------
    4242private with Ada.Containers.Vectors;
     43with Ada.Tags;
    4344
    4445private with League.Regexps;
     
    8687   --  Parses given string.
    8788
     89   procedure Register_Block_Parser
     90    (Regexp_String : League.Strings.Universal_String;
     91     Total_Groups  : Positive;
     92     Offset_Group  : Positive;
     93     Tag           : Ada.Tags.Tag);
     94   --  Registers custom block parser. Regexp_String is regular expression to
     95   --  detect start of custom block. Offset_Group is number of group in regular
     96   --  expression which is used to detect position of first significant
     97   --  character of text on block's start line. Total_Groups is total number of
     98   --  groups used in regular expression. Tag is tag of the custom block parser
     99   --  to create its instance.
     100
     101   procedure Register_Paragraph_Block_Parser
     102    (Regexp_String : League.Strings.Universal_String;
     103     Total_Groups  : Positive;
     104     Offset_Group  : Positive;
     105     Tag           : Ada.Tags.Tag);
     106   --  Register custom block parser for base paragraph block. Only one parser
     107   --  can be registered in this way.
     108
    88109private
    89110
  • trunk/forge/source/wiki/forge-wiki-setup.adb

    r19 r20  
    4545package body Forge.Wiki.Setup is
    4646
     47begin
     48   Forge.Wiki.Block_Parsers.Lists.Register;
     49   Forge.Wiki.Block_Parsers.Paragraphs.Register;
    4750end Forge.Wiki.Setup;
Note: See TracChangeset for help on using the changeset viewer.