| 1 | package JQ::Lite::Tokenizer; | ||||||||||
| 2 | |||||||||||
| 3 | 182 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 182 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 182 | ▶ | use JQ::Lite::Util (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # The tokenizer deliberately recognizes only the top-level pipeline boundary. | ||||||||||
| 9 | # Filter-local syntax remains owned by the existing, compatibility-sensitive | ||||||||||
| 10 | # parser and filter implementations while those constructs are ported to ASTs. | ||||||||||
| 11 | 1043 | ▶ | sub tokenize { | ||||||||
|
Subroutine
tokenize: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||
| 12 | 1043 | my ($source) = @_; | |||||||||
| 13 | |||||||||||
| 14 | 1043 | ▶ | return [] unless defined $source; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | |||||||||||
| 16 | 1043 | my @parts = JQ::Lite::Util::_split_top_level_pipes($source); | |||||||||
| 17 | 1043 | my @tokens; | |||||||||
| 18 | 1043 | my $offset = 0; | |||||||||
| 19 | |||||||||||
| 20 | 1043 | for my $index (0 .. $#parts) { | |||||||||
| 21 | 1526 | my $text = $parts[$index]; | |||||||||
| 22 | 1526 | my $start = index($source, $text, $offset); | |||||||||
| 23 | 1526 | ▶ | $start = $offset if $start < 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 1526 | my $end = $start + length($text); | |||||||||
| 25 | |||||||||||
| 26 | 1526 | push @tokens, { | |||||||||
| 27 | type => 'FILTER', | ||||||||||
| 28 | value => $text, | ||||||||||
| 29 | start => $start, | ||||||||||
| 30 | end => $end, | ||||||||||
| 31 | }; | ||||||||||
| 32 | |||||||||||
| 33 | 1526 | ▶ | if ($index < $#parts) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 483 | my $pipe = index($source, '|', $end); | |||||||||
| 35 | 483 | ▶ | $pipe = $end if $pipe < 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 483 | push @tokens, { | |||||||||
| 37 | type => 'PIPE', | ||||||||||
| 38 | value => '|', | ||||||||||
| 39 | start => $pipe, | ||||||||||
| 40 | end => $pipe + 1, | ||||||||||
| 41 | }; | ||||||||||
| 42 | 483 | $offset = $pipe + 1; | |||||||||
| 43 | } | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 1043 | push @tokens, { | |||||||||
| 47 | type => 'EOF', | ||||||||||
| 48 | value => undef, | ||||||||||
| 49 | start => length($source), | ||||||||||
| 50 | end => length($source), | ||||||||||
| 51 | }; | ||||||||||
| 52 | |||||||||||
| 53 | 1043 | return \@tokens; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 182 | 1; | |||||||||