Skip to content

Commit 914838c

Browse files
authored
Merge pull request #98 from robotpy/using-enum
Add support for 'using enum'
2 parents 7aac68c + 4d1f184 commit 914838c

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

.github/workflows/dist.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ jobs:
8383
runs-on: ${{ matrix.os }}
8484
strategy:
8585
matrix:
86-
os: [windows-latest, macos-latest, ubuntu-20.04]
86+
os: [windows-latest, macos-13, ubuntu-20.04]
8787
python_version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
8888
architecture: [x86, x64]
8989
exclude:
90-
- os: macos-latest
90+
- os: macos-13
9191
architecture: x86
9292
- os: ubuntu-20.04
9393
architecture: x86

cxxheaderparser/parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,9 @@ def _parse_using(
10411041
) -> None:
10421042
self.state.location = tok.location
10431043

1044-
tok = self._next_token_must_be("NAME", "DBL_COLON", "namespace", "typename")
1044+
tok = self._next_token_must_be(
1045+
"NAME", "DBL_COLON", "namespace", "typename", "enum"
1046+
)
10451047

10461048
if tok.type == "namespace":
10471049
if template:

tests/test_using.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,3 +716,64 @@ def test_using_typename_in_class() -> None:
716716
]
717717
)
718718
)
719+
720+
721+
def test_using_enum_global() -> None:
722+
content = """
723+
namespace A {
724+
using enum B::C;
725+
}
726+
"""
727+
data = parse_string(content, cleandoc=True)
728+
729+
assert data == ParsedData(
730+
namespace=NamespaceScope(
731+
namespaces={
732+
"A": NamespaceScope(
733+
name="A",
734+
using=[
735+
UsingDecl(
736+
typename=PQName(
737+
segments=[
738+
NameSpecifier(name="B"),
739+
NameSpecifier(name="C"),
740+
],
741+
classkey="enum",
742+
)
743+
)
744+
],
745+
)
746+
}
747+
)
748+
)
749+
750+
751+
def test_using_enum_in_struct() -> None:
752+
content = """
753+
struct S {
754+
using enum fruit;
755+
};
756+
"""
757+
data = parse_string(content, cleandoc=True)
758+
759+
assert data == ParsedData(
760+
namespace=NamespaceScope(
761+
classes=[
762+
ClassScope(
763+
class_decl=ClassDecl(
764+
typename=PQName(
765+
segments=[NameSpecifier(name="S")], classkey="struct"
766+
)
767+
),
768+
using=[
769+
UsingDecl(
770+
typename=PQName(
771+
segments=[NameSpecifier(name="fruit")], classkey="enum"
772+
),
773+
access="public",
774+
)
775+
],
776+
)
777+
]
778+
)
779+
)

0 commit comments

Comments
 (0)