aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--c/lex.c18
-rw-r--r--test/07-pp.c2
-rw-r--r--test/07-pp.h3
3 files changed, 19 insertions, 4 deletions
diff --git a/c/lex.c b/c/lex.c
index e2d86c6..02e9f3d 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -722,8 +722,22 @@ static void
ppskipline(struct lexer *lx)
{
while (lx->macstk) popmac(lx);
- while (peek(lx, 0) != '\n' && !lx->eof)
- next(lx);
+ for (int c; (c = peek(lx, 0)) != '\n' && !lx->eof; next(lx)) {
+ if (c == '/' && peek(lx, 1) == '*') { /* comment */
+ next(lx), next(lx);
+ bool done = 0;
+ while (!((c = peek(lx, 0)) == '*' && peek(lx, 1) == '/')) {
+ if (lx->eof) {
+ struct span span = {{ lx->idx, lx->chridx - lx->idx, lx->fileid }};
+ fatal(&span, "unterminated comment");
+ }
+ done = c == '\n';
+ next(lx);
+ }
+ next(lx);
+ if (done) return;
+ }
+ }
}
static bool
diff --git a/test/07-pp.c b/test/07-pp.c
index 47b9dbb..071b359 100644
--- a/test/07-pp.c
+++ b/test/07-pp.c
@@ -37,7 +37,7 @@ s
#ifdef CMD_WORKING
int
main(V)
-#endif
+#endif // comment
{
int CATl(foo);
++foobar;
diff --git a/test/07-pp.h b/test/07-pp.h
index 63de6f5..c0725b5 100644
--- a/test/07-pp.h
+++ b/test/07-pp.h
@@ -9,7 +9,8 @@ void hi(int x) {
}
#if 1
#endif
-#elifndef Ww
+#elifndef Ww /*
+ t'e */
#define Bar 7
#define SQR_(x) ((x)*(x))
#define SQR(y) SQR_(1+(y)-1)