Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: improve diagnostics for parse errors #78

Open
mikkorantalainen opened this issue Jul 3, 2014 · 0 comments
Open

New feature: improve diagnostics for parse errors #78

mikkorantalainen opened this issue Jul 3, 2014 · 0 comments
Labels

Comments

@mikkorantalainen
Copy link

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;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants