aboutsummaryrefslogtreecommitdiffhomepage
path: root/c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-01-09 19:19:17 +0100
committerlemon <lsof@mailbox.org>2026-01-09 19:24:41 +0100
commit95301a8b8ece4b6d823e84bcff8a67d518840491 (patch)
tree11b0aba86ae26b5b3330a01c9d082dc92405a3b2 /c
parent0355a01d205983737d0fe1bcb1d542be6b12491e (diff)
cpp: fix pasting ident+keyword
Diffstat (limited to 'c')
-rw-r--r--c/lex.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/c/lex.c b/c/lex.c
index 8bfee38..d072464 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -281,6 +281,7 @@ readstrchrlit(struct lexer *lx, struct token *tk, char delim, int wide)
span.sl.len = lx->chridx - span.sl.off;
error(&span, "hex escape sequence out of range");
}
+ c = n;
break;
default:
if (aisodigit(c)) { /* octal */
@@ -749,6 +750,8 @@ ppskipline(struct lexer *lx)
}
}
+#define isppident(tk) in_range((tk).t, TKIDENT, TKWEND_)
+
static bool
tokpaste(struct lexer *lx, struct token *dst, const struct token *l, const struct token *r)
{
@@ -756,10 +759,10 @@ tokpaste(struct lexer *lx, struct token *dst, const struct token *l, const struc
dst->span = l->span;
if (dst->span.ex.file == r->span.ex.file && dst->span.ex.off < r->span.ex.off)
joinspan(&dst->span.ex, r->span.ex);
- if (l->t == TKIDENT && (r->t == TKIDENT || r->t == TKNUMLIT)) {
+ if (isppident(*l) && (isppident(*r) || r->t == TKNUMLIT)) {
/* foo ## bar ; foo ## 123 */
dst->t = TKIDENT;
- } else if (l->t == TKNUMLIT && (r->t == TKIDENT || r->t == TKNUMLIT)) {
+ } else if (l->t == TKNUMLIT && (isppident(*r) || r->t == TKNUMLIT)) {
/* 0x ## abc ; 213 ## 456 */
dst->t = TKNUMLIT;
} else if (l->t && !r->t) {
@@ -790,11 +793,11 @@ tokpaste(struct lexer *lx, struct token *dst, const struct token *l, const struc
char buf[200];
dst->len = l->len + r->len;
- char *s = (dst->t == TKIDENT && dst->len + 1 < sizeof buf) ? buf : alloc(lx->tmparena, dst->len + 1, 1);
+ char *s = (isppident(*dst) && dst->len + 1 < sizeof buf) ? buf : alloc(lx->tmparena, dst->len + 1, 1);
memcpy(s, l->s, l->len);
memcpy(s + l->len, r->s, r->len);
s[dst->len] = 0;
- if (dst->t == TKIDENT) {
+ if (isppident(*dst)) {
dst->blue = 0;
dst->name = intern(s);
} else {