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

Wrong column and line numbers in error message. #163

Closed
jairodemorais opened this issue Feb 27, 2013 · 7 comments
Closed

Wrong column and line numbers in error message. #163

jairodemorais opened this issue Feb 27, 2013 · 7 comments

Comments

@jairodemorais
Copy link

Hi @dmajda ,
we are using pegjs in Linkedin dustjs project, it is a really nice tool to generate parsers but now I am having a little issue with the error message.
Maybe I have written the pegjs rule wrong.
Let me try to explain my problem.

In the following example I would expect that the parser says that the error is in line 4, column 4 but it say line 1, column1.

I understand why pegs say that, the first tag is not a valid tag because it has a tag with an invalid tag inside.
But it is not intuitive for the users who writes our templates, because they think that the error is in line one but that is not correct, the error is in line 4.

this is the example:

{tag}     
  {tag}   
    {tag}     
       body1    
    {/tag}    
  {/tag} 
start
  = section

section "section"
  = "{tag}" ws* body ws* "{/tag}" 

body
  = "body1"
  / s:section {return s}

ws
  = [\t\v\f \u00A0\uFEFF] / eol

eol 
  = "\n"        //line feed
  / "\r\n"      //carriage + line feed
  / "\r"        //carriage return
  / "\u2028"    //line separator
  / "\u2029"    //paragraph separator

Thanks, JAiro

@otac0n
Copy link

otac0n commented Feb 27, 2013

You can define your section rule similar to this (untested):

section = "{tag}" blah ( "{/tag}" / { throw "unterminated tag"; } )

@jairodemorais
Copy link
Author

thanks @otac0n for your answer, but I think that it doesn't work. I tested it with the pegjs online tool. this is the screenshot.
Screen Shot 2013-02-27 at 7 18 06 PM

@otac0n
Copy link

otac0n commented Feb 28, 2013

Bummer. Well, then this should probably be a bug. The original PEG paper indicated that errors should be defined inline. PEG.js does a good job of adding default error messages, but we should allow exceptions to indicate error positions as well.

@vybs
Copy link

vybs commented Mar 19, 2013

@otac0n hello, is there going to be a fix on this soon?

@otac0n
Copy link

otac0n commented Mar 19, 2013

It appears that you can do throw new Error("foo").

@vybs
Copy link

vybs commented Mar 19, 2013

ah, so this is the recommended solution.

@dmajda
Copy link
Contributor

dmajda commented Aug 17, 2013

I am closing this issue because the behavior of PEG.js is technically correct (as suggested in the original report already).

@jairodemorais @vybs As for improving the error handling, please see #198. I welcome your input into the discussion.

@dmajda dmajda closed this as completed Aug 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants