eliben / pycparser

:snake: Complete C99 parser in pure Python
Other
3.21k stars 611 forks source link

Parsing '//' comments #464

Closed juanfgarcia closed 2 years ago

juanfgarcia commented 2 years ago

I'm getting an error when parsing '//' style comments and not with '/.../' style

I've been searching and I've found in pycparser/ply/ctokens.py

# Comment (C-Style)
def t_COMMENT(t):
    r'/\*(.|\n)*?\*/'
    t.lexer.lineno += t.value.count('\n')
    return t

# Comment (C++-Style)
def t_CPPCOMMENT(t):
    r'//.*\n'
    t.lexer.lineno += 1
    return t

But changing t_COMMENT(t) to the // style doesn't work.

Is there any option to compile with the C++ style? If not, do I need to run yacc or other tool to make it work?

eliben commented 2 years ago

The preprocessor is supposed to remove all comments. If you use a preprocessor that supports C++ style comments, this should work because pycparser itself is not aware of comments.

eliben commented 2 years ago

https://github.com/eliben/pycparser#31interaction-with-the-c-preprocessor