New feature: improve diagnostics for parse errors
mikkorantalainen opened this issue · comments
In case of parse errors the Parser::parse() will throw Exception
or UnexpectedTokenException
depending on error type.
However, this is not enough to create meaningful diagnostics about the problem. For example a CSS document such as this
@foo (something=another))
{
bar { zoo: 1; }
}
will cause parse()
to throw \Exception
with a message Unopened {
where the real problem is an extra closing parenthesis before first '{'.
In best case, there would be much more exception classes for each specific parse error, but I think even adding a simple public method to Parser.php would improve things a lot:
/**
* @return int byte offset for current parser position
* In case the parse() throws an exception, this method can be
* used to approximate the error location.
*/
public function getPosition()
{
return $this->iCurrentPosition;
}