Skip to content

Commit 17c03ac

Browse files
qwengerinducer
andauthored
Add support for case ranges. (#62)
* Add support for case ranges. * Tweak line wrapping to content the linter. Co-authored-by: Andreas Klöckner <inform@tiker.net>
1 parent 502dbb9 commit 17c03ac

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

pycparserext/ext_c_parser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,15 @@ def p_range_designator(self, p):
558558
"""
559559
p[0] = RangeExpression(p[2], p[4], coord=self._coord(p.lineno(1)))
560560

561+
def p_labeled_statement_4(self, p):
562+
""" labeled_statement : CASE constant_expression ELLIPSIS constant_expression \
563+
COLON pragmacomp_or_statement
564+
"""
565+
p[0] = c_ast.Case(
566+
RangeExpression(p[2], p[4], coord=self._coord(p.lineno(1))),
567+
[p[6]],
568+
self._coord(p.lineno(1)))
569+
561570
def p_unified_volatile_gnu(self, p):
562571
""" unified_volatile : VOLATILE
563572
| __VOLATILE

test/test_pycparserext.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,22 @@ def test_designated_initializers():
469469
assert _round_trip_matches(src)
470470

471471

472+
def test_case_ranges():
473+
src = """
474+
void f() {
475+
switch (1) {
476+
case 3:
477+
break;
478+
case 0 ... 5:
479+
break;
480+
case 'A' ... 'Z':
481+
break;
482+
}
483+
}
484+
"""
485+
assert _round_trip_matches(src)
486+
487+
472488
@pytest.mark.parametrize("restrict_kw", ["restrict", "__restrict__", "__restrict"])
473489
def test_restrict(restrict_kw):
474490
src = """

0 commit comments

Comments
 (0)