Skip to content

Conversation

khwilliamson
Copy link
Contributor

@khwilliamson khwilliamson commented Sep 24, 2025

This commit greatly improves this function, often eliminating the need for heuristics when use strict is in effect, and looking for lexical variables besides globals.

There is plenty more problems with this function, but this gets the majority, as use strict is in effect most of the time these days.

I really don't know much about parsing, so there could easily be some oversights here; Reviews especially welcome

@khwilliamson khwilliamson force-pushed the initial_intuit_more branch 3 times, most recently from c88e111 to 23656e0 Compare September 24, 2025 16:11
The source to parse must be in the buffer terminated at PL_bufend.  This
was not obvious to me; this assertion would have caught my error
earlier.
This checks first if there is a lexical variable in scope with the given
name, and if not, if there is a global
Most code these days runs under 'use strict'.  That allows us to resolve
ambiguity without resorting to heuristics in far more cases than before.

This commit adds a parameter to intuit_more() that gives the context it
is being called from.  And when that call is to resolve what $foo[...]
is supposed to mean, we can look up foo to see if it is an array or a
scalar.  If the former, the "..." must be a subscript; if a scalar, it
must be a charclass.

Only if there is both a $foo and an @foo is there ambiguity.  If so, we
drop down to using the heuristics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant