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

Recognize integer multicharacter constants like 'ABCD' #350

Merged
merged 3 commits into from
Sep 25, 2019
Merged

Recognize integer multicharacter constants like 'ABCD' #350

merged 3 commits into from
Sep 25, 2019

Conversation

yaroslav-o
Copy link
Contributor

No description provided.

@yaroslav-o
Copy link
Contributor Author

@eliben

Copy link
Owner

@eliben eliben left a comment

Choose a reason for hiding this comment

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

Would you mind adding some description to your PR explaining the feature you're implementing, where it's defined, and so on? Also, add tests

@@ -448,11 +448,11 @@ def test_char_constants(self):
self.assertLexerError("'", ERR_UNMATCHED_QUOTE)
self.assertLexerError("'b\n", ERR_UNMATCHED_QUOTE)
self.assertLexerError("'\\xaa\n'", ERR_UNMATCHED_QUOTE)

self.assertLexerError(r"'\12a'", ERR_INVALID_CCONST)
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure why you're modifying these tests, without adding any new tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added new tests.

@yaroslav-o
Copy link
Contributor Author

yaroslav-o commented Sep 24, 2019

The feature I am adding is defined here - 5th case.
https://en.cppreference.com/w/c/language/character_constant
Also here: 6.4.4.4.10 of C99.

Put simply, pycparser thought a statement like this is an error:
int a = 'ABCD';
However it is not.

It is likely possible to just modify char_const regular expression in c_lexer.py:240 to allow longer characters, but the way it is done in this PR - multicharacter constants are clearly separated. I am also limiting the length of multicharacter const integers to 4 characters - this matches VS compiler behavior (gcc allows any length with a warning) and lets pycparser NOT consider lengthy single-quoted strings as integers - these would be nonsensical anyway.

@eliben
Copy link
Owner

eliben commented Sep 25, 2019

Thanks for adding the information.

@eliben eliben merged commit a4a7127 into eliben:master Sep 25, 2019
fengjixuchui added a commit to fengjixuchui/pycparser that referenced this pull request Oct 22, 2019
Recognize integer multicharacter constants like 'ABCD' (eliben#350)
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.

None yet

2 participants