| 1 | package Markdown::Compiler::Lexer; | ||||||||||||||||||||||||||||||
| 2 | 18 | ▶ | BEGIN { | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | { | ||||||||||||||||||||||||||||||
| 4 | package Markdown::Compiler::Lexer::Token; | ||||||||||||||||||||||||||||||
| 5 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 18 | has source => ( | |||||||||||||||||||||||||||||
| 8 | is => 'ro', | ||||||||||||||||||||||||||||||
| 9 | required => 1, | ||||||||||||||||||||||||||||||
| 10 | ); | ||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 18 | has start => ( | |||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 18 | has end => ( | |||||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||||
| 19 | required => 1, | ||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | has line => ( | ||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||
| 24 | lazy => 1, | ||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | builder => sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 26 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 0 | my $lines = grep { $_ eq "\n" } (split(//, substr(${$self->source}, 0, $self->start))); | |||||||||||||||||||||||||||||
| 29 | 0 | return $lines; | |||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||||
| 31 | 18 | ); | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | has content => ( | ||||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||||||||||||||
| 36 | 135 | ▶ | builder => sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
_build_content: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 37 | 135 | my $self = shift; | |||||||||||||||||||||||||||||
| 38 | 135 | return substr( ${$self->source}, $self->start, ( $self->end - $self->start ) ); | |||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||||
| 40 | 18 | ); | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | # Allow to overide, for example to return multiple tokens. | ||||||||||||||||||||||||||||||
| 43 | 398 | ▶ | sub tokens { | ||||||||||||||||||||||||||||
|
Subroutine
tokens: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 44 | 398 | return shift; | |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | 18 | 1; | |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||
| 50 | 18 | package Markdown::Compiler::Lexer::Token::EscapedChar; | |||||||||||||||||||||||||||||
| 51 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 52 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 294 | ▶ | sub type { 'EscapedChar' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 55 | 424 | ▶ | sub match { [ qr/\G(\\\\|\\\`|\\\*|\\\_|\\\{|\\\}|\\\[|\\\]|\\\(|\\\)|\\\#|\\\+|\\\-|\\\.|\\\!)/ ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | # Delete the first \ | ||||||||||||||||||||||||||||||
| 58 | 14 | ▶ | around content => sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 59 | 14 | my $orig = shift; | |||||||||||||||||||||||||||||
| 60 | 14 | my $value = $orig->(@_); | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | 14 | return substr($value,1); | |||||||||||||||||||||||||||||
| 63 | 18 | }; | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 18 | 1; | |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||
| 68 | 18 | package Markdown::Compiler::Lexer::Token::CodeBlock; | |||||||||||||||||||||||||||||
| 69 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 70 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | 30 | ▶ | sub type { 'CodeBlock' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 73 | 410 | ▶ | sub match {[ | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 74 | 410 | qr|\G\`\`\`(?:\n\|$)|, | |||||||||||||||||||||||||||||
| 75 | qr|\G\`\`\`[ ]*\S+[ ]*\n|, | ||||||||||||||||||||||||||||||
| 76 | ]} | ||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||
| 80 | has language => ( | ||||||||||||||||||||||||||||||
| 81 | is => 'ro', | ||||||||||||||||||||||||||||||
| 82 | lazy => 1, | ||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | builder => sub { | ||||||||||||||||||||||||||||
|
Subroutine
_build_language: called CC=2 SCAR=7.3
| |||||||||||||||||||||||||||||||
| 84 | 2 | my $content = shift->content; | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( $content =~ m|\`\`\`[ ]*(\S+)[ ]*\n| ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 87 | 0 | return $1; | |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||
| 89 | 2 | return undef; | |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||
| 91 | 18 | ); | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | 18 | 1; | |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||
| 97 | 18 | package Markdown::Compiler::Lexer::Token::HR; | |||||||||||||||||||||||||||||
| 98 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 99 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub type { 'HR' } | ||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 102 | 406 | ▶ | sub match { [ qr/\G(?:(?<=^)|(?<=\n))((?:(\*\s*\*\s*\*)|(-\s*-\s*-)|(_\s*_\s*_))[-_*\s]*)\n/ ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 103 | 18 | 1; | |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||
| 107 | 18 | package Markdown::Compiler::Lexer::Token::Image; | |||||||||||||||||||||||||||||
| 108 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 109 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 110 | 18 | ▶ | use Regexp::Common qw( URI ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||
| 112 | # Regexp::Common::URI doesn't support fragments, I should make a patch for it. | ||||||||||||||||||||||||||||||
| 113 | 18 | my $url_match = qr/$RE{URI}{HTTP}{ -scheme => 'https?' }(?:\#[A-z0-9-_]+)?/; | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | 62 | ▶ | sub type { 'Image' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 116 | # sub match {[ | ||||||||||||||||||||||||||||||
| 117 | # qr/\G\!\[(.*)\]\(($url_match)\s+"([^"]+)"\s*\)/, | ||||||||||||||||||||||||||||||
| 118 | # qr/\G\!\[(.*)\]\(($url_match\s*)\)/, | ||||||||||||||||||||||||||||||
| 119 | # qr/\G\!($url_match)/, | ||||||||||||||||||||||||||||||
| 120 | # ]} | ||||||||||||||||||||||||||||||
| 121 | 406 | ▶ | sub match {[ | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 122 | 406 | qr/\G\!\[(.*)\]\(([^ ]+)\s+"([^"]+)"\s*\)/, | |||||||||||||||||||||||||||||
| 123 | qr/\G\!\[(.*)\]\(([^ ]+\s*)\)/, | ||||||||||||||||||||||||||||||
| 124 | qr/\G\!($url_match)/, | ||||||||||||||||||||||||||||||
| 125 | ]} | ||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | has text => ( | ||||||||||||||||||||||||||||||
| 128 | is => 'ro', | ||||||||||||||||||||||||||||||
| 129 | lazy => 1, | ||||||||||||||||||||||||||||||
| 130 | 4 | ▶ | builder => sub { shift->data->{text} }, | ||||||||||||||||||||||||||||
|
Subroutine
_build_text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 131 | 18 | ); | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||
| 133 | has href => ( | ||||||||||||||||||||||||||||||
| 134 | is => 'ro', | ||||||||||||||||||||||||||||||
| 135 | lazy => 1, | ||||||||||||||||||||||||||||||
| 136 | 4 | ▶ | builder => sub { shift->data->{href} }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 137 | 18 | ); | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||
| 139 | has title => ( | ||||||||||||||||||||||||||||||
| 140 | is => 'ro', | ||||||||||||||||||||||||||||||
| 141 | lazy => 1, | ||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | builder => sub { shift->data->{title} }, | ||||||||||||||||||||||||||||
|
Subroutine
_build_title: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 143 | 18 | ); | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||
| 145 | has data => ( | ||||||||||||||||||||||||||||||
| 146 | is => 'ro', | ||||||||||||||||||||||||||||||
| 147 | lazy => 1, | ||||||||||||||||||||||||||||||
| 148 | 4 | ▶ | builder => sub { | ||||||||||||||||||||||||||||
|
Subroutine
_build_data: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||
| 149 | 4 | my $content = shift->content; | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | 4 | ▶ | if ( $content =~ /!\[(.*)\]\(([^ ]+)\s+"([^"]+)"\s*\)/ ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 152 | return { | ||||||||||||||||||||||||||||||
| 153 | 1 | text => $1, | |||||||||||||||||||||||||||||
| 154 | href => $2, | ||||||||||||||||||||||||||||||
| 155 | title => $3, | ||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||
| 157 | } elsif ( $content =~ /!\[(.*)\]\(([^ ]+\s*)\)/ ) { | ||||||||||||||||||||||||||||||
| 158 | return { | ||||||||||||||||||||||||||||||
| 159 | 1 | text => $1, | |||||||||||||||||||||||||||||
| 160 | href => $2, | ||||||||||||||||||||||||||||||
| 161 | title => undef, | ||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||
| 163 | } elsif ( $content =~ /!($url_match)/ ) { | ||||||||||||||||||||||||||||||
| 164 | return { | ||||||||||||||||||||||||||||||
| 165 | 2 | text => undef, | |||||||||||||||||||||||||||||
| 166 | href => $1, | ||||||||||||||||||||||||||||||
| 167 | title => undef, | ||||||||||||||||||||||||||||||
| 168 | }; | ||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||
| 171 | 18 | ); | |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||
| 173 | 18 | 1; | |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||||
| 176 | 18 | package Markdown::Compiler::Lexer::Token::Link; | |||||||||||||||||||||||||||||
| 177 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 178 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 179 | 18 | ▶ | use Regexp::Common qw( URI ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | # Regexp::Common::URI doesn't support fragments, I should make a patch for it. | ||||||||||||||||||||||||||||||
| 182 | 18 | my $url_match = qr/$RE{URI}{HTTP}{ -scheme => 'https?' }(?:#[A-z0-9-_]+)?(?=[ )])/; | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||
| 184 | 132 | ▶ | sub type { 'Link' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 185 | # qr/\G\[.*\]\($url_match\s+"([^"]+)"\s*\)/, | ||||||||||||||||||||||||||||||
| 186 | # qr/\G\[.*\]\($url_match\)/, | ||||||||||||||||||||||||||||||
| 187 | # qr/\G$url_match/, | ||||||||||||||||||||||||||||||
| 188 | 402 | ▶ | sub match {[ | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 189 | 402 | qr/\G\[.*?\]\($url_match\s+"([^"]+)"\s*\)/, | |||||||||||||||||||||||||||||
| 190 | qr/\G\[.*?\]\($url_match\)/, | ||||||||||||||||||||||||||||||
| 191 | qr/\G$url_match/, | ||||||||||||||||||||||||||||||
| 192 | qr/\G$RE{URI}{HTTP}{ -scheme => 'https?' }/, | ||||||||||||||||||||||||||||||
| 193 | ]} | ||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||
| 195 | has text => ( | ||||||||||||||||||||||||||||||
| 196 | is => 'ro', | ||||||||||||||||||||||||||||||
| 197 | lazy => 1, | ||||||||||||||||||||||||||||||
| 198 | 10 | ▶ | builder => sub { shift->data->{text} }, | ||||||||||||||||||||||||||||
|
Subroutine
_build_text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 199 | 18 | ); | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||
| 201 | has title => ( | ||||||||||||||||||||||||||||||
| 202 | is => 'ro', | ||||||||||||||||||||||||||||||
| 203 | lazy => 1, | ||||||||||||||||||||||||||||||
| 204 | 10 | ▶ | builder => sub { shift->data->{title} }, | ||||||||||||||||||||||||||||
|
Subroutine
_build_title: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 205 | 18 | ); | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||
| 207 | has href => ( | ||||||||||||||||||||||||||||||
| 208 | is => 'ro', | ||||||||||||||||||||||||||||||
| 209 | lazy => 1, | ||||||||||||||||||||||||||||||
| 210 | 10 | ▶ | builder => sub { shift->data->{href} }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 211 | 18 | ); | |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||
| 213 | has data => ( | ||||||||||||||||||||||||||||||
| 214 | is => 'ro', | ||||||||||||||||||||||||||||||
| 215 | lazy => 1, | ||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | builder => sub { | ||||||||||||||||||||||||||||
|
Subroutine
_build_data: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||
| 217 | 0 | my $content = shift->content; | |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ( $content =~ /\[(.*)\]\(($url_match)\s+"([^"]+)"\s*\)/ ) { | ||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||
| 220 | return { | ||||||||||||||||||||||||||||||
| 221 | 0 | text => $1, | |||||||||||||||||||||||||||||
| 222 | href => $2, | ||||||||||||||||||||||||||||||
| 223 | title => $3, | ||||||||||||||||||||||||||||||
| 224 | }; | ||||||||||||||||||||||||||||||
| 225 | } elsif ( $content =~ /\[(.*)\]\(($url_match\s*)\)/ ) { | ||||||||||||||||||||||||||||||
| 226 | return { | ||||||||||||||||||||||||||||||
| 227 | 0 | text => $1, | |||||||||||||||||||||||||||||
| 228 | href => $2, | ||||||||||||||||||||||||||||||
| 229 | title => undef, | ||||||||||||||||||||||||||||||
| 230 | }; | ||||||||||||||||||||||||||||||
| 231 | } elsif ( $content =~ /($url_match)/ ) { | ||||||||||||||||||||||||||||||
| 232 | return { | ||||||||||||||||||||||||||||||
| 233 | 0 | text => undef, | |||||||||||||||||||||||||||||
| 234 | href => $1, | ||||||||||||||||||||||||||||||
| 235 | title => undef, | ||||||||||||||||||||||||||||||
| 236 | }; | ||||||||||||||||||||||||||||||
| 237 | } elsif ( $content =~ /($RE{URI}{HTTP}{ -scheme => 'https?' })/ ) { | ||||||||||||||||||||||||||||||
| 238 | return { | ||||||||||||||||||||||||||||||
| 239 | 0 | text => undef, | |||||||||||||||||||||||||||||
| 240 | href => $1, | ||||||||||||||||||||||||||||||
| 241 | title => undef, | ||||||||||||||||||||||||||||||
| 242 | }; | ||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||
| 244 | }, | ||||||||||||||||||||||||||||||
| 245 | 18 | ); | |||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||
| 247 | 18 | 1; | |||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||
| 251 | 18 | package Markdown::Compiler::Lexer::Token::Item; | |||||||||||||||||||||||||||||
| 252 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 253 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||
| 255 | 126 | ▶ | sub type { 'Item' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 256 | 392 | ▶ | sub match { [ | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 257 | # Unordered / Beginning of line, then * + or - | ||||||||||||||||||||||||||||||
| 258 | 392 | qr/\G(?:(?<=^)|(?<=\n))(?:\*|\+|\-) /, | |||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||
| 260 | # Numbered / Beginning of line, [number].[space] | ||||||||||||||||||||||||||||||
| 261 | qr/\G(?:(?<=^)|(?<=\n))\d+\.\s+/, | ||||||||||||||||||||||||||||||
| 262 | ]} | ||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||
| 264 | # Note: I have the following version of this I should solve why I did this: | ||||||||||||||||||||||||||||||
| 265 | # $str =~ /\G(?:(?=^)|(?=\n))(?:\*|\+|\-) /gc or ( exists $tokens[-1] and $tokens[-1]->{type} eq 'line_break' and $str =~ /\G(?:\*|\+|\-) /gc | ||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||
| 267 | 18 | 1; | |||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||||
| 271 | 18 | package Markdown::Compiler::Lexer::Token::TableStart; | |||||||||||||||||||||||||||||
| 272 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 273 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||
| 275 | 57 | ▶ | sub type { 'TableStart' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 276 | 380 | ▶ | sub match { [ qr/\G(?:(?<=^)|(?<=\n))\| / ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||
| 278 | 18 | 1; | |||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||
| 281 | { | ||||||||||||||||||||||||||||||
| 282 | 18 | package Markdown::Compiler::Lexer::Token::TableHeaderSep; | |||||||||||||||||||||||||||||
| 283 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 284 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | sub type { 'TableHeaderSep' } | ||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 287 | # sub match { [ qr/\G(?:(?<=^)|(?<=\n))\| / ] } | ||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||
| 289 | 374 | ▶ | sub match { return [ | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 290 | 374 | qr/\G:---:/, | |||||||||||||||||||||||||||||
| 291 | qr/\G:--/, | ||||||||||||||||||||||||||||||
| 292 | qr/\G--:/, | ||||||||||||||||||||||||||||||
| 293 | ]; | ||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||
| 296 | 18 | 1; | |||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||||
| 300 | 18 | package Markdown::Compiler::Lexer::Token::BlockQuote; | |||||||||||||||||||||||||||||
| 301 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 302 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||
| 304 | 18 | ▶ | sub type { 'BlockQuote' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 305 | 370 | ▶ | sub match { [ qr/\G(?:(?=^)|(?=\n)|(?=>\s))> / ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||
| 307 | 18 | 1; | |||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||
| 310 | { | ||||||||||||||||||||||||||||||
| 311 | 18 | package Markdown::Compiler::Lexer::Token::Header; | |||||||||||||||||||||||||||||
| 312 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 313 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||
| 315 | 2 | ▶ | sub type { 'Header' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 316 | 367 | ▶ | sub match { [ qr/\G([\#]+) (.+?)(?=\n|$)/ ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||
| 318 | has size => ( | ||||||||||||||||||||||||||||||
| 319 | is => 'ro', | ||||||||||||||||||||||||||||||
| 320 | lazy => 1, | ||||||||||||||||||||||||||||||
| 321 | 1 | ▶ | default => sub { length(shift->data->{header}) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 322 | 18 | ); | |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||
| 324 | has title => ( | ||||||||||||||||||||||||||||||
| 325 | is => 'ro', | ||||||||||||||||||||||||||||||
| 326 | lazy => 1, | ||||||||||||||||||||||||||||||
| 327 | 1 | ▶ | default => sub { shift->data->{title} }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 328 | 18 | ); | |||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||
| 330 | has data => ( | ||||||||||||||||||||||||||||||
| 331 | is => 'ro', | ||||||||||||||||||||||||||||||
| 332 | lazy => 1, | ||||||||||||||||||||||||||||||
| 333 | 1 | ▶ | builder => sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||
| 334 | 1 | my $content = shift->content; | |||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||
| 336 | 1 | ▶ | if ( $content =~ /^([\#]+)\s+(.+?)$/ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 337 | return { | ||||||||||||||||||||||||||||||
| 338 | 1 | header => $1, | |||||||||||||||||||||||||||||
| 339 | title => $2, | ||||||||||||||||||||||||||||||
| 340 | }; | ||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||
| 342 | }, | ||||||||||||||||||||||||||||||
| 343 | 18 | ); | |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||
| 346 | 18 | 1; | |||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||
| 349 | { | ||||||||||||||||||||||||||||||
| 350 | 18 | package Markdown::Compiler::Lexer::Token::InlineCode; | |||||||||||||||||||||||||||||
| 351 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 352 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||
| 354 | 40 | ▶ | sub type { 'InlineCode' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 355 | 374 | ▶ | sub match { [ qr/\G`/ ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||
| 357 | 18 | 1; | |||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||
| 360 | { | ||||||||||||||||||||||||||||||
| 361 | 18 | package Markdown::Compiler::Lexer::Token::Bold; | |||||||||||||||||||||||||||||
| 362 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 363 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||
| 365 | 132 | ▶ | sub type { 'Bold' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||
| 367 | 18 | 1; | |||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||
| 370 | { | ||||||||||||||||||||||||||||||
| 371 | 18 | package Markdown::Compiler::Lexer::Token::Italic; | |||||||||||||||||||||||||||||
| 372 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 373 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||
| 375 | 156 | ▶ | sub type { 'Italic' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||
| 377 | 18 | 1; | |||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||
| 380 | { | ||||||||||||||||||||||||||||||
| 381 | 18 | package Markdown::Compiler::Lexer::Token::BoldItalic; | |||||||||||||||||||||||||||||
| 382 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 383 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | sub type { 'BoldItalic' } | ||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||
| 387 | 18 | 1; | |||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||
| 390 | { | ||||||||||||||||||||||||||||||
| 391 | 18 | package Markdown::Compiler::Lexer::Token::BoldItalicMaker; | |||||||||||||||||||||||||||||
| 392 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 393 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | sub type { 'ShortAttribute' } | ||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 396 | 365 | ▶ | sub match { | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 397 | return [ | ||||||||||||||||||||||||||||||
| 398 | 365 | qr/\G\*\*\*/, | |||||||||||||||||||||||||||||
| 399 | qr/\G___/, | ||||||||||||||||||||||||||||||
| 400 | qr/\G\*\*/, | ||||||||||||||||||||||||||||||
| 401 | qr/\G(?:(?<=^)|(?<=[\s]))\*(?=\S|$)/, | ||||||||||||||||||||||||||||||
| 402 | qr/\G(?<=[\S])\*/, | ||||||||||||||||||||||||||||||
| 403 | qr/\G__/, | ||||||||||||||||||||||||||||||
| 404 | qr/\G_/, | ||||||||||||||||||||||||||||||
| 405 | ] | ||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||
| 408 | 26 | ▶ | sub tokens { | ||||||||||||||||||||||||||||
|
Subroutine
tokens: called CC=7 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 409 | 26 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 410 | 26 | my $content = $self->content; | |||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||
| 412 | 26 | ▶ | if ( $content =~ /^___/ ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 413 | 0 | return Markdown::Compiler::Lexer::Token::BoldItalic->new( | |||||||||||||||||||||||||||||
| 414 | start => $self->start, | ||||||||||||||||||||||||||||||
| 415 | end => $self->end, | ||||||||||||||||||||||||||||||
| 416 | source => $self->source | ||||||||||||||||||||||||||||||
| 417 | ); | ||||||||||||||||||||||||||||||
| 418 | } elsif ( $content =~ /^\*\*\*/ ) { | ||||||||||||||||||||||||||||||
| 419 | 0 | return Markdown::Compiler::Lexer::Token::BoldItalic->new( | |||||||||||||||||||||||||||||
| 420 | start => $self->start, | ||||||||||||||||||||||||||||||
| 421 | end => $self->end, | ||||||||||||||||||||||||||||||
| 422 | source => $self->source | ||||||||||||||||||||||||||||||
| 423 | ); | ||||||||||||||||||||||||||||||
| 424 | } elsif ( $content =~ /^\*\*/ ) { | ||||||||||||||||||||||||||||||
| 425 | 8 | return Markdown::Compiler::Lexer::Token::Bold->new( | |||||||||||||||||||||||||||||
| 426 | start => $self->start, | ||||||||||||||||||||||||||||||
| 427 | end => $self->end, | ||||||||||||||||||||||||||||||
| 428 | source => $self->source | ||||||||||||||||||||||||||||||
| 429 | ); | ||||||||||||||||||||||||||||||
| 430 | } elsif ( $content =~ /^__/ ) { | ||||||||||||||||||||||||||||||
| 431 | 4 | return Markdown::Compiler::Lexer::Token::Bold->new( | |||||||||||||||||||||||||||||
| 432 | start => $self->start, | ||||||||||||||||||||||||||||||
| 433 | end => $self->end, | ||||||||||||||||||||||||||||||
| 434 | source => $self->source | ||||||||||||||||||||||||||||||
| 435 | ); | ||||||||||||||||||||||||||||||
| 436 | } elsif ( $content =~ /^_/ ) { | ||||||||||||||||||||||||||||||
| 437 | 6 | return Markdown::Compiler::Lexer::Token::Italic->new( | |||||||||||||||||||||||||||||
| 438 | start => $self->start, | ||||||||||||||||||||||||||||||
| 439 | end => $self->end, | ||||||||||||||||||||||||||||||
| 440 | source => $self->source | ||||||||||||||||||||||||||||||
| 441 | ); | ||||||||||||||||||||||||||||||
| 442 | } elsif ( $content =~ /^\*/ ) { | ||||||||||||||||||||||||||||||
| 443 | 8 | return Markdown::Compiler::Lexer::Token::Italic->new( | |||||||||||||||||||||||||||||
| 444 | start => $self->start, | ||||||||||||||||||||||||||||||
| 445 | end => $self->end, | ||||||||||||||||||||||||||||||
| 446 | source => $self->source | ||||||||||||||||||||||||||||||
| 447 | ); | ||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||
| 450 | }; | ||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||
| 454 | 18 | 1; | |||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||
| 457 | { | ||||||||||||||||||||||||||||||
| 458 | 18 | package Markdown::Compiler::Lexer::Token::LineBreak; | |||||||||||||||||||||||||||||
| 459 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 460 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||
| 462 | 195 | ▶ | sub type { 'LineBreak' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 463 | 339 | ▶ | sub match { [ qr/\G\n/ ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||
| 465 | 18 | 1; | |||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||
| 468 | { | ||||||||||||||||||||||||||||||
| 469 | 18 | package Markdown::Compiler::Lexer::Token::Space; | |||||||||||||||||||||||||||||
| 470 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 471 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||
| 473 | 1175 | ▶ | sub type { 'Space' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 474 | 301 | ▶ | sub match { [ qr/\G\s+/ ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||
| 476 | has length => ( | ||||||||||||||||||||||||||||||
| 477 | is => 'ro', | ||||||||||||||||||||||||||||||
| 478 | lazy => 1, | ||||||||||||||||||||||||||||||
| 479 | 1 | ▶ | builder => sub { length(shift->content) }, | ||||||||||||||||||||||||||||
|
Subroutine
_build_length: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 480 | 18 | ); | |||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||
| 482 | 18 | 1; | |||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||
| 485 | { | ||||||||||||||||||||||||||||||
| 486 | 18 | package Markdown::Compiler::Lexer::Token::Word; | |||||||||||||||||||||||||||||
| 487 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 488 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||
| 490 | # We'll match words to avoid making too many objects, such | ||||||||||||||||||||||||||||||
| 491 | # that "Hello World" becomes 11 objects. | ||||||||||||||||||||||||||||||
| 492 | 1700 | ▶ | sub type { 'Word' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 493 | 196 | ▶ | sub match { [ qr|\G[a-zA-Z]+|, qr|\G\d+\.\d+|, qr|\G\d+| ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||
| 495 | 18 | 1; | |||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||
| 498 | { | ||||||||||||||||||||||||||||||
| 499 | 18 | package Markdown::Compiler::Lexer::Token::Char; | |||||||||||||||||||||||||||||
| 500 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 501 | 18 | extends 'Markdown::Compiler::Lexer::Token'; | |||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||
| 503 | 490 | ▶ | sub type { 'Char' } | ||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 504 | 55 | ▶ | sub match { [ qr/\G./s ] } | ||||||||||||||||||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||
| 506 | 18 | 1; | |||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||
| 509 | 18 | ▶ | use Moo; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 510 | 18 | ▶ | use v5.10; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||
| 512 | 18 | has source => ( | |||||||||||||||||||||||||||||
| 513 | is => 'ro', | ||||||||||||||||||||||||||||||
| 514 | required => 1, | ||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||
| 516 | ); | ||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||
| 518 | 18 | has tokens => ( | |||||||||||||||||||||||||||||
| 519 | is => 'ro', | ||||||||||||||||||||||||||||||
| 520 | builder => '_build_tokens', | ||||||||||||||||||||||||||||||
| 521 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||
| 523 | ); | ||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||
| 525 | has token_table => ( | ||||||||||||||||||||||||||||||
| 526 | is => 'ro', | ||||||||||||||||||||||||||||||
| 527 | lazy => 1, | ||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | builder => sub { | ||||||||||||||||||||||||||||
|
Subroutine
_build_token_table: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 529 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||
| 531 | 0 | my $str; | |||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||
| 533 | 0 | foreach my $token ( @{$self->tokens} ) { | |||||||||||||||||||||||||||||
| 534 | 0 | ( my $content = $token->content ) =~ s/\n//g; | |||||||||||||||||||||||||||||
| 535 | 0 | $str .= sprintf( "%20s | %s\n", $content, $token->type ); | |||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||
| 538 | 0 | return $str; | |||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||
| 540 | 18 | ); | |||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||
| 542 | has hooks => ( | ||||||||||||||||||||||||||||||
| 543 | is => 'ro', | ||||||||||||||||||||||||||||||
| 544 | 65 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 545 | 18 | ); | |||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||
| 547 | has lexer_tokens => ( | ||||||||||||||||||||||||||||||
| 548 | is => 'ro', | ||||||||||||||||||||||||||||||
| 549 | 65 | ▶ | default => sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 550 | 65 | return [qw( | |||||||||||||||||||||||||||||
| 551 | Markdown::Compiler::Lexer::Token::EscapedChar | ||||||||||||||||||||||||||||||
| 552 | Markdown::Compiler::Lexer::Token::CodeBlock | ||||||||||||||||||||||||||||||
| 553 | Markdown::Compiler::Lexer::Token::HR | ||||||||||||||||||||||||||||||
| 554 | Markdown::Compiler::Lexer::Token::Image | ||||||||||||||||||||||||||||||
| 555 | Markdown::Compiler::Lexer::Token::Link | ||||||||||||||||||||||||||||||
| 556 | Markdown::Compiler::Lexer::Token::Item | ||||||||||||||||||||||||||||||
| 557 | Markdown::Compiler::Lexer::Token::TableStart | ||||||||||||||||||||||||||||||
| 558 | Markdown::Compiler::Lexer::Token::TableHeaderSep | ||||||||||||||||||||||||||||||
| 559 | Markdown::Compiler::Lexer::Token::InlineCode | ||||||||||||||||||||||||||||||
| 560 | Markdown::Compiler::Lexer::Token::BlockQuote | ||||||||||||||||||||||||||||||
| 561 | Markdown::Compiler::Lexer::Token::Header | ||||||||||||||||||||||||||||||
| 562 | Markdown::Compiler::Lexer::Token::BoldItalicMaker | ||||||||||||||||||||||||||||||
| 563 | Markdown::Compiler::Lexer::Token::LineBreak | ||||||||||||||||||||||||||||||
| 564 | Markdown::Compiler::Lexer::Token::Space | ||||||||||||||||||||||||||||||
| 565 | Markdown::Compiler::Lexer::Token::Word | ||||||||||||||||||||||||||||||
| 566 | Markdown::Compiler::Lexer::Token::Char | ||||||||||||||||||||||||||||||
| 567 | )]; | ||||||||||||||||||||||||||||||
| 568 | # Removed from betweenb Space and Char, might have been | ||||||||||||||||||||||||||||||
| 569 | # more trouble than it's worth. | ||||||||||||||||||||||||||||||
| 570 | # Markdown::Compiler::Lexer::Token::Word | ||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||
| 572 | 18 | ); | |||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||
| 574 | 65 | ▶ | sub _build_tokens { | ||||||||||||||||||||||||||||
|
Subroutine
_build_tokens: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||
| 575 | 65 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||
| 577 | 65 | my $str = $self->source; | |||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||
| 579 | 65 | pos($str) = 0; | |||||||||||||||||||||||||||||
| 580 | 65 | my @tokens; | |||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||
| 582 | 65 | ▶ | PARSE: while ( length($str) != pos($str) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 583 | 424 | my $start_pos = pos($str); | |||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||
| 585 | 424 | TOKEN: foreach my $token_class ( @{$self->lexer_tokens} ) { | |||||||||||||||||||||||||||||
| 586 | 5561 | my $matches = $token_class->match; | |||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||
| 588 | 5561 | foreach my $match ( @{$matches} ) { | |||||||||||||||||||||||||||||
| 589 | 11368 | ▶ | if ( $str =~ m|$match|gc ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 590 | 424 | push @tokens, $token_class->new( | |||||||||||||||||||||||||||||
| 591 | source => \$self->source, | ||||||||||||||||||||||||||||||
| 592 | start => $start_pos, | ||||||||||||||||||||||||||||||
| 593 | end => pos($str), | ||||||||||||||||||||||||||||||
| 594 | )->tokens; | ||||||||||||||||||||||||||||||
| 595 | 424 | next PARSE; | |||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||
| 599 | # We were not able to match the content, so we're blowing up now. | ||||||||||||||||||||||||||||||
| 600 | 0 | die "Error at offset $start_pos of document: next 10 chars" . substr($self->source, $start_pos, 10 ); | |||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||
| 603 | 65 | return [ @tokens ]; | |||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||
| 606 | 18 | 1; | |||||||||||||||||||||||||||||