| 1 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package MarpaX::Languages::IDL::AST::Util; | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Translate an IDL source to an AST - Tools | ||||||||||
| 7 | |||||||||||
| 8 | 3 | our $VERSION = '0.007'; # VERSION | |||||||||
| 9 | |||||||||||
| 10 | # Marpa follows Unicode recommendation, i.e. perl's \R, that cannot be in a character class | ||||||||||
| 11 | 3 | our $NEWLINE_REGEXP = qr/(?>\x0D\x0A|\v)/; | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub showLineAndCol { | ||||||||
|
Subroutine
showLineAndCol: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||
| 16 | 0 | my ($line, $col, $source) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | my $pointer = ($col > 0 ? '-' x ($col-1) : '') . '^'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | my $content = ''; | |||||||||
| 20 | |||||||||||
| 21 | 0 | my $prevpos = pos($source); | |||||||||
| 22 | 0 | pos($source) = undef; | |||||||||
| 23 | 0 | my $thisline = 0; | |||||||||
| 24 | 0 | my $nbnewlines = 0; | |||||||||
| 25 | 0 | my $eos = 0; | |||||||||
| 26 | 0 | ▶ | while ($source =~ m/\G(.*?)($NEWLINE_REGEXP|\Z)/scmg) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | ▶ | if (++$thisline == $line) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 0 | $content = substr($source, $-[1], $+[1] - $-[1]); | |||||||||
| 29 | 0 | ▶ | $eos = (($+[2] - $-[2]) > 0) ? 0 : 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | last; | |||||||||
| 31 | } | ||||||||||
| 32 | } | ||||||||||
| 33 | 0 | $content =~ s/\t/ /g; | |||||||||
| 34 | 0 | ▶ | if ($content) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | $nbnewlines = (substr($source, 0, pos($source)) =~ tr/\n//); | |||||||||
| 36 | 0 | ▶ | if ($eos) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | ++$nbnewlines; # End of string instead of $NEWLINE_REGEXP | |||||||||
| 38 | } | ||||||||||
| 39 | } | ||||||||||
| 40 | 0 | pos($source) = $prevpos; | |||||||||
| 41 | |||||||||||
| 42 | # return "line:column $line:$col (Unicode newline count) $nbnewlines:$col (\\n count)\n\n$content\n$pointer"; | ||||||||||
| 43 | 0 | return "line:column $nbnewlines:$col\n\n$content\n$pointer"; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 3 | 1; | |||||||||
| 47 | |||||||||||
| 48 | __END__ | ||||||||||