Skip to content

Commit

Permalink
Merge pull request #98 from robotpy/using-enum
Browse files Browse the repository at this point in the history
Add support for 'using enum'
  • Loading branch information
virtuald authored May 28, 2024
2 parents 7aac68c + 4d1f184 commit 914838c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-20.04]
os: [windows-latest, macos-13, ubuntu-20.04]
python_version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
architecture: [x86, x64]
exclude:
- os: macos-latest
- os: macos-13
architecture: x86
- os: ubuntu-20.04
architecture: x86
Expand Down
4 changes: 3 additions & 1 deletion cxxheaderparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,9 @@ def _parse_using(
) -> None:
self.state.location = tok.location

tok = self._next_token_must_be("NAME", "DBL_COLON", "namespace", "typename")
tok = self._next_token_must_be(
"NAME", "DBL_COLON", "namespace", "typename", "enum"
)

if tok.type == "namespace":
if template:
Expand Down
61 changes: 61 additions & 0 deletions tests/test_using.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,3 +716,64 @@ def test_using_typename_in_class() -> None:
]
)
)


def test_using_enum_global() -> None:
content = """
namespace A {
using enum B::C;
}
"""
data = parse_string(content, cleandoc=True)

assert data == ParsedData(
namespace=NamespaceScope(
namespaces={
"A": NamespaceScope(
name="A",
using=[
UsingDecl(
typename=PQName(
segments=[
NameSpecifier(name="B"),
NameSpecifier(name="C"),
],
classkey="enum",
)
)
],
)
}
)
)


def test_using_enum_in_struct() -> None:
content = """
struct S {
using enum fruit;
};
"""
data = parse_string(content, cleandoc=True)

assert data == ParsedData(
namespace=NamespaceScope(
classes=[
ClassScope(
class_decl=ClassDecl(
typename=PQName(
segments=[NameSpecifier(name="S")], classkey="struct"
)
),
using=[
UsingDecl(
typename=PQName(
segments=[NameSpecifier(name="fruit")], classkey="enum"
),
access="public",
)
],
)
]
)
)

0 comments on commit 914838c

Please sign in to comment.