| 1 | package Text::CaffeinatedMarkup::PullParser; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | our $VERSION = 0.01; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Log::Log4perl qw(:easy); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | Log::Log4perl->easy_init($OFF); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | has 'pml' => (is=>'rw'); | |||||||||||||||||||||||||||
| 14 | 5 | has 'pml_chars' => (is=>'rw'); | |||||||||||||||||||||||||||
| 15 | 5 | has 'num_pml_chars' => (is=>'rw'); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 5 | has 'temporary_token' => (is=>'rw'); | |||||||||||||||||||||||||||
| 18 | 5 | has 'temporary_token_context' => (is=>'rw'); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 5 | has 'tokens' => (is=>'rw'); | |||||||||||||||||||||||||||
| 21 | 5 | has 'has_finished_parsing' => (is=>'rw'); | |||||||||||||||||||||||||||
| 22 | 5 | has 'pointer' => (is=>'rw'); | |||||||||||||||||||||||||||
| 23 | 5 | has 'state' => (is=>'rw'); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 5 | has 'token' => (is=>'rw'); # Output token | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 5 | has 'data_context' => (is=>'rw'); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 5 | my $SYM_STRONG = '*'; | |||||||||||||||||||||||||||
| 31 | 5 | my $SYM_EMPHASIS = '/'; | |||||||||||||||||||||||||||
| 32 | 5 | my $SYM_UNDERLINE = '_'; | |||||||||||||||||||||||||||
| 33 | 5 | my $SYM_DELETE = '-'; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | my $SYM_LINK_START = '['; | |||||||||||||||||||||||||||
| 36 | 5 | my $SYM_LINK_END = ']'; | |||||||||||||||||||||||||||
| 37 | 5 | my $SYM_LINK_CONTEXT_SWITCH = '|'; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | my $SYM_IMAGE_START = '{'; | |||||||||||||||||||||||||||
| 40 | 5 | my $SYM_IMAGE_END = '}'; | |||||||||||||||||||||||||||
| 41 | 5 | my $SYM_IMAGE_CONTEXT_SWITCH = '|'; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 5 | my $SYM_NEWLINE = "\n"; | |||||||||||||||||||||||||||
| 44 | 5 | my $SYM_SECTION_BREAK = '~'; | |||||||||||||||||||||||||||
| 45 | 5 | my $SYM_HEADER = '#'; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 5 | my $SYM_ROW = '='; | |||||||||||||||||||||||||||
| 48 | 5 | my $SYM_COLUMN = '|'; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 5 | my $SYM_QUOTE = '"'; | |||||||||||||||||||||||||||
| 51 | 5 | my $SYM_QUOTE_CONTEXT_SWITCH = '|'; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 5 | my $SYM_ESCAPE = "\\"; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 77 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 77 | my ($self) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 77 | ▶ | die "Must supply 'pml' to ".__PACKAGE__."::new()\n\n" unless $self->pml; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Presplit the input before parsing | ||||||||||||||||||||||||||||
| 64 | 76 | $self->pml_chars([split //,$self->pml]); | |||||||||||||||||||||||||||
| 65 | 76 | $self->num_pml_chars( scalar @{$self->pml_chars} ); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Initialise | ||||||||||||||||||||||||||||
| 68 | 76 | $self->tokens([]); | |||||||||||||||||||||||||||
| 69 | 76 | $self->has_finished_parsing(0); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 76 | $self->pointer(0); | |||||||||||||||||||||||||||
| 72 | 76 | $self->state('newline'); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 76 | $self->data_context([]); | |||||||||||||||||||||||||||
| 75 | #$self->data_context('data'); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 76 | return; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # ============================================================== PUBLIC API ==== | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 415 | ▶ | sub get_next_token { | ||||||||||||||||||||||||||
|
Subroutine
get_next_token: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 415 | my ($self) = @_; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 415 | ▶ | return 0 if $self->has_finished_parsing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 348 | return $self->_get_next_token; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 75 | ▶ | sub get_all_tokens { | ||||||||||||||||||||||||||
|
Subroutine
get_all_tokens: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 75 | my ($self) = @_; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # Not finished parsing yet (or started at all) so get_next_token until | ||||||||||||||||||||||||||||
| 95 | # we run out of document! Otherwise we just return what we have. | ||||||||||||||||||||||||||||
| 96 | 75 | ▶ | unless ($self->has_finished_parsing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 75 | ▶ | while ($self->get_next_token) {} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 71 | ▶ | return wantarray ? @{$self->tokens} : $self->tokens; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # ================================================================ INTERNAL ==== | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 348 | ▶ | sub _get_next_token { | ||||||||||||||||||||||||||
|
Subroutine
_get_next_token: called CC=118 SCAR=58.6
| |||||||||||||||||||||||||||||
| 105 | 348 | my ($self) = @_; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 348 | ▶ | while(!$self->token) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 6098 | my $state = $self->state; | |||||||||||||||||||||||||||
| 109 | 6098 | my $char = $self->pml_chars->[$self->pointer]; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 6098 | $self->_increment_pointer; | |||||||||||||||||||||||||||
| 112 | 6098 | TRACE "State is '$state'"; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 6098 | ▶ | $char = 'EOF' unless defined $char; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 6098 | TRACE " Read char [$char]"; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 6098 | ▶ | if ($state eq 'data') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | #$self->data_context('data'); # REMOVE | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 3092 | ▶ | if ($char eq $SYM_STRONG) { $self->_switch_state('strong'); next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 3078 | ▶ | if ($char eq $SYM_EMPHASIS) { $self->_switch_state('emphasis'); next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 3069 | ▶ | if ($char eq $SYM_UNDERLINE){ $self->_switch_state('underline'); next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 3061 | ▶ | if ($char eq $SYM_DELETE) { $self->_switch_state('delete'); next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 3051 | ▶ | if ($char eq $SYM_QUOTE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 5 | $self->_switch_state('quote-start'); | |||||||||||||||||||||||||||
| 129 | 5 | next; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 3046 | ▶ | if ($char eq $SYM_LINK_START) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 10 | $self->_switch_state('link-start'); | |||||||||||||||||||||||||||
| 134 | 10 | next; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 3036 | ▶ | if ($char eq $SYM_IMAGE_START) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 17 | $self->_switch_state('image-start'); | |||||||||||||||||||||||||||
| 139 | 17 | next; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 3019 | ▶ | if ($char eq $SYM_NEWLINE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 16 | $self->_create_token({type=>'NEWLINE'}); | |||||||||||||||||||||||||||
| 144 | 16 | $self->_switch_state('newline'); | |||||||||||||||||||||||||||
| 145 | 16 | next; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 3003 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 53 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 150 | 53 | next; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # "Anything else" | ||||||||||||||||||||||||||||
| 154 | # Append to string char, emitting if there was a | ||||||||||||||||||||||||||||
| 155 | # previous token that wasn't a string. | ||||||||||||||||||||||||||||
| 156 | 2950 | my $previous_token = $self->_append_to_string_token( $char ); | |||||||||||||||||||||||||||
| 157 | 2950 | next; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 3006 | ▶ | if ($state eq 'strong') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 16 | ▶ | if ($char eq $SYM_STRONG) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 16 | $self->_create_token({type=>'STRONG'}); | |||||||||||||||||||||||||||
| 166 | 16 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 167 | 16 | next; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | $self->_append_to_string_token( $SYM_STRONG ); | |||||||||||||||||||||||||||
| 172 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 173 | 0 | next; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # "Anything else" | ||||||||||||||||||||||||||||
| 177 | # Append a star (*) to the current string token, reconsume char | ||||||||||||||||||||||||||||
| 178 | # and switch to data state. | ||||||||||||||||||||||||||||
| 179 | 0 | $self->_append_to_string_token( $SYM_STRONG ); | |||||||||||||||||||||||||||
| 180 | 0 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 181 | 0 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 182 | 0 | next; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 2990 | ▶ | if ($state eq 'emphasis') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 11 | ▶ | if ($char eq $SYM_EMPHASIS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 10 | $self->_create_token({type=>'EMPHASIS'}); | |||||||||||||||||||||||||||
| 191 | 10 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 192 | 10 | next; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 1 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | $self->_append_to_string_token( $SYM_EMPHASIS ); | |||||||||||||||||||||||||||
| 197 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 198 | 0 | next; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # "Anything else" | ||||||||||||||||||||||||||||
| 202 | # Append a foreslash (/) to the current string token, reconsume char | ||||||||||||||||||||||||||||
| 203 | # and switch to data state. | ||||||||||||||||||||||||||||
| 204 | 1 | $self->_append_to_string_token( $SYM_EMPHASIS ); | |||||||||||||||||||||||||||
| 205 | 1 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 206 | 1 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 207 | 1 | next; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 2979 | ▶ | if ($state eq 'underline') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 10 | ▶ | if ($char eq $SYM_UNDERLINE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 10 | $self->_create_token({type=>'UNDERLINE'}); | |||||||||||||||||||||||||||
| 216 | 10 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 217 | 10 | next; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | $self->_append_to_string_token( $SYM_UNDERLINE ); | |||||||||||||||||||||||||||
| 222 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 223 | 0 | next; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | # "Anything else" | ||||||||||||||||||||||||||||
| 227 | # Append an underscore (_) to the current string token, reconsume char | ||||||||||||||||||||||||||||
| 228 | # and switch to data state. | ||||||||||||||||||||||||||||
| 229 | 0 | $self->_append_to_string_token( $SYM_UNDERLINE ); | |||||||||||||||||||||||||||
| 230 | 0 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 231 | 0 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 232 | 0 | next; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 2969 | ▶ | if ($state eq 'delete') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 14 | ▶ | if ($char eq $SYM_DELETE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 10 | $self->_create_token({type=>'DEL'}); | |||||||||||||||||||||||||||
| 241 | 10 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 242 | 10 | next; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 4 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 0 | $self->_append_to_string_token( $SYM_DELETE ); | |||||||||||||||||||||||||||
| 247 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 248 | 0 | next; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | # "Anything else" | ||||||||||||||||||||||||||||
| 252 | # Append a dash (-) to the current string token, reconsume char | ||||||||||||||||||||||||||||
| 253 | # and switch to data state. | ||||||||||||||||||||||||||||
| 254 | 4 | $self->_append_to_string_token( $SYM_DELETE ); | |||||||||||||||||||||||||||
| 255 | 4 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 256 | 4 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 257 | 4 | next; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 2955 | ▶ | if ($state eq 'link-start') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 13 | ▶ | if ($char eq $SYM_LINK_START) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 13 | $self->_create_token({type=>'LINK',href=>'',text=>''}); | |||||||||||||||||||||||||||
| 266 | 13 | $self->temporary_token_context('href'); | |||||||||||||||||||||||||||
| 267 | 13 | $self->_switch_state('link-href'); | |||||||||||||||||||||||||||
| 268 | 13 | next; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | $self->_append_to_string_token( $SYM_LINK_START ); | |||||||||||||||||||||||||||
| 273 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 274 | 0 | next; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | # "Anything else" | ||||||||||||||||||||||||||||
| 278 | # Append an open square bracket ([) to the current string token, | ||||||||||||||||||||||||||||
| 279 | # reconsume char and switch to data state. | ||||||||||||||||||||||||||||
| 280 | 0 | $self->_append_to_string_token( $SYM_LINK_START ); | |||||||||||||||||||||||||||
| 281 | 0 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 282 | 0 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 283 | 0 | next; | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 2942 | ▶ | if ($state eq 'link-href') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 450 | ▶ | if ($char eq $SYM_LINK_CONTEXT_SWITCH) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 10 | $self->temporary_token_context('text'); | |||||||||||||||||||||||||||
| 292 | 10 | $self->_switch_state('link-text'); | |||||||||||||||||||||||||||
| 293 | 10 | next; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | 440 | ▶ | if ($char eq $SYM_LINK_END) { $self->_switch_state('link-end'); next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 437 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | 0 | $self->_raise_parse_error("Unexpected 'EOF' while parsing link href"); | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | # "Anything else" | ||||||||||||||||||||||||||||
| 302 | # Append to open link token href | ||||||||||||||||||||||||||||
| 303 | 437 | ▶ | if ($self->temporary_token->{type} eq 'LINK') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 437 | $self->temporary_token->{href} .= $char; | |||||||||||||||||||||||||||
| 305 | 437 | next; | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | # Oops | ||||||||||||||||||||||||||||
| 309 | 0 | $self->_raise_parse_error("Attempt to append link href data to non-link token"); | |||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 2492 | ▶ | if ($state eq 'link-text') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 106 | ▶ | if ($char eq $SYM_LINK_END) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 10 | $self->_switch_state('link-end'); | |||||||||||||||||||||||||||
| 318 | 10 | next; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 96 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 0 | $self->_raise_parse_error("Unexpected 'EOF' while parsing link text"); | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | # "Anything else" | ||||||||||||||||||||||||||||
| 326 | # Append to open link token href | ||||||||||||||||||||||||||||
| 327 | 96 | ▶ | if ($self->temporary_token->{type} eq 'LINK') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 96 | $self->temporary_token->{text} .= $char; | |||||||||||||||||||||||||||
| 329 | 96 | next; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | # Oops | ||||||||||||||||||||||||||||
| 333 | 0 | $self->_raise_parse_error("Attempt to append link text data to non-link token"); | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 2386 | ▶ | if ($state eq 'link-end') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 13 | ▶ | if ($char eq $SYM_LINK_END) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | 13 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 342 | 13 | next; | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | 0 | $self->_raise_parse_error("Unexpected 'EOF' while parsing link end"); | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | # "Anything else" | ||||||||||||||||||||||||||||
| 350 | # Append to href or text depending on context | ||||||||||||||||||||||||||||
| 351 | 0 | my $context = $self->temporary_token_context; | |||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ($context =~ /^(?:href|text)$/o) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | 0 | $self->temporary_token->{$context} .= $char; | |||||||||||||||||||||||||||
| 355 | 0 | next; | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 0 | $self->_raise_parse_error("Missing or bad link token context"); | |||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 2373 | ▶ | if ($state eq 'image-start') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 22 | ▶ | if ($char eq $SYM_IMAGE_START) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 22 | $self->_create_token({type=>'IMAGE',src=>'',options=>''}); | |||||||||||||||||||||||||||
| 367 | 22 | $self->temporary_token_context('src'); | |||||||||||||||||||||||||||
| 368 | 22 | $self->_switch_state('image-src'); | |||||||||||||||||||||||||||
| 369 | 22 | next; | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | 0 | $self->_append_to_string_token( $SYM_IMAGE_START ); | |||||||||||||||||||||||||||
| 374 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 375 | 0 | next; | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | # "Anything else" | ||||||||||||||||||||||||||||
| 379 | # Append an open curly bracket ({}) to the current string token, | ||||||||||||||||||||||||||||
| 380 | # reconsume char and switch to data state. | ||||||||||||||||||||||||||||
| 381 | 0 | $self->_append_to_string_token( $SYM_IMAGE_START ); | |||||||||||||||||||||||||||
| 382 | 0 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 383 | 0 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 384 | 0 | next; | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 2351 | ▶ | if ($state eq 'image-src') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 205 | ▶ | if ($char eq $SYM_IMAGE_CONTEXT_SWITCH) { $self->_switch_state('image-options'); next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 187 | ▶ | if ($char eq $SYM_IMAGE_END) { $self->_switch_state('image-end'); next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 183 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 395 | 0 | $self->_raise_parse_error("Unexpected 'EOF' while parsing image src"); | |||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | # "Anything else" | ||||||||||||||||||||||||||||
| 399 | # Append to open link token href | ||||||||||||||||||||||||||||
| 400 | 183 | ▶ | if ($self->temporary_token->{type} eq 'IMAGE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | 183 | $self->temporary_token->{src} .= $char; | |||||||||||||||||||||||||||
| 402 | 183 | next; | |||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | # Oops | ||||||||||||||||||||||||||||
| 406 | 0 | $self->_raise_parse_error("Attempt to append image src data to non-image token"); | |||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 2146 | ▶ | if ($state eq 'image-options') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 148 | ▶ | if ($char eq $SYM_IMAGE_END) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 18 | $self->_switch_state('image-end'); | |||||||||||||||||||||||||||
| 415 | 18 | next; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 130 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | 0 | $self->_raise_parse_error("Unexpected 'EOF' while parsing image options"); | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | # "Anything else" | ||||||||||||||||||||||||||||
| 423 | # Append to open link token href | ||||||||||||||||||||||||||||
| 424 | 130 | ▶ | if ($self->temporary_token->{type} eq 'IMAGE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | 130 | $self->temporary_token->{options} .= $char; | |||||||||||||||||||||||||||
| 426 | 130 | next; | |||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | # Oops | ||||||||||||||||||||||||||||
| 430 | 0 | $self->_raise_parse_error("Attempt to append image options data to non-image token"); | |||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 1998 | ▶ | if ($state eq 'image-end') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 22 | ▶ | if ($char eq $SYM_IMAGE_END) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | 22 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 439 | 22 | next; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 443 | 0 | $self->_raise_parse_error("Unexpected 'EOF' while parsing image end"); | |||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | # "Anything else" | ||||||||||||||||||||||||||||
| 447 | # Append to src or options depending on context | ||||||||||||||||||||||||||||
| 448 | 0 | my $context = $self->temporary_token_context; | |||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 0 | ▶ | if ($context =~ /^(?:src|options)$/o) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 0 | $self->temporary_token->{$context} .= $char; | |||||||||||||||||||||||||||
| 452 | 0 | next; | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | 0 | $self->_raise_parse_error("Missing or bad image token context"); | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 1976 | ▶ | if ($state eq 'newline') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 154 | ▶ | if ($char eq 'EOF') { $self->_switch_state('end_of_data'); next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 463 | 150 | ▶ | if ($char eq $SYM_NEWLINE) { $self->_create_token({type=>'NEWLINE'}); next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 464 | 0 | ▶ | if ($char eq ' ') { next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 131 | ▶ | if ($char eq $SYM_HEADER) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | 8 | $self->_create_token({type=>'HEADER',level=>1}); | |||||||||||||||||||||||||||
| 468 | 8 | $self->_switch_state('header'); | |||||||||||||||||||||||||||
| 469 | 8 | next; | |||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 123 | ▶ | if ($char eq $SYM_SECTION_BREAK) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 473 | 1 | $self->_switch_state('section-break'); | |||||||||||||||||||||||||||
| 474 | 1 | next; | |||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | 122 | ▶ | if ($char eq $SYM_ROW) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 478 | 41 | $self->_switch_state('row'); | |||||||||||||||||||||||||||
| 479 | 41 | next; | |||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | # Anything else | ||||||||||||||||||||||||||||
| 483 | 81 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 484 | 81 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 485 | 81 | next; | |||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 1822 | ▶ | if ($state eq 'section-break') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | 1 | ▶ | if ($char eq $SYM_SECTION_BREAK) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 493 | 1 | $self->_create_token({type=>'SECTIONBREAK'}); | |||||||||||||||||||||||||||
| 494 | 1 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 495 | 1 | next; | |||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 499 | 0 | $self->_append_to_string_token( $SYM_SECTION_BREAK ); | |||||||||||||||||||||||||||
| 500 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 501 | 0 | next; | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | # Anything else | ||||||||||||||||||||||||||||
| 505 | 0 | $self->_append_to_string_token( $SYM_SECTION_BREAK ); | |||||||||||||||||||||||||||
| 506 | 0 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 507 | 0 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 508 | 0 | next; | |||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 1821 | ▶ | if ($state eq 'header') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 23 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 516 | 0 | my $cur_level = $self->temporary_token->{level}; | |||||||||||||||||||||||||||
| 517 | 0 | $self->_discard_token; | |||||||||||||||||||||||||||
| 518 | 0 | my $new_string = $SYM_HEADER x $cur_level; | |||||||||||||||||||||||||||
| 519 | 0 | $self->_create_token({type=>'STRING',content=>$new_string}); | |||||||||||||||||||||||||||
| 520 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 521 | 0 | next; | |||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | 23 | ▶ | if ($char eq ' ') { next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 15 | ▶ | if ($char eq $SYM_HEADER) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 527 | 7 | $self->temporary_token->{level}++; | |||||||||||||||||||||||||||
| 528 | 7 | next; | |||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | # Anything else | ||||||||||||||||||||||||||||
| 532 | 8 | $self->_switch_state('header-text'); | |||||||||||||||||||||||||||
| 533 | 8 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 534 | 8 | next; | |||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | 1798 | ▶ | if ($state eq 'header-text') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | 93 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 542 | 4 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 543 | 4 | next; | |||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 89 | ▶ | if ($char eq $SYM_NEWLINE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 547 | 4 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 548 | 4 | next; | |||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | # Anything else | ||||||||||||||||||||||||||||
| 552 | 85 | $self->temporary_token->{text} .= $char; | |||||||||||||||||||||||||||
| 553 | 85 | next; | |||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | 1705 | ▶ | if ($state eq 'row') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | 41 | ▶ | if ($char eq $SYM_ROW) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 561 | 41 | $self->_discard_token; # Discard previous newline | |||||||||||||||||||||||||||
| 562 | 41 | $self->_create_token({type=>'ROW'}); | |||||||||||||||||||||||||||
| 563 | 41 | $self->_switch_state('row-end-state'); | |||||||||||||||||||||||||||
| 564 | 41 | next; | |||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 568 | 0 | $self->_append_to_string_token( $SYM_ROW ); | |||||||||||||||||||||||||||
| 569 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 570 | 0 | next; | |||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | # Anything else | ||||||||||||||||||||||||||||
| 574 | 0 | $self->_append_to_string_token( $SYM_ROW ); | |||||||||||||||||||||||||||
| 575 | 0 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 576 | 0 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 577 | 0 | next; | |||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | 1664 | ▶ | if ($state eq 'row-end-state') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | 41 | ▶ | if ($char eq $SYM_NEWLINE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 585 | 30 | ▶ | if ($self->_get_data_context eq 'column-data') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 586 | 8 | TRACE " -> Data context is 'column-data'"; | |||||||||||||||||||||||||||
| 587 | 8 | $self->_emit_token; | |||||||||||||||||||||||||||
| 588 | 8 | $self->_pop_data_context; | |||||||||||||||||||||||||||
| 589 | 8 | $self->_pop_data_context; # Pop two levels (column then row) | |||||||||||||||||||||||||||
| 590 | 8 | $self->_switch_state('newline'); | |||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||
| 592 | else { | ||||||||||||||||||||||||||||
| 593 | 22 | TRACE " -> Data context other than 'column-data'"; | |||||||||||||||||||||||||||
| 594 | 22 | $self->_push_data_context('row-data'); | |||||||||||||||||||||||||||
| 595 | 22 | $self->_switch_state('row-data-state'); | |||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||
| 597 | 30 | next; | |||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | 11 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 601 | 10 | ▶ | if ($self->_get_data_context eq 'column-data') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 602 | # Oops expecting a newline. We'll be nice though and | ||||||||||||||||||||||||||||
| 603 | # close the sequence as if it were there. | ||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||
| 605 | else { | ||||||||||||||||||||||||||||
| 606 | 0 | $self->_discard_token; | |||||||||||||||||||||||||||
| 607 | 0 | $self->_create_token({type=>'STRING',content=>"$SYM_ROW$SYM_ROW"}); | |||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||
| 609 | 10 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 610 | 10 | next; | |||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | # Anything else | ||||||||||||||||||||||||||||
| 614 | 1 | $self->_discard_token; | |||||||||||||||||||||||||||
| 615 | 1 | $self->_create_token({type=>'STRING',content=>"$SYM_ROW$SYM_ROW"}); | |||||||||||||||||||||||||||
| 616 | 1 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 617 | 1 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 618 | 1 | next; | |||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | 1623 | ▶ | if ($state eq 'row-data-state') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | 22 | ▶ | if ($char eq $SYM_COLUMN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 626 | 21 | $self->_switch_state('first-column'); | |||||||||||||||||||||||||||
| 627 | 21 | next; | |||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | # Anything else | ||||||||||||||||||||||||||||
| 631 | 1 | $self->_raise_parse_error('Unexpected char at start of row data'); | |||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | 1601 | ▶ | if ($state eq 'first-column') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | 21 | ▶ | if ($char eq $SYM_COLUMN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 639 | 20 | $self->_push_data_context('column-data'); | |||||||||||||||||||||||||||
| 640 | 20 | $self->_create_token({type=>'COLUMN'}); | |||||||||||||||||||||||||||
| 641 | 20 | $self->_switch_state('column-data'); | |||||||||||||||||||||||||||
| 642 | 20 | next; | |||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | # Anything else | ||||||||||||||||||||||||||||
| 646 | 1 | $self->_raise_parse_error('Unexpected char in first column tag'); | |||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||
| 651 | 1580 | ▶ | if ($state eq 'column') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | 16 | ▶ | if ($char eq $SYM_COLUMN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 654 | 15 | ▶ | $self->_discard_token if $self->temporary_token->{type} eq 'NEWLINE'; # Discard previous newline | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 655 | 15 | $self->_push_data_context('column-data'); | |||||||||||||||||||||||||||
| 656 | 15 | $self->_create_token({type=>'COLUMN'}); | |||||||||||||||||||||||||||
| 657 | 15 | $self->_switch_state('column-data'); | |||||||||||||||||||||||||||
| 658 | 15 | next; | |||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | 1 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 662 | 1 | $self->_raise_parse_error('Unexpected end of data in column tag'); | |||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | # Anything else | ||||||||||||||||||||||||||||
| 666 | 0 | $self->_append_to_string_token($SYM_COLUMN); | |||||||||||||||||||||||||||
| 667 | 0 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 668 | 0 | $self->_switch_state('column-data'); | |||||||||||||||||||||||||||
| 669 | 0 | next; | |||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | 1564 | ▶ | if ($state eq 'column-data') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||
| 676 | 1346 | ▶ | if ($char eq $SYM_COLUMN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 677 | 16 | $self->_switch_state('column'); | |||||||||||||||||||||||||||
| 678 | 16 | next; | |||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | 1330 | ▶ | if ($char eq $SYM_STRONG) { $self->_switch_state('strong'); next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 682 | 1328 | ▶ | if ($char eq $SYM_EMPHASIS) { $self->_switch_state('emphasis'); next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 683 | 1326 | ▶ | if ($char eq $SYM_UNDERLINE){ $self->_switch_state('underline'); next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 684 | 1324 | ▶ | if ($char eq $SYM_DELETE) { $self->_switch_state('delete'); next; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||
| 686 | 1320 | ▶ | if ($char eq $SYM_QUOTE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 687 | 1 | $self->_switch_state('quote-start'); | |||||||||||||||||||||||||||
| 688 | 1 | next; | |||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | 1319 | ▶ | if ($char eq $SYM_LINK_START) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 692 | 3 | $self->_switch_state('link-start'); | |||||||||||||||||||||||||||
| 693 | 3 | next; | |||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | 1316 | ▶ | if ($char eq $SYM_IMAGE_START) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 697 | 5 | $self->_switch_state('image-start'); | |||||||||||||||||||||||||||
| 698 | 5 | next; | |||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||
| 701 | 1311 | ▶ | if ($char eq $SYM_NEWLINE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 702 | 36 | $self->_create_token({type=>'NEWLINE'}); | |||||||||||||||||||||||||||
| 703 | 36 | $self->_switch_state('newline'); | |||||||||||||||||||||||||||
| 704 | 36 | next; | |||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||
| 707 | 1275 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 708 | 1 | $self->_raise_parse_error('Unexpected end of data in column data'); | |||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||
| 711 | # Anything else | ||||||||||||||||||||||||||||
| 712 | 1274 | $self->_append_to_string_token($char); | |||||||||||||||||||||||||||
| 713 | 1274 | next; | |||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||
| 716 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||
| 718 | 218 | ▶ | if ($state eq 'end_of_data') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 719 | 71 | DEBUG "End of data reached - finish parse"; | |||||||||||||||||||||||||||
| 720 | 71 | $self->has_finished_parsing(1); | |||||||||||||||||||||||||||
| 721 | 71 | $self->_emit_token; | |||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||
| 723 | 71 | ▶ | if ($self->temporary_token) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 724 | 0 | TRACE "Still got temp token!"; | |||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | 71 | last; | |||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||
| 730 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||
| 732 | 147 | ▶ | if ($state eq 'quote-start') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 733 | 6 | ▶ | if ($char eq $SYM_QUOTE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 734 | 6 | $self->_create_token({type=>'QUOTE',body=>'',cite=>''}); | |||||||||||||||||||||||||||
| 735 | 6 | $self->temporary_token_context('body'); | |||||||||||||||||||||||||||
| 736 | 6 | $self->_switch_state('quote-body'); | |||||||||||||||||||||||||||
| 737 | 6 | $self->_push_data_context('quote-body'); | |||||||||||||||||||||||||||
| 738 | 6 | next; | |||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||
| 741 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 742 | 0 | $self->_append_to_string_token('"'); | |||||||||||||||||||||||||||
| 743 | 0 | $self->_switch_state('end_of_data'); | |||||||||||||||||||||||||||
| 744 | 0 | next; | |||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||
| 747 | # Anything else | ||||||||||||||||||||||||||||
| 748 | 0 | $self->_append_to_string_token('"'); | |||||||||||||||||||||||||||
| 749 | 0 | $self->_decrement_pointer; | |||||||||||||||||||||||||||
| 750 | 0 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 751 | 0 | next; | |||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||
| 754 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||
| 756 | 141 | ▶ | if ($state eq 'quote-end') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 757 | 6 | ▶ | if ($char eq $SYM_QUOTE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 758 | 6 | $self->_pop_data_context; | |||||||||||||||||||||||||||
| 759 | 6 | $self->_switch_to_data_state; | |||||||||||||||||||||||||||
| 760 | 6 | next; | |||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | 0 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 764 | 0 | $self->_raise_parse_error("unexpected end of file in quote end sequence"); | |||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||
| 767 | # Anything else | ||||||||||||||||||||||||||||
| 768 | 0 | my $context = $self->temporary_token_context; | |||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||
| 770 | 0 | ▶ | if ($context =~ /^(?:body|cite)$/o) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 771 | 0 | $self->temporary_token->{$context} .= $char; | |||||||||||||||||||||||||||
| 772 | 0 | next; | |||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||
| 775 | 0 | $self->_raise_parse_error("Missing or bad quote token context"); | |||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||
| 778 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||
| 780 | 135 | ▶ | if ($state eq 'quote-body') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 781 | 116 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 782 | 0 | $self->_raise_parse_error('unexpected end of file in quote'); | |||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | 116 | ▶ | if ($char eq $SYM_QUOTE_CONTEXT_SWITCH) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 786 | 2 | $self->temporary_token_context('cite'); | |||||||||||||||||||||||||||
| 787 | 2 | $self->_switch_state('quote-cite'); | |||||||||||||||||||||||||||
| 788 | 2 | next; | |||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||
| 791 | 114 | ▶ | if ($char eq $SYM_QUOTE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 792 | 4 | $self->_switch_state('quote-end'); | |||||||||||||||||||||||||||
| 793 | 4 | next; | |||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||
| 796 | # Anything else | ||||||||||||||||||||||||||||
| 797 | 110 | $self->temporary_token->{body} .= $char; | |||||||||||||||||||||||||||
| 798 | 110 | next; | |||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||
| 801 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||
| 803 | 19 | ▶ | if ($state eq 'quote-cite') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 804 | 19 | ▶ | if ($char eq 'EOF') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 805 | 0 | $self->_raise_parse_error('unexpected end of file in quote'); | |||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||
| 808 | 19 | ▶ | if ($char eq $SYM_QUOTE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 809 | 2 | $self->_switch_state('quote-end'); | |||||||||||||||||||||||||||
| 810 | 2 | next; | |||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||
| 813 | # Anything else | ||||||||||||||||||||||||||||
| 814 | 17 | $self->temporary_token->{cite} .= $char; | |||||||||||||||||||||||||||
| 815 | 17 | next; | |||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||
| 818 | # --------------------------------------- | ||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||
| 820 | # Shouldn't ever get here! | ||||||||||||||||||||||||||||
| 821 | 0 | $self->_raise_parse_error("Invalid state! '$state'"); | |||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||
| 825 | 344 | ▶ | my $token = $self->token || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->token || 0
MC/DC100%1/1
$self->token || 0
$self->token
Truth table100%2/2
A
A= $self->token
| |||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||
| 827 | 344 | $self->token(undef); | |||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||
| 829 | 344 | return $token; | |||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||
| 832 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||
| 834 | 6098 | ▶ | sub _increment_pointer { $_[0]->pointer( $_[0]->pointer + 1) } | ||||||||||||||||||||||||||
|
Subroutine
_increment_pointer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 835 | 95 | ▶ | sub _decrement_pointer { $_[0]->pointer( $_[0]->pointer - 1); TRACE " -> Requeue char" } | ||||||||||||||||||||||||||
|
Subroutine
_decrement_pointer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||
| 837 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||
| 839 | # Emit the current "temporary token" if there is one. | ||||||||||||||||||||||||||||
| 840 | # Doing this returns to the client as well as adding to the token bucket. | ||||||||||||||||||||||||||||
| 841 | 347 | ▶ | sub _emit_token { | ||||||||||||||||||||||||||
|
Subroutine
_emit_token: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 842 | 347 | my ($self) = @_; | |||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||
| 844 | 347 | ▶ | return unless my $token = $self->temporary_token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 845 | 343 | push @{$self->tokens}, $token; | |||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||
| 847 | # Reset the temporary token | ||||||||||||||||||||||||||||
| 848 | 343 | $self->temporary_token(undef); | |||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||
| 850 | 343 | DEBUG " >> Emit token [ ".$token->{type}.' ]'; | |||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||
| 852 | 343 | $self->token($token); # Mark the token for output; | |||||||||||||||||||||||||||
| 853 | 343 | return; | |||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||
| 856 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||
| 858 | 6 | ▶ | sub _raise_parse_error { | ||||||||||||||||||||||||||
|
Subroutine
_raise_parse_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 859 | 6 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||
| 860 | 6 | ERROR "!!Parse error [$msg]"; | |||||||||||||||||||||||||||
| 861 | 6 | die "Encountered parse error [$msg]\n\n"; | |||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||
| 864 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||
| 866 | 179 | ▶ | sub _switch_to_data_state { | ||||||||||||||||||||||||||
|
Subroutine
_switch_to_data_state: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 867 | 179 | my ($self) = @_; | |||||||||||||||||||||||||||
| 868 | 179 | $self->_switch_state( $self->_get_data_context ); | |||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||
| 871 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||
| 873 | 709 | ▶ | sub _switch_state { | ||||||||||||||||||||||||||
|
Subroutine
_switch_state: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 874 | 709 | my ($self, $switch_to) = @_; | |||||||||||||||||||||||||||
| 875 | 709 | TRACE " Switching to state [ $switch_to ]"; | |||||||||||||||||||||||||||
| 876 | 709 | $self->state($switch_to); | |||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||
| 879 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||
| 881 | # If there's a temporary token, get rid of it | ||||||||||||||||||||||||||||
| 882 | 54 | ▶ | sub _discard_token { | ||||||||||||||||||||||||||
|
Subroutine
_discard_token: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 883 | 54 | my ($self) = @_; | |||||||||||||||||||||||||||
| 884 | 54 | $self->temporary_token(undef); | |||||||||||||||||||||||||||
| 885 | 54 | $self->temporary_token_context(undef); | |||||||||||||||||||||||||||
| 886 | 54 | return; | |||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||
| 889 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||
| 891 | 67 | ▶ | sub _push_data_context { | ||||||||||||||||||||||||||
|
Subroutine
_push_data_context: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 892 | 67 | my ($self, $context) = @_; | |||||||||||||||||||||||||||
| 893 | 67 | TRACE "Stack data context '$context'"; | |||||||||||||||||||||||||||
| 894 | 67 | unshift @{$self->data_context}, $context | |||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||
| 897 | 25 | ▶ | sub _pop_data_context { | ||||||||||||||||||||||||||
|
Subroutine
_pop_data_context: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 898 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||
| 899 | 25 | shift @{$self->data_context}; | |||||||||||||||||||||||||||
| 900 | 25 | TRACE "Popped data context stack back to '".$self->_get_data_context."'"; | |||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||
| 903 | 1 | ▶ | sub _clear_data_context { $_[0]->data_context([]) }; | ||||||||||||||||||||||||||
|
Subroutine
_clear_data_context: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||
| 905 | 250 | ▶ | sub _get_data_context { $_[0]->data_context->[0] || 'data' } | ||||||||||||||||||||||||||
|
Subroutine
_get_data_context: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||
| 907 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||
| 909 | # Append a given char to the current string token or, if there isn't one, | ||||||||||||||||||||||||||||
| 910 | # create one (emitting existing tokens as appropriate) | ||||||||||||||||||||||||||||
| 911 | # | ||||||||||||||||||||||||||||
| 912 | # @param char character to add | ||||||||||||||||||||||||||||
| 913 | # | ||||||||||||||||||||||||||||
| 914 | 4232 | ▶ | sub _append_to_string_token { | ||||||||||||||||||||||||||
|
Subroutine
_append_to_string_token: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 915 | 4232 | my ($self, $char) = @_; | |||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||
| 917 | 4232 | TRACE " Append [ $char ] to string token"; | |||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||
| 919 | # Look at the current temporary token (if there is one). | ||||||||||||||||||||||||||||
| 920 | 4232 | my $tmp_token = $self->temporary_token; | |||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||
| 922 | 4232 | ▶ | if ($tmp_token && $tmp_token->{type} eq 'STRING') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tmp_token and $tmp_token->{"type"} eq "STRING"
MC/DC100%2/2
$tmp_token and $tmp_token->{"type"} eq "STRING"
$tmp_token
$tmp_token->{"type"} eq "STRING"
Truth table100%3/3
A and B
A= $tmp_tokenB= $tmp_token->{"type"} eq "STRING"
| |||||||||||||||||||||||||||||
| 923 | 4099 | TRACE " -> Has existing string token"; | |||||||||||||||||||||||||||
| 924 | 4099 | $self->temporary_token->{content} .= $char; | |||||||||||||||||||||||||||
| 925 | 4099 | return; # Nothing to return | |||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||
| 928 | # Otherwise create a new token and return the previous one | ||||||||||||||||||||||||||||
| 929 | # if there was one. | ||||||||||||||||||||||||||||
| 930 | 133 | $self->_create_token({type=>'STRING',content=>$char}); | |||||||||||||||||||||||||||
| 931 | 133 | return; | |||||||||||||||||||||||||||
| 932 | } | ||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||
| 934 | # ------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||
| 936 | # Create a new token in the temporary store. If a token already exists | ||||||||||||||||||||||||||||
| 937 | # there then this method returns it. | ||||||||||||||||||||||||||||
| 938 | # | ||||||||||||||||||||||||||||
| 939 | # @param tpken initial token | ||||||||||||||||||||||||||||
| 940 | # @returns the old temporary token | ||||||||||||||||||||||||||||
| 941 | # before it was replaced | ||||||||||||||||||||||||||||
| 942 | # with the new one. | ||||||||||||||||||||||||||||
| 943 | # | ||||||||||||||||||||||||||||
| 944 | 381 | ▶ | sub _create_token { | ||||||||||||||||||||||||||
|
Subroutine
_create_token: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 945 | 381 | my ($self, $token) = @_; | |||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||
| 947 | 381 | ▶ | $self->_raise_parse_error("No token data passed to _create_token()") unless $token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||
| 949 | 380 | TRACE " Create new token [ ".$token->{type}." ]"; | |||||||||||||||||||||||||||
| 950 | 380 | my $old_temporary_token = undef; | |||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||
| 952 | 380 | ▶ | if ($self->temporary_token) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 953 | 268 | $self->_emit_token; | |||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||
| 956 | # Clear any current context | ||||||||||||||||||||||||||||
| 957 | 380 | $self->temporary_token_context(undef); | |||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||
| 959 | 380 | $self->temporary_token( $token ); | |||||||||||||||||||||||||||
| 960 | 380 | return undef; | |||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||
| 963 | 5 | 1; | |||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||
| 965 | __END__ | ||||||||||||||||||||||||||||