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

Incorrect line numbers reported when errors are emitted #77

Closed
yash-nisar opened this issue Jul 12, 2018 · 1 comment · Fixed by #78
Closed

Incorrect line numbers reported when errors are emitted #77

yash-nisar opened this issue Jul 12, 2018 · 1 comment · Fixed by #78

Comments

@yash-nisar
Copy link
Contributor

Steps to reproduce:

  1. Edit line FileCopyrightText: Copyright 2014 Acme Inc in SPDXSimpleTag.tag
  2. Navigate to the examples directory.
  3. Run the command python parse_tv.py '../data/SPDXSimpleTag.tag'
  4. Get output as :
Generating LALR tables
FileCopyrightText must be one of NOASSERTION, NONE or free form text, line: 34
Errors encountered while parsing

@yash-nisar
Copy link
Contributor Author

I've figured out the cause of the bug.

This occurs due to the method t_text_end in lexers\tagvalue.py. The method body is:

def t_text_end(self, t):
        r'</text>\s*'
        t.type = 'TEXT'
        t.value = t.lexer.lexdata[
            t.lexer.text_start:t.lexer.lexpos].strip()
        t.lexer.lineno += t.value.count('\n')
        t.lexer.begin('INITIAL')
        return t

The line t.value.count('\n') doesn't detect newlines because the earlier line is stripped of whitespaces and newlines.

yash-nisar added a commit to yash-nisar/tools-python that referenced this issue Jul 13, 2018
This occurs due to the method `t_text_end` in the
file `lexers\tagvalue.py`. The line `t.value.count('\n')`
doesn't detect newlines because the earlier line is stripped
of whitespaces and newlines. This issue is resolved by first
counting the no. of newline chars and then stripping
whitespaces and newlines so information is preserved.

Signed-off-by: Yash Nisar <yash.nisar@somaiya.edu>
pombredanne added a commit that referenced this issue Aug 6, 2018
Report correct line no.s while showing errors #77 

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
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

Successfully merging a pull request may close this issue.

1 participant