cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit d77cb90330efd684416cd8b85b95f74bce253716
parent 9c824820b0add0bd840fb559fa4e98afea65986b
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 12 Mar 2019 17:58:54 -0700

scan: Add support for prefixed string literals and character constants

Diffstat:
Mexpr.c | 10++++++++--
Mscan.c | 24+++++++++++++++++++++---
2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/expr.c b/expr.c @@ -342,7 +342,10 @@ primaryexpr(struct scope *s) do { e->string.data = xreallocarray(e->string.data, e->string.size + strlen(tok.lit), 1); dst = e->string.data + e->string.size; - for (src = tok.lit + 1; *src != '"'; ++dst) + src = tok.lit; + if (*src != '"') + fatal("wide string literal not yet implemented"); + for (++src; *src != '"'; ++dst) *dst = unescape(&src); e->string.size = dst - e->string.data; next(); @@ -352,7 +355,10 @@ primaryexpr(struct scope *s) e = decay(e); break; case TCHARCONST: - src = tok.lit + 1; + src = tok.lit; + if (*src != '\'') + fatal("wide character constant not yet implemented"); + ++src; e = mkconstexpr(&typeint, unescape(&src)); if (*src != '\'') error(&tok.loc, "character constant contains more than one character: %c", *src); diff --git a/scan.c b/scan.c @@ -122,8 +122,8 @@ static int ident(struct scanner *s) { s->usebuf = true; - do nextchar(s); - while (isalnum(s->chr) || s->chr == '_'); + while (isalnum(s->chr) || s->chr == '_') + nextchar(s); return TIDENT; } @@ -285,7 +285,6 @@ again: return op2(s, TMOD, TMODASSIGN); case '&': return op3(s, TBAND, TBANDASSIGN, TLAND); - // TODO: u8, U, and L string literals case '\'': return charconst(s); case '*': @@ -367,6 +366,25 @@ again: case ',': nextchar(s); return TCOMMA; + case 'L': + case 'U': + case 'u': + s->usebuf = true; + nextchar(s); + switch (s->chr) { + case '\'': + return charconst(s); + case '8': + if (s->buf.str[0] != 'u') + break; + nextchar(s); + if (s->chr != '"') + break; + /* fallthrough */ + case '"': + return stringlit(s); + } + return ident(s); case EOF: return TEOF; default: