build: omit named test source operands
This commit is contained in:
@@ -358,6 +358,78 @@ skipws(Lex *l)
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the next initial import token without ever lexing the first ordinary
|
||||
* declaration token. Go's named-file reader consumes header trivia while
|
||||
* looking for another import, so NUL/comment diagnostics in that trivia remain
|
||||
* visible; a malformed UTF-8 byte or non-leading BOM that itself begins the
|
||||
* ordinary body is outside the header and must not be diagnosed here. */
|
||||
int
|
||||
lexheaderimport(Lex *l, Tok *out)
|
||||
{
|
||||
for (;;) {
|
||||
if (l->pos >= l->srclen)
|
||||
return 0;
|
||||
unsigned char c = (unsigned char)l->src[l->pos];
|
||||
if (c == 0) {
|
||||
/* The loader necessarily reaches this byte while deciding whether
|
||||
* another import follows. Preserve the source decoder diagnostic. */
|
||||
lskipnul(l);
|
||||
return 0;
|
||||
}
|
||||
if ((c >= 0x80 && !utf8bytevalid(l->src, l->srclen, l->pos))
|
||||
|| bomat(l->src, l->srclen, l->pos))
|
||||
return 0;
|
||||
if (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
|
||||
lget(l);
|
||||
continue;
|
||||
}
|
||||
if (c == '/' && l->pos + 1 < l->srclen
|
||||
&& l->src[l->pos + 1] == '/') {
|
||||
lget(l); lget(l);
|
||||
linecomment(l);
|
||||
if (l->errs != 0)
|
||||
return 0;
|
||||
continue;
|
||||
}
|
||||
if (c == '/' && l->pos + 1 < l->srclen
|
||||
&& l->src[l->pos + 1] == '*') {
|
||||
lget(l); lget(l);
|
||||
int prev = -1;
|
||||
for (;;) {
|
||||
int x = lget(l);
|
||||
if (x < 0) {
|
||||
Pos p = lpos(l);
|
||||
errorf(p, "unterminated /* comment");
|
||||
l->errs++;
|
||||
return 0;
|
||||
}
|
||||
if (prev == '*' && x == '/')
|
||||
break;
|
||||
prev = x;
|
||||
}
|
||||
if (l->errs != 0)
|
||||
return 0;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* A compiler-owned source-boundary directive is an ordinary declaration
|
||||
* boundary here, just as it was when lexnext eagerly exposed the token. */
|
||||
if (l->modreset || l->modpath != NULL)
|
||||
return 0;
|
||||
static const char kw[] = "import";
|
||||
const u64 n = sizeof kw - 1;
|
||||
if (l->srclen - l->pos < n
|
||||
|| memcmp(l->src + l->pos, kw, n) != 0)
|
||||
return 0;
|
||||
if (l->srclen - l->pos > n
|
||||
&& isidcont((unsigned char)l->src[l->pos + n]))
|
||||
return 0;
|
||||
*out = lexnext(l);
|
||||
return out->kind == TK_USE;
|
||||
}
|
||||
|
||||
static u64
|
||||
parseint(const char *s, u64 n, int base, int *ok)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user