Skip to content

Commit

Permalink
Add support for case ranges. (#62)
Browse files Browse the repository at this point in the history
* Add support for case ranges.

* Tweak line wrapping to content the linter.

Co-authored-by: Andreas Klöckner <[email protected]>
  • Loading branch information
qwenger and inducer authored Sep 22, 2021
1 parent 502dbb9 commit 17c03ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pycparserext/ext_c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,15 @@ def p_range_designator(self, p):
"""
p[0] = RangeExpression(p[2], p[4], coord=self._coord(p.lineno(1)))

def p_labeled_statement_4(self, p):
""" labeled_statement : CASE constant_expression ELLIPSIS constant_expression \
COLON pragmacomp_or_statement
"""
p[0] = c_ast.Case(
RangeExpression(p[2], p[4], coord=self._coord(p.lineno(1))),
[p[6]],
self._coord(p.lineno(1)))

def p_unified_volatile_gnu(self, p):
""" unified_volatile : VOLATILE
| __VOLATILE
Expand Down
16 changes: 16 additions & 0 deletions test/test_pycparserext.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,22 @@ def test_designated_initializers():
assert _round_trip_matches(src)


def test_case_ranges():
src = """
void f() {
switch (1) {
case 3:
break;
case 0 ... 5:
break;
case 'A' ... 'Z':
break;
}
}
"""
assert _round_trip_matches(src)


@pytest.mark.parametrize("restrict_kw", ["restrict", "__restrict__", "__restrict"])
def test_restrict(restrict_kw):
src = """
Expand Down

0 comments on commit 17c03ac

Please sign in to comment.