toke.c: Use flags parameter to S_parse_ident

This makes it clearer at each call point what is happening, and prepares
for future commits where more flags will be passed to this function.
This commit is contained in:
Karl Williamson 2025-10-08 05:58:33 -06:00
parent 4349cf9cd0
commit e4be402477
4 changed files with 17 additions and 14 deletions

View File

@ -6179,9 +6179,8 @@ So |SV * |new_constant |NULLOK const char *s \
S |void |parse_ident |NN char **s \
|SPTR char **d \
|EPTR char * const e \
|int allow_package \
|bool is_utf8 \
|bool check_dollar
|U32 flags
S |int |pending_ident
RS |char * |scan_const |NN char *start
RS |char * |scan_formline |NN char *s

View File

@ -1688,7 +1688,7 @@
# define is_existing_identifier(a,b,c,d) S_is_existing_identifier(aTHX_ a,b,c,d)
# define lop(a,b,c,d) S_lop(aTHX_ a,b,c,d)
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)
# define parse_ident(a,b,c,d,e) S_parse_ident(aTHX_ a,b,c,d,e)
# define pending_ident() S_pending_ident(aTHX)
# define scan_const(a) S_scan_const(aTHX_ a)
# define scan_formline(a) S_scan_formline(aTHX_ a)

2
proto.h generated
View File

@ -9467,7 +9467,7 @@ S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
assert(key); assert(sv)
STATIC void
S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package, bool is_utf8, bool check_dollar);
S_parse_ident(pTHX_ char **s, char **d, char * const e, bool is_utf8, U32 flags);
# define PERL_ARGS_ASSERT_PARSE_IDENT \
assert(s); assert(d); assert(*d); assert(e); assert(*d < e)

24
toke.c
View File

@ -176,6 +176,7 @@ static const char ident_var_zero_multi_digit[] = "Numeric variables with more th
/* Bits in the flags parameter of various functions */
#define CHECK_KEYWORD (1 << 0)
#define ALLOW_PACKAGE (1 << 1)
#define CHECK_DOLLAR (1 << 2)
#ifdef DEBUGGING
static const char* const lex_state_names[] = {
@ -5503,8 +5504,7 @@ yyl_sigvar(pTHX_ char *s)
char *dest = PL_tokenbuf + 1;
/* read var name, including sigil, into PL_tokenbuf */
PL_tokenbuf[0] = sigil;
parse_ident(&s, &dest, C_ARRAY_END(PL_tokenbuf),
0, cBOOL(UTF), FALSE);
parse_ident(&s, &dest, C_ARRAY_END(PL_tokenbuf), cBOOL(UTF), 0);
*dest = '\0';
assert(PL_tokenbuf[1]); /* we have a variable name */
}
@ -10538,8 +10538,8 @@ S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
}
STATIC void
S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package,
bool is_utf8, bool check_dollar)
S_parse_ident(pTHX_ char **s, char **d, char * const e, bool is_utf8,
U32 flags)
{
PERL_ARGS_ASSERT_PARSE_IDENT;
assert(*s <= PL_bufend);
@ -10565,10 +10565,12 @@ S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package,
* variable path. Each iteration of the loop below picks up one segment
* of the path. If the apostrophe is allowed as a package separator, it
* is converted to "::", so later code doesn't have to concern itself with
* this possibility.
*
* 'check_dollar' is used to look for and stop parsing before the dollar
* this possibility. */
const bool allow_package = flags & ALLOW_PACKAGE;
/* 'check_dollar' is used to look for and stop parsing before the dollar
* in things like Foo::$bar */
const bool check_dollar = flags & CHECK_DOLLAR;
while (*s < PL_bufend) {
if (*d >= e)
@ -10642,7 +10644,8 @@ Perl_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STR
char * const e = d + destlen - 3; /* two-character token, ending NUL */
bool is_utf8 = cBOOL(UTF);
parse_ident(&s, &d, e, allow_package, is_utf8, TRUE);
parse_ident(&s, &d, e, is_utf8,
(CHECK_DOLLAR | ((allow_package) ? ALLOW_PACKAGE : 0)));
*d = '\0';
*slp = d - dest;
return s;
@ -10683,7 +10686,7 @@ S_scan_ident(pTHX_ char *s, char *dest, char *dest_end, bool chk_unary)
croak(ident_var_zero_multi_digit);
}
else { /* See if it is a "normal" identifier */
parse_ident(&s, &d, e, 1, is_utf8, FALSE);
parse_ident(&s, &d, e, is_utf8, ALLOW_PACKAGE);
}
*d = '\0';
d = dest;
@ -10804,7 +10807,8 @@ S_scan_ident(pTHX_ char *s, char *dest, char *dest_end, bool chk_unary)
(the later check for } being at the expected point will trap
cases where this doesn't pan out.) */
d += advance;
parse_ident(&s, &d, e, 1, is_utf8, TRUE);
parse_ident(&s, &d, e, is_utf8, ( ALLOW_PACKAGE
|CHECK_DOLLAR));
*d = '\0';
}
else { /* caret word: ${^Foo} ${^CAPTURE[0]} */