Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'using enum' #98

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
)
],
)
]
)
)
Loading