Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parsing of SPL2 modules for statement names to handle strings, fields, functions, comments. #131

Merged
merged 4 commits into from
Dec 2, 2024

Conversation

fantavlik
Copy link
Collaborator

This PR adds more robust parsing for search statements to exclude cases like local variable assignments within a function:

function foo() {
  $not_a_search = ...
}

or statements that have been commented out:

$use_me = from ...;
/*
$dont_use_me = ...;
*/

@fantavlik fantavlik changed the title Draft: Fix issues with determining last SPL2 search statement to execute Improve parsing of SPL2 modules for statement names to handle strings, fields, functions, comments. Nov 26, 2024
newModule += next;
}
}
spl2Module = spl2Module.substring(indx, spl2Module.length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a tall ask and is out of scope for this, but are the repeated substring calls suboptimal here? Would it be best to traverse the string via an index like so:

newModule = "";
for (index = 0; index < spl2Module.length; index++) {
    next = spl2Module[indx];
    ...
    // Case logic and all here
    ...
    if (!inBlockComment && !inField && !inString && !inLineComment && braceLevel === 0) {
        newModule += next;

    prev = next;
}

Doing so might fare better for larger modules since we don't need to repeatedly substringify the module.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good suggestion substring made more sense before I rewrote the parsing code but serves no purpose anymore. I made your suggested changes.

let braceLevel = 0; // { .. }

let newModule = '';
let prev = '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we updating prev? I don't see any assignments to prev, specifically nothing like prev = next

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch, it looks like I neglected to add a test that includes string and field escape chars too so let me do that

@haariskhan902
Copy link
Collaborator

Approved on my end!

@fantavlik fantavlik merged commit 385fec5 into master Dec 2, 2024
6 checks passed
@fantavlik fantavlik deleted the bugfix/exclude-function-params branch December 2, 2024 22:01
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.

2 participants