Fixing minor bugs in parser error line reporter
Publish PHP Package / docker (push) Failing after 3s
Details
Publish PHP Package / docker (push) Failing after 3s
Details
This commit is contained in:
parent
4d080bacd8
commit
1a24065c72
|
@ -11,16 +11,17 @@ function jzon_show_position(int $p, string $in, int $context_lines = 5) : string
|
||||||
$out = array();
|
$out = array();
|
||||||
$lines = explode("\n", $in);
|
$lines = explode("\n", $in);
|
||||||
//let's find out the maximum leading zeros for line numbers
|
//let's find out the maximum leading zeros for line numbers
|
||||||
$fmt_num = (int)round(log10(count($lines)));
|
$fmt_num = (int)round(log10(count($lines)))+1;
|
||||||
foreach($lines as $line_idx => $line)
|
foreach($lines as $line_idx => $line)
|
||||||
{
|
{
|
||||||
//adding line numbers and handling tabs
|
//adding line numbers and normalizing tabs by converting them to spaces
|
||||||
$out[] = sprintf('%0'.$fmt_num.'d', $line_idx) . ' ' . str_replace("\t", " ", $line);
|
$out[] = sprintf('%0'.$fmt_num.'d', ($line_idx+1)) . ' ' . str_replace("\t", " ", $line);
|
||||||
$left = $p - (strlen($line) + 1/*taking into account \n*/);
|
$left = $p - (strlen($line) + 1/*taking into account \n*/);
|
||||||
//var_dump($left, $p, $line, $fmt_num);
|
//var_dump($left, $p, $line, $fmt_num);
|
||||||
if($left < 0)
|
if($left <= 0)
|
||||||
{
|
{
|
||||||
$arrow = str_repeat('-', $fmt_num) . '-'; //line numbers
|
$arrow = str_repeat('-', $fmt_num) . '-'; //line numbers
|
||||||
|
//let's normalize tabs
|
||||||
for($i=0;$i<$p;++$i)
|
for($i=0;$i<$p;++$i)
|
||||||
$arrow .= ($line[$i] === "\t" ? '----' : '-');
|
$arrow .= ($line[$i] === "\t" ? '----' : '-');
|
||||||
$arrow .= '^';
|
$arrow .= '^';
|
||||||
|
|
Loading…
Reference in New Issue