Skip to content

Commit e4be402

Browse files
committed
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.
1 parent 4349cf9 commit e4be402

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

embed.fnc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6179,9 +6179,8 @@ So |SV * |new_constant |NULLOK const char *s \
61796179
S |void |parse_ident |NN char **s \
61806180
|SPTR char **d \
61816181
|EPTR char * const e \
6182-
|int allow_package \
61836182
|bool is_utf8 \
6184-
|bool check_dollar
6183+
|U32 flags
61856184
S |int |pending_ident
61866185
RS |char * |scan_const |NN char *start
61876186
RS |char * |scan_formline |NN char *s

embed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@
16881688
# define is_existing_identifier(a,b,c,d) S_is_existing_identifier(aTHX_ a,b,c,d)
16891689
# define lop(a,b,c,d) S_lop(aTHX_ a,b,c,d)
16901690
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
1691-
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)
1691+
# define parse_ident(a,b,c,d,e) S_parse_ident(aTHX_ a,b,c,d,e)
16921692
# define pending_ident() S_pending_ident(aTHX)
16931693
# define scan_const(a) S_scan_const(aTHX_ a)
16941694
# define scan_formline(a) S_scan_formline(aTHX_ a)

proto.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

toke.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static const char ident_var_zero_multi_digit[] = "Numeric variables with more th
176176
/* Bits in the flags parameter of various functions */
177177
#define CHECK_KEYWORD (1 << 0)
178178
#define ALLOW_PACKAGE (1 << 1)
179+
#define CHECK_DOLLAR (1 << 2)
179180

180181
#ifdef DEBUGGING
181182
static const char* const lex_state_names[] = {
@@ -5503,8 +5504,7 @@ yyl_sigvar(pTHX_ char *s)
55035504
char *dest = PL_tokenbuf + 1;
55045505
/* read var name, including sigil, into PL_tokenbuf */
55055506
PL_tokenbuf[0] = sigil;
5506-
parse_ident(&s, &dest, C_ARRAY_END(PL_tokenbuf),
5507-
0, cBOOL(UTF), FALSE);
5507+
parse_ident(&s, &dest, C_ARRAY_END(PL_tokenbuf), cBOOL(UTF), 0);
55085508
*dest = '\0';
55095509
assert(PL_tokenbuf[1]); /* we have a variable name */
55105510
}
@@ -10538,8 +10538,8 @@ S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
1053810538
}
1053910539

1054010540
STATIC void
10541-
S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package,
10542-
bool is_utf8, bool check_dollar)
10541+
S_parse_ident(pTHX_ char **s, char **d, char * const e, bool is_utf8,
10542+
U32 flags)
1054310543
{
1054410544
PERL_ARGS_ASSERT_PARSE_IDENT;
1054510545
assert(*s <= PL_bufend);
@@ -10565,10 +10565,12 @@ S_parse_ident(pTHX_ char **s, char **d, char * const e, int allow_package,
1056510565
* variable path. Each iteration of the loop below picks up one segment
1056610566
* of the path. If the apostrophe is allowed as a package separator, it
1056710567
* is converted to "::", so later code doesn't have to concern itself with
10568-
* this possibility.
10569-
*
10570-
* 'check_dollar' is used to look for and stop parsing before the dollar
10568+
* this possibility. */
10569+
const bool allow_package = flags & ALLOW_PACKAGE;
10570+
10571+
/* 'check_dollar' is used to look for and stop parsing before the dollar
1057110572
* in things like Foo::$bar */
10573+
const bool check_dollar = flags & CHECK_DOLLAR;
1057210574

1057310575
while (*s < PL_bufend) {
1057410576
if (*d >= e)
@@ -10642,7 +10644,8 @@ Perl_scan_word(pTHX_ char *s, char *dest, STRLEN destlen, int allow_package, STR
1064210644
char * const e = d + destlen - 3; /* two-character token, ending NUL */
1064310645
bool is_utf8 = cBOOL(UTF);
1064410646

10645-
parse_ident(&s, &d, e, allow_package, is_utf8, TRUE);
10647+
parse_ident(&s, &d, e, is_utf8,
10648+
(CHECK_DOLLAR | ((allow_package) ? ALLOW_PACKAGE : 0)));
1064610649
*d = '\0';
1064710650
*slp = d - dest;
1064810651
return s;
@@ -10683,7 +10686,7 @@ S_scan_ident(pTHX_ char *s, char *dest, char *dest_end, bool chk_unary)
1068310686
croak(ident_var_zero_multi_digit);
1068410687
}
1068510688
else { /* See if it is a "normal" identifier */
10686-
parse_ident(&s, &d, e, 1, is_utf8, FALSE);
10689+
parse_ident(&s, &d, e, is_utf8, ALLOW_PACKAGE);
1068710690
}
1068810691
*d = '\0';
1068910692
d = dest;
@@ -10804,7 +10807,8 @@ S_scan_ident(pTHX_ char *s, char *dest, char *dest_end, bool chk_unary)
1080410807
(the later check for } being at the expected point will trap
1080510808
cases where this doesn't pan out.) */
1080610809
d += advance;
10807-
parse_ident(&s, &d, e, 1, is_utf8, TRUE);
10810+
parse_ident(&s, &d, e, is_utf8, ( ALLOW_PACKAGE
10811+
|CHECK_DOLLAR));
1080810812
*d = '\0';
1080910813
}
1081010814
else { /* caret word: ${^Foo} ${^CAPTURE[0]} */

0 commit comments

Comments
 (0)