Commits

Anonymous committed 9a3c042

Made progress with the grammar and everything - trunk is broken.

  • Participants
  • Parent commits b7718d2

Comments (0)

Files changed (4)

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

 use warnings;
 use strict;
 
+use Carp;
+
 use XML::Writer;
 use Text::Qantor::Parser;
 
         sub {
             return $self->_parser_error($args, [@_]);
         },
-        # yydebug => 0x1F,
+        yydebug => 0x1F,
     );
 
     foreach my $p (@{$doc_tree->_list()})
 {
     my $self = shift;
     my @ret = $self->_lexer2(@_);
+
+    use Data::Dumper;
+    print Dumper(\@ret);
     return @ret;
 }
 
 
         if ($state eq "text")
         {
-            if ($parser->YYData->{LINE} =~ m{\G\z}gmos)
+            if ($parser->YYData->{LINE} =~ m{\G\z}cgms)
             {
                 if (my $ret = $read_line->())
                 {
                     return @$ret;
                 }
             }
-            elsif ($parser->YYData->{LINE} =~ m{\G(\\)(?=\w)}gmos)
+            elsif ($parser->YYData->{LINE} =~ m{\G(\\)(?=\w)}cgms)
             {
                 $parser->YYData->{STATE} = "after_macro_start";
                 return ("MACRO_START", [$1, $parser->YYData->{LINE_COUNT}]);
             }
-            elsif ($parser->YYData->{LINE} =~ m{\G(\\\W)}gmos)
+            elsif ($parser->YYData->{LINE} =~ m{\G(\\\W)}cgms)
             {
                 return ("BS_ESCAPE_SEQ", [$1, $parser->YYData->{LINE_COUNT}]);
             }
-            elsif ($parser->YYData->{LINE} =~ m{\G(\})(?=\w)}gmos)
+            elsif ($parser->YYData->{LINE} =~ m{\G(\})}cgms)
             {
                 return ("MACRO_BODY_END", [$1, $parser->YYData->{LINE_COUNT}]);
             }
-            elsif ($parser->YYData->{LINE} =~ m{\G([^\\\}]+)}gmos)
+            elsif ($parser->YYData->{LINE} =~ m{\G([^\\\}]+)}cgms)
             {
                 return ("TEXT", [$1, $parser->YYData->{LINE_COUNT}]);
             }
         }
         elsif ($state eq "after_macro_start")
         {
-            $parser->YYData->{LINE} =~ m{\G(\w+)}gmos;
+            $parser->YYData->{LINE} =~ m{\G(\w+)}cgms;
 
             my $macro_name = $1;
 
         }
         elsif ($state eq "after_macro_name")
         {
-            if ($parser->YYData->{LINE} =~ m{\G(\{)}gmos)
+            if ($parser->YYData->{LINE} =~ m{\G(\{)}cgms)
             {
                 $parser->YYData->{STATE} = "text";
                 return ("MACRO_BODY_START", [$1, $parser->YYData->{LINE_COUNT}]);
         die $parser->YYData->{ERRMSG};
     }
 
-    die "Syntax error.";
+    Carp::confess("Syntax error.");
 
     return 1;
 }

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

 
 =cut
 
+sub _init
+{
+    my ($self, $args) = @_;
+
+    $self->name($args->{name});
+    $self->body($args->{body});
+
+    return;
+}
+
 use base 'Text::Qantor::Parser::Elem::Base';
 
 =head1 AUTHOR

File Text-Qantor/qantor_grammar.yp

 # 
 # Grammar for Qantor
 %left TEXT
+%left MACRO_START
 %%
 
-input: text { $_[1] }
+input: raw_para { $_[1] }
     ;
 
 text: raw_para
         }
         ;
 
-raw_para: para_text {
-        my $p = Text::Qantor::Parser::Elem::Para->new(
-                    { body => $_[1]->[0] },
-                    );
-                return Text::Qantor::Parser::Elem::ParaList->new(
-                { para => $p,},
-                )  } 
+raw_para: para_text_wrapper
+    | raw_para para_text_wrapper {
+        my ($self, $l, $other) = @_; $l->append($other); return $l;
+    }
     ;
 
 single_empty_line: EMPTY_LINE 
     | empty_line single_empty_line
     ;
 
-para_text: plain_para_text
-      #| macro_para_text
-    ;
+para_text_wrapper: para_text { 
+        my $p = Text::Qantor::Parser::Elem::Para->new(
+                    { body => $_[1] },
+                    );
+                return Text::Qantor::Parser::Elem::ParaList->new(
+                { para => $p,},
+                ) 
+                }
+         ;
 
-macro_start: MACRO_START 
-    ;
+para_text: macro_para_text 
+         | plain_para_text
+         ;
 
-macro_para_text : macro_start macro_ident MACRO_BODY_START para_text MACRO_BODY_END { Text::Qantor::Parser::Elem::MacroCall->new({ name => $_[2], body => $_[4] }) } 
+macro_para_text: MACRO_START MACRO_NAME MACRO_BODY_START para_text MACRO_BODY_END { Text::Qantor::Parser::Elem::MacroCall->new({ name => $_[2]->[0], body => $_[4]->[0] }) } 
     ;
     
 macro_ident: MACRO_NAME # TODO - create a better regex for it than just 

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(
     )
 );
 
-@files = (@files[0 .. 1]);
-
 sub read_file
 {
     my $path = shift;