Skip to content

Commit eea4938

Browse files
committed
Fix leafo#698 add source column to thrown error message
1 parent ce644ca commit eea4938

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Compiler.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,14 +4147,17 @@ public function throwError($msg)
41474147
return;
41484148
}
41494149

4150+
$line = $this->sourceLine;
4151+
$column = $this->sourceColumn;
4152+
4153+
$loc = isset($this->sourceNames[$this->sourceIndex])
4154+
? $this->sourceNames[$this->sourceIndex] . " on line $line, at column $column"
4155+
: "line: $line, column: $column";
4156+
41504157
if (func_num_args() > 1) {
41514158
$msg = call_user_func_array('sprintf', func_get_args());
41524159
}
41534160

4154-
$line = $this->sourceLine;
4155-
$loc = isset($this->sourceNames[$this->sourceIndex])
4156-
? $this->sourceNames[$this->sourceIndex] . " on line $line"
4157-
: "line: $line";
41584161
$msg = "$msg: $loc";
41594162

41604163
$callStackMsg = $this->callStackMessage();

src/Parser.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ public function getSourceName()
130130
*/
131131
public function throwParseError($msg = 'parse error')
132132
{
133-
list($line, /* $column */) = $this->getSourcePosition($this->count);
133+
list($line, $column) = $this->getSourcePosition($this->count);
134134

135-
$loc = empty($this->sourceName) ? "line: $line" : "$this->sourceName on line $line";
135+
$loc = empty($this->sourceName)
136+
? "line: $line, column: $column"
137+
: "$this->sourceName on line $line, at column $column";
136138

137139
if ($this->peek("(.*?)(\n|$)", $m, $this->count)) {
138140
throw new ParserException("$msg: failed at `$m[1]` $loc");

0 commit comments

Comments
 (0)