Skip to content

Commit 6cdac49

Browse files
committed
S_parse_ident: Add flag to check for legality and not croak
When this flag is set, when an illegal identifier is found, instead of croaking the function returns NULL. This will allow future commits to use this function when all that is desired is to determine if the identifier is legal or not.
1 parent 628b1c0 commit 6cdac49

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

toke.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ static const char ident_var_zero_multi_digit[] = "Numeric variables with more th
173173
#define CHECK_DOLLAR (1 << 2)
174174
#define IDFIRST_ONLY (1 << 3)
175175
#define STOP_AT_FIRST_NON_DIGIT (1 << 4)
176+
#define CHECK_ONLY (1 << 5)
176177

177178
#ifdef DEBUGGING
178179
static const char* const lex_state_names[] = {
@@ -10339,7 +10340,13 @@ S_parse_ident(pTHX_ const char *s, const char * const send,
1033910340
* identifier ends in the input. If no identifier was found, the return
1034010341
* will be the the input 's' unchanged.
1034110342
*
10342-
* If the identifier is illegal, the function croaks.
10343+
* If the identifier is illegal, the function croaks unless this flag is
10344+
* passed in: */
10345+
const bool check_only = flags & CHECK_ONLY;
10346+
10347+
/* In this case NULL is returned instead of croaking, and the contents
10348+
* of '*d' are undefined.
10349+
*
1034310350
* The possible reasons for failure are:
1034410351
* 1) There is not enough room for the entire source identifier to be
1034510352
* copied
@@ -10408,8 +10415,12 @@ S_parse_ident(pTHX_ const char *s, const char * const send,
1040810415
} while (isDIGIT_A(*s));
1040910416

1041010417
/* Leading zeros are not permitted */
10411-
if (is_zero && *d - digit_start > 1)
10418+
if (is_zero && *d - digit_start > 1) {
10419+
if (check_only) {
10420+
return NULL;
10421+
}
1041210422
croak(ident_var_zero_multi_digit);
10423+
}
1041310424

1041410425
break;
1041510426
}
@@ -10458,6 +10469,10 @@ S_parse_ident(pTHX_ const char *s, const char * const send,
1045810469
return (char *) s;
1045910470

1046010471
too_long:
10472+
if (check_only) {
10473+
return NULL;
10474+
}
10475+
1046110476
croak("%s", ident_too_long);
1046210477
}
1046310478

0 commit comments

Comments
 (0)