Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix the syntax rule (regex) for creating a new instance with a new keyword bug mentioned in issue #116 #117

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

Merged

Conversation

@guyleaf
Copy link

@guyleaf guyleaf commented Sep 12, 2021
edited
Loading

Modification

  1. Fix the syntax rule (regex) for creating a new instance with a new keyword
  2. Add some tests for testing the syntax rule with the prefix "new"

Detail

I changed ^new(?>\s*)

protected static readonly Regex instanceCreationWithNewKeywordRegex = new Regex(@"^new(?>\s*)((?<isAnonymous>[{{])|((?<name>[\p{L}_][\p{L}_0-9\.]*)(?>\s*)(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?>\s*)((?<isfunction>[(])|(?<isArray>\[)|(?<isInit>[{{]))?))", RegexOptions.IgnoreCase | RegexOptions.Compiled);

to ^new(?>\s+)

protected static readonly Regex instanceCreationWithNewKeywordRegex = new Regex(@"^new(?>\s+)((?<isAnonymous>[{{])|((?<name>[\p{L}_][\p{L}_0-9\.]*)(?>\s*)(?<isgeneric>[<](?>[^<>]+|(?<gentag>[<])|(?<-gentag>[>]))*(?(gentag)(?!))[>])?(?>\s*)((?<isfunction>[(])|(?<isArray>\[)|(?<isInit>[{{]))?))", RegexOptions.IgnoreCase | RegexOptions.Compiled);

Reason

The original regex rule will detect 3 cases.

  1. new instance: new List() ✔
  2. new function: new(...) ✔
  3. newCards (variable name) (❌ false detection

The original one should not detect the last one.

Copy link
Author

guyleaf commented Sep 12, 2021

The problem is mentioned in #116

Copy link
Author

guyleaf commented Sep 12, 2021
edited
Loading

Still fixing regex...
I find this modification should affect other tests error, like new(...), but it is still working.
Because the space after the new keyword is at least one space.

(Update) I figure out why it works.
"(?>.." is to capture keywords.
So, if we keep the original one, it will detect words with the prefix "new" without blanks. (because it is \s*)
And with \s+, new() is still working because there is a ?<isfunction> regex after that.

@guyleaf guyleaf marked this pull request as ready for review September 12, 2021 18:55
@guyleaf guyleaf marked this pull request as draft September 12, 2021 18:55
@guyleaf guyleaf changed the base branch from master to dev September 12, 2021 19:13
@guyleaf guyleaf changed the base branch from dev to master September 12, 2021 19:14
@guyleaf guyleaf marked this pull request as ready for review September 13, 2021 01:02
@guyleaf guyleaf changed the title (削除) Fix new instance keyword identification bug mentioned in issue #116 (削除ここまで) (追記) Fix instance creation with new keyword regex detection bug mentioned in issue #116 (追記ここまで) Sep 13, 2021
@codingseb codingseb merged commit d5932a7 into codingseb:master Sep 13, 2021
Copy link
Owner

codingseb commented Sep 13, 2021
edited
Loading

I changed ^new(?>\s*)
to ^new(?>\s+)

Of course it is obvious. My bad.
Thanks a lot for the bug report and for your PR @guyleaf .
I have less time these days for ExpressionEvaluator so your help is greatly appreciate.

I will also try to correct quickly #115 and publish a new version asap.

guyleaf reacted with thumbs up emoji

@guyleaf guyleaf changed the title (削除) Fix instance creation with new keyword regex detection bug mentioned in issue #116 (削除ここまで) (追記) Fix the syntax rule (regex) for creating a new instance with a new keyword bug mentioned in issue #116 (追記ここまで) May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /