File Coverage

blib/lib/Parse/Lex.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 20 21 95.2


line stmt bran cond sub pod time code
1             require 5.004;
2 2     2   42090 use strict qw(vars);
  2         4  
  2         70  
3 2     2   11 use strict qw(refs);
  2         2  
  2         51  
4 2     2   8 use strict qw(subs);
  2         3  
  2         68  
5            
6             package Parse::Lex;
7 2     2   1758 use Parse::ALex;
  2         6  
  2         377  
8             $Parse::Lex::VERSION = '2.21';
9             @Parse::Lex::ISA = qw(Parse::Tokenizer);
10            
11             my $lexer = __PACKAGE__->clone;
12 5 100   5 0 43 sub prototype { $lexer or __PACKAGE__->SUPER::prototype }
13            
14             ####################################################################
15             #Structure of the next routine:
16             # HEADER_STRING | HEADER_STREAM
17             # TOKEN+
18             # FOOTER
19            
20             # %%...%% are processed by the Parse::Template class
21             # In %%%% $template and $self are the same Parse::Template instance
22             # RegExp must be delimited by // or m!!
23            
24             my %TEMPLATE = ();
25            
26             $TEMPLATE{'WITH_SKIP_PART'} = q@
27             if ($LEX_POS < $LEX_LENGTH and $LEX_BUFFER =~ /\G(?:%%$SKIP%%)/cg) {
28             $textLength = pos($LEX_BUFFER) - $LEX_POS; # length $&
29             $LEX_OFFSET += $textLength;
30             $LEX_POS += $textLength;
31             %% $IS_HOLD ? HOLD_SKIP_PART(): ''%%
32             }
33             @;
34             $TEMPLATE{'WITH_SKIP_LAST_READ_PART'} = q@
35             if ($LEX_BUFFER =~ /\G(?:%%$SKIP%%)/cg) { # skip this pattern
36             $textLength = pos($LEX_BUFFER) - $LEX_POS; # length $&
37             $LEX_OFFSET += $textLength;
38             $LEX_POS += $textLength;
39             %% $IS_HOLD ? HOLD_SKIP_PART(): ''%%
40             } else {
41             last READ;
42             }
43             @;
44             $TEMPLATE{'HOLD_SKIP_PART'} = q@$self->[%%$HOLD_TEXT%%] .= $1;@;
45             $TEMPLATE{'HEADER_STRING_PART'} = q@
46             {
47             pos($LEX_BUFFER) = $LEX_POS;
48             my $textLength = 0;
49             #
50             %% $SKIP ne '' ? WITH_SKIP_PART() : '' %%
51             if ($LEX_POS == $LEX_LENGTH) {
52             $self->[%%$EOI%%] = 1;
53             $LEX_TOKEN = $Parse::Token::EOI;
54             return $Parse::Token::EOI;
55             }
56             $LEX_TOKEN = undef;
57             my $content = '';
58             #
59             CASE:{
60             @;
61             $TEMPLATE{'HEADER_STREAM_PART'} = q@
62             {
63             pos($LEX_BUFFER) = $LEX_POS;
64             my $textLength = 0;
65             my $LEX_FH = $$LEX_FHR;
66             #
67             %% $SKIP ne '' ? WITH_SKIP_PART() : '' %%
68             if ($LEX_POS == $LEX_LENGTH) {
69             if ($self->[%%$EOI%%]) # if EOI
70             {
71             $LEX_TOKEN = $Parse::Token::EOI;
72             return $Parse::Token::EOI;
73             }
74             else
75             {
76             READ:{
77             do {
78             $LEX_BUFFER = <$LEX_FH>;
79             if (defined($LEX_BUFFER)) {
80             pos($LEX_BUFFER) = $LEX_POS = 0;
81             $LEX_LENGTH = CORE::length($LEX_BUFFER);
82             $LEX_RECORD++;
83             %%$SKIP ne '' ? WITH_SKIP_LAST_READ_PART() : '' %%
84             } else {
85             $self->[%%$EOI%%] = 1;
86             $LEX_TOKEN = $Parse::Token::EOI;
87             return $Parse::Token::EOI;
88             }
89             } while ($LEX_POS == $LEX_LENGTH);
90             }# READ
91             }
92             }
93             my $content = '';
94             $LEX_TOKEN = undef;
95             #
96             CASE:{
97             @;
98             $TEMPLATE{'HOLD_TOKEN_PART'} = q@$self->[%%$HOLD_TEXT%%] .= $content;@;
99             $TEMPLATE{'FOOTER_PART'} = q!
100             }#CASE
101             %%$IS_HOLD ? HOLD_TOKEN_PART() : ''%%
102             $self->[%%$PENDING_TOKEN%%] = $LEX_TOKEN;
103             $LEX_TOKEN;
104             }
105             !;
106             $lexer->template(Parse::Template->new(%TEMPLATE)); # code template
107            
108             1;
109             __END__