Skip to content

Commit 2c42ac5

Browse files
committed
S_parse_ident: Add ability to start parse in middle
S_scan_ident would like to call this function, already having looked at the first character of an identifier, and deciding it is legal. It wants this function to finish the scan. This commit adds a flag to S_parse_ident to accommodate this.
1 parent a940e99 commit 2c42ac5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

toke.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ static const char ident_var_zero_multi_digit[] = "Numeric variables with more th
181181
#define STOP_AT_FIRST_NON_DIGIT (1 << 4)
182182
#define CHECK_ONLY (1 << 5)
183183
#define CHECK_UNARY (1 << 6)
184+
#define IDCONT_first_OK (1 << 7)
184185

185186
#ifdef DEBUGGING
186187
static const char* const lex_state_names[] = {
@@ -10597,6 +10598,11 @@ S_parse_ident(pTHX_ const char *s, const char * const s_end,
1059710598
* in things like Foo::$bar */
1059810599
const bool check_dollar = flags & CHECK_DOLLAR;
1059910600

10601+
/* There is a use case for calling this function in the middle of having
10602+
* parsed a portion of an identifier. Therefore it should be able to
10603+
* accept the first character being an IDCont, and not necessarily an
10604+
* IDFIRST. The 'IDCONT_first_OK' flag is used to indicate this */
10605+
1060010606
while (s < s_end) {
1060110607

1060210608
/* For non-UTF8, variables that match ASCII \w are a superset of
@@ -10605,7 +10611,10 @@ S_parse_ident(pTHX_ const char *s, const char * const s_end,
1060510611
* for the subset before checking for the superset. */
1060610612
Size_t advance;
1060710613
if ( (is_utf8 || idfirst_only)
10608-
&& (advance = isIDFIRST_lazy_if_safe(s, s_end, is_utf8)))
10614+
&& (advance = (flags & IDCONT_first_OK)
10615+
? isIDCONT_lazy_if_safe((U8 *) s, (U8 *) s_end,
10616+
is_utf8)
10617+
: isIDFIRST_lazy_if_safe(s, s_end, is_utf8)))
1060910618
{
1061010619
const char *this_start = s;
1061110620
s += advance;

0 commit comments

Comments
 (0)