Skip to content

Commit f915e6a

Browse files
Explicit error for comments, with user hint
1 parent 2215299 commit f915e6a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pycparser/c_lexer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ def _make_tok_location(self, token):
209209

210210
bad_octal_constant = '0[0-7]*[89]'
211211

212+
# comments are not supported
213+
unsupported_c89_comment = r'\/\/'
214+
unsupported_c99_comment = r'\/\*'
215+
212216
# character constants (K&R2: A.2.5.2)
213217
# Note: a-zA-Z and '.-~^_!=&;,' are allowed as escape chars to support #line
214218
# directives with Windows paths as filenames (..\..\dir\file)
@@ -475,6 +479,16 @@ def t_BAD_CONST_OCT(self, t):
475479
msg = "Invalid octal constant"
476480
self._error(msg, t)
477481

482+
@TOKEN(unsupported_c89_comment)
483+
def t_UNSUPPORTED_C89_COMMENT(self, t):
484+
msg = "Comments are not supported (note: GCC's cpp removes comments, Clang's cpp does not)."
485+
self._error(msg, t)
486+
487+
@TOKEN(unsupported_c99_comment)
488+
def t_UNSUPPORTED_C99_COMMENT(self, t):
489+
msg = "Comments are not supported (note: GCC's cpp removes comments, Clang's cpp does not)."
490+
self._error(msg, t)
491+
478492
@TOKEN(octal_constant)
479493
def t_INT_CONST_OCT(self, t):
480494
return t

0 commit comments

Comments
 (0)