nctype: add nasm_isquote()

Add nasm_isquote() to test for a NASM quoted string.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2018-11-28 15:01:40 -08:00
parent 1350620bf1
commit 53e2e4c099
3 changed files with 31 additions and 23 deletions

View File

@ -958,7 +958,7 @@ static Token *tokenize(char *line)
p++;
}
while (nasm_isidchar(*p));
} else if (*p == '\'' || *p == '\"' || *p == '`') {
} else if (nasm_isquote(*p)) {
p = nasm_skip_string(p);
if (*p)
p++;
@ -986,7 +986,7 @@ static Token *tokenize(char *line)
p++;
while (*p && nasm_isidchar(*p))
p++;
} else if (*p == '\'' || *p == '"' || *p == '`') {
} else if (nasm_isquote(*p)) {
/*
* A string token.
*/
@ -1239,7 +1239,7 @@ static char *detoken(Token * tlist, bool expand_locals)
char *q = t->text;
v = t->text + 2;
if (*v == '\'' || *v == '\"' || *v == '`') {
if (nasm_isquote(*v)) {
size_t len = nasm_unquote(v, NULL);
size_t clen = strlen(v);
@ -1787,7 +1787,7 @@ static bool if_condition(Token * tline, enum preproc_token ct)
p = tline->text;
if (tline->type == TOK_PREPROC_ID)
p += 2; /* Skip leading %! */
if (*p == '\'' || *p == '\"' || *p == '`')
if (nasm_isquote(*p))
nasm_unquote_cstr(p, ct);
if (getenv(p))
j = true;

View File

@ -51,18 +51,19 @@ static inline char nasm_tolower(char x)
* NASM ctype table
*/
enum nasm_ctype {
NCT_CTRL = 0x001,
NCT_SPACE = 0x002,
NCT_ASCII = 0x004,
NCT_LOWER = 0x008, /* isalpha(x) && tolower(x) == x */
NCT_UPPER = 0x010, /* isalpha(x) && tolower(x) != x */
NCT_DIGIT = 0x020,
NCT_HEX = 0x040,
NCT_ID = 0x080,
NCT_IDSTART = 0x100,
NCT_MINUS = 0x200, /* - */
NCT_DOLLAR = 0x400, /* $ */
NCT_UNDER = 0x800 /* _ */
NCT_CTRL = 0x0001,
NCT_SPACE = 0x0002,
NCT_ASCII = 0x0004,
NCT_LOWER = 0x0008, /* isalpha(x) && tolower(x) == x */
NCT_UPPER = 0x0010, /* isalpha(x) && tolower(x) != x */
NCT_DIGIT = 0x0020,
NCT_HEX = 0x0040,
NCT_ID = 0x0080,
NCT_IDSTART = 0x0100,
NCT_MINUS = 0x0200, /* - */
NCT_DOLLAR = 0x0400, /* $ */
NCT_UNDER = 0x0800, /* _ */
NCT_QUOTE = 0x1000 /* " ' ` */
};
extern uint16_t nasm_ctype_tab[256];
@ -113,6 +114,10 @@ static inline bool nasm_isnumchar(char x)
{
return nasm_ctype(x, NCT_DIGIT|NCT_LOWER|NCT_UPPER|NCT_UNDER);
}
static inline bool nasm_isquote(char x)
{
return nasm_ctype(x, NCT_QUOTE);
}
/* TASM-compatible mode requires ? to be an identifier character */
static inline void nasm_ctype_tasm_mode(void)

View File

@ -96,13 +96,16 @@ static void ctype_tab_init(void)
nasm_ctype_tab[i] = ct;
}
nasm_ctype_tab['-'] |= NCT_MINUS;
nasm_ctype_tab['$'] |= NCT_DOLLAR|NCT_ID;
nasm_ctype_tab['_'] |= NCT_UNDER|NCT_ID|NCT_IDSTART;
nasm_ctype_tab['.'] |= NCT_ID|NCT_IDSTART;
nasm_ctype_tab['@'] |= NCT_ID|NCT_IDSTART;
nasm_ctype_tab['#'] |= NCT_ID;
nasm_ctype_tab['~'] |= NCT_ID;
nasm_ctype_tab['-'] |= NCT_MINUS;
nasm_ctype_tab['$'] |= NCT_DOLLAR|NCT_ID;
nasm_ctype_tab['_'] |= NCT_UNDER|NCT_ID|NCT_IDSTART;
nasm_ctype_tab['.'] |= NCT_ID|NCT_IDSTART;
nasm_ctype_tab['@'] |= NCT_ID|NCT_IDSTART;
nasm_ctype_tab['#'] |= NCT_ID;
nasm_ctype_tab['~'] |= NCT_ID;
nasm_ctype_tab['\''] |= NCT_QUOTE;
nasm_ctype_tab['\"'] |= NCT_QUOTE;
nasm_ctype_tab['`'] |= NCT_QUOTE;
}
void nasm_ctype_init(void)