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

Update grammar functionDefinition parser rule and rename NumberUnit lexer rule #14066

Merged
merged 1 commit into from Mar 24, 2023

Conversation

matheusaaguiar
Copy link
Collaborator

@matheusaaguiar matheusaaguiar commented Mar 22, 2023

While working in literal suffixes, some problematic cases not covered by tests were found and motivated this.

docs/grammar/SolidityLexer.g4 Outdated Show resolved Hide resolved
/**
* Scanned but not used by any rule, i.e, disallowed.
*/
OctalNumber: '0' DecimalDigits ('.' DecimalDigits)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically, 8 and 9 are not valid octal numbers, but are present in DecimalDigits (at least I'd hope, I haven't looked :D). So something like 091 would not be a valid octal number in the first place, but the parser error would indicate that octal numbers are not supported, which could be a bit confusing if someone makes a typo, e.g. 091 instead of 91. I think we might have to introduce OctalDigits as well if we want to be fully correct, at least I'm assuming that's something @ekpyron or @cameel would say.

Copy link
Member

@cameel cameel Mar 22, 2023

Choose a reason for hiding this comment

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

I think we can leave it as is because solc's parser behaves the same way. I.e. 091 results in

Error: Octal numbers not allowed.

Perhaps we should change that in solc, but that's a separate matter - and it would still be an error, just a different one (what is even 091?).

In any case, we should definitely have a test case for something like 091 to make sure both the grammar and the parser at least both treat it as an error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough. But I can tell you what 091 isn't. An octal number :D

Copy link
Member

Choose a reason for hiding this comment

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

We could at least add a note about this weirdness in the docstring above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was mainly focused in mirroring solc parser, which seems to treat anything starting with a 0 (and not followed by .) as octal...
I am going to add the test case regarding 091.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also added the note in the docstring.

docs/grammar/SolidityParser.g4 Outdated Show resolved Hide resolved
/** The definition of a free function.
*
*/
freeFunctionDefinition:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this and the NumberUnit changes should be separate PRs, since it's a bit confusing this way, especially since the tests only cover the NumberUnit changes.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, would not mind having those as separate PRs, though I'm also fine with one because we already have quite a few suffix-related PRs :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I felt that, since we already tested (and cameel reviewed) the changes in the literal suffix PR, it would be easier to just push this as a single one. Plus, not too many changes.
But, no problem splitting it, if we consider that should be done.

@cameel cameel requested a review from chriseth March 22, 2023 21:21
@matheusaaguiar matheusaaguiar force-pushed the update_grammar branch 2 times, most recently from c30e530 to 1f45ef6 Compare March 22, 2023 21:47
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

Needs only small corrections.

docs/grammar/SolidityParser.g4 Outdated Show resolved Hide resolved
cameel
cameel previously approved these changes Mar 24, 2023
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

Looks good. Please squash review fixes into the original commits and we can merge.

Also, you should add a changelog entry for some of the grammar changes. The renamings and splits are just refactors but we also have some actual changes:

  • a fix of the discrepancy between the grammar and our parser for numbers followed by an identifier
  • grammar is now more strict for free function definitions and will no longer accept some things that are only allowed for contract functions

@stackenbotten

This comment was marked as resolved.

Changelog.md Outdated Show resolved Hide resolved
@matheusaaguiar matheusaaguiar force-pushed the update_grammar branch 2 times, most recently from 77f675e to 9dac87e Compare March 24, 2023 17:42
@matheusaaguiar
Copy link
Collaborator Author

I was not sure if the changes should go in their own section titled Antlr Changes.

Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

Some text corrections.

Changelog.md Outdated Show resolved Hide resolved
Changelog.md Outdated Show resolved Hide resolved
Changelog.md Outdated Show resolved Hide resolved
@cameel
Copy link
Member

cameel commented Mar 24, 2023

By the way, just FYI, you don't have to squash it into a single commit. In this case it would be even nicer to have the independent changes in separate commits. There should just be no commits that change things from other commits from the same PR. Other than that it mostly matters that each commit is a single logical change.

A good rule is that if it's hard to describe the set of changes in one short sentence, it's probably doing more than one thing and could be split.

…d number followed by identifier with no whitespace.
@matheusaaguiar
Copy link
Collaborator Author

matheusaaguiar commented Mar 24, 2023

By the way, just FYI, you don't have to squash it into a single commit. In this case it would be even nicer to have the independent changes in separate commits.

Good to know that. I'll keep in mind for the future. Thanks.
Should we leave this in a single commit or try to restore the order from before?

@cameel
Copy link
Member

cameel commented Mar 24, 2023

Let's leave it as is so that we can merge it :)

@cameel cameel merged commit 5dbfa94 into develop Mar 24, 2023
1 check passed
@cameel cameel deleted the update_grammar branch March 24, 2023 20:19
@cameel cameel mentioned this pull request Apr 5, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants