Skip to content

Support for labels with no statement#562

Merged
eliben merged 4 commits intoeliben:mainfrom
ignatirabo:main
Jan 13, 2025
Merged

Support for labels with no statement#562
eliben merged 4 commits intoeliben:mainfrom
ignatirabo:main

Conversation

@ignatirabo
Copy link
Copy Markdown
Contributor

This pull request is aimed at fixing the issue described here: #528

The testing I did seems fine, and I implemented it through two rules to ensure that the representation of label: and label:; is the same.

Copy link
Copy Markdown
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.

This seems to be introducing a large number of new shift/reduce conflicts for the parser, and it's clear why!

Comment thread pycparser/c_parser.py Outdated
p[0] = c_ast.Default([p[3]], self._token_coord(p, 1))

def p_labeled_statement_4(self, p):
""" labeled_statement : ID COLON SEMI"""
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't think this rule (_4) should be necessary, since a statement can already be empty. Why do you need it?

@ignatirabo ignatirabo requested a review from eliben January 9, 2025 17:27
Copy link
Copy Markdown
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.

For the test, there's no reason to create a separate class just for this test. You can add a test_ function to the existing class.

Also, you're only checking that the code compiles properly without verifying anything about the AST. pycparser could completely ignore the label here and your test would still pass.

You probably want something similar to test_pragmacomp_or_statement but much simpler, that checks the right AST nodes with labels are parsed in a short function body.

@ignatirabo ignatirabo requested a review from eliben January 12, 2025 19:54
@ignatirabo
Copy link
Copy Markdown
Contributor Author

Thank you for the all the comments. I imitated the test as you suggested.

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