ply yacc lineno not working?

inhahe inhahe at gmail.com
Fri May 16 10:15:36 EDT 2008


I dunno but on Dos/Windows a newline is usually \r\n (although that still 
includes a \n..)

"Laszlo Nagy" <gandalf at shopzeus.com> wrote in message 
news:mailman.1220.1210938144.12834.python-list at python.org...
> I'm sorry for the dumb question. I had to add these to the lexer:
>
> def t_comment(t):
>    r"\#[^\n]*\n"
>    t.lexer.lineno += 1
>    # We do not return anything - comments are ignored.
>
> # Define a rule so we can track line numbers
> def t_newline(t):
>    r'\n+'
>    t.lexer.lineno += len(t.value)
>
>
> Well, it is not very straightforward. From the docs, it was not clear that 
> I HAVE TO increment t.lexer.lineno in my lexer if you want yacc to parse 
> line numbers. But it is logical. I believe this could be done 
> automatically, since "line number" ALWAYS means "\n", there is nothing to 
> be configured here. (Am I wrong? There can be parsers to parse files where 
> new lines are chr(255) or something?)
>
> Thanks,
>
>   Laszlo
> 





More information about the Python-list mailing list