Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed c9dae40

Got all test files to pass. Also with the macro calls.

Regexp::Grammars++ - great stuff it seems so far.

  • Participants
  • Parent commits caf6461

Comments (0)

Files changed (3)

File Text-Qantor/lib/Text/Qantor.pm

 use warnings;
 use strict;
 
+use Moose;
+
 use Carp;
 
 use XML::Writer;
 use Text::Qantor::Parser;
 
+has '_xml_out' => (is => "rw", isa => "XML::Writer");
+
+my $fo_ns = "http://www.w3.org/1999/XSL/Format";
+
 =head1 NAME
 
 Text::Qantor - a post-modern Typesetting System.
     return;
 }
 
+sub _write_para
+{
+    my $self = shift;
+    my $p = shift;
+
+    my $writer = $self->_xml_out();
+
+    my $text_nodes = $p->{'Para_Text_Wrapper'};
+
+    foreach my $t_n (@$text_nodes)
+    {
+        if (exists($t_n->{'Plain_Para_Text'}))
+        {
+            $writer->characters($t_n->{'Plain_Para_Text'});
+        }
+        elsif (exists($t_n->{'Macro_Para_Text'}))
+        {
+            my $macro_call = $t_n->{'Macro_Para_Text'};
+            $writer->startTag([$fo_ns, "inline"], "font-weight" => "bold");
+            $self->_write_para(
+                $macro_call->{'Raw_Para'}
+            );
+            $writer->endTag(); # inline font-weight=bold
+        }
+    }
+
+    return;
+}
+
 =head2 $qantor->convert_input_to_xsl_fo({in_fh => \*STDIN, out_fh => \*STDOUT})
 
 Converts the input from the C<in_fh> filehandle to XSL-FO and outputs it to
     my $in_fh = $args->{in_fh};
     my $out_fh = $args->{out_fh};
 
-    my $fo_ns = "http://www.w3.org/1999/XSL/Format";
 
     my $writer = XML::Writer->new(
         NAMESPACES => 1,
         ENCODING => "utf-8",
     );
 
+    $self->_xml_out($writer);
+
     $writer->xmlDecl("utf-8");
     $writer->startTag([$fo_ns, "root"]);
    
     foreach my $p (@{$doc_tree->{Text}->{Raw_Para}})
     {
         $writer->startTag([$fo_ns, "block"]);
-
-        $writer->characters($p->{q//});
-
-        $writer->endTag();
+        $self->_write_para($p);
+        $writer->endTag(); # block
     }
 
     $writer->endTag(); # flow

File Text-Qantor/lib/Text/Qantor/Parser.pm

         # <logfile: - > 
         # <debug: on>
 
-        \A <Input>
+        \A <Input> \z
 
         <token: Input>
             <Text> (?:<.Empty_Line>)?
         <token: Empty_Line>
             <.Single_Empty_Line>+
         <token: Para_Text_Wrapper>
-            <Plain_Para_Text>
+            <Plain_Para_Text> 
+                |
+            <Macro_Para_Text>
         <token: Macro_Para_Text>
-            <MACRO_START> <MACRO_NAME> <MACRO_BODY_START> <Para_Text> <MACRO_BODY_END>
+            <MACRO_START> <MACRO_NAME> <MACRO_BODY_START> <Raw_Para> <MACRO_BODY_END>
         <token: MACRO_START> <.MATCH= (\\(?=\w)) >
         <token: MACRO_NAME> <MATCH= (\w+) >
-        <token: MACRO_BODY_START> <.MATCH= (?:\\\{) >
+        <token: MACRO_BODY_START> <.MATCH= (?:\{) >
         <token: MACRO_BODY_END> <.MATCH= (?:\}) >
         
         <token: Para_Text>
                 |
             <Plain_Para_Text>
 
-        <token: Plain_Para_Text> <MATCH= ([^\n]+\n?) > 
+        <token: Plain_Para_Text> <MATCH= ([^\\\n\{\}]+\n?) > 
         /msx;
 
     };

File Text-Qantor/t/01-convert-to-xsl-fo.t

 use strict;
 use warnings;
 
-use Test::More tests => 2;
+use Test::More tests => 3;
 
 use lib "./t/lib";
 
 
 use Text::Qantor;
 
-# TEST:$num_files=2
+# TEST:$num_files=3
 my @files =
 (
     qw(
         t/data/to-xsl-fo/input/three-paras.qant
         t/data/to-xsl-fo/input/several-paras.qant
+        t/data/to-xsl-fo/input/with-bold.qant
     )
 );
 
-#       t/data/to-xsl-fo/input/with-bold.qant
 
 sub read_file
 {