Skip to content

Commit 326da61

Browse files
committed
Remove EmptyBlockState
- Turns out you can't put an empty block except in code
1 parent 8c69970 commit 326da61

File tree

6 files changed

+1
-124
lines changed

6 files changed

+1
-124
lines changed

cxxheaderparser/parser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from .options import ParserOptions
1111
from .parserstate import (
1212
ClassBlockState,
13-
EmptyBlockState,
1413
ExternBlockState,
1514
NamespaceBlockState,
1615
ParsedTypeModifiers,
@@ -510,9 +509,7 @@ def _consume_static_assert(
510509
def _on_empty_block_start(
511510
self, tok: LexToken, doxygen: typing.Optional[str]
512511
) -> None:
513-
state = self._push_state(EmptyBlockState)
514-
if self.visitor.on_empty_block_start(state) is False:
515-
self.visitor = null_visitor
512+
raise self._parse_error(tok)
516513

517514
def _on_block_end(self, tok: LexToken, doxygen: typing.Optional[str]) -> None:
518515
old_state = self._pop_state()

cxxheaderparser/parserstate.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ def _finish(self, visitor: "CxxVisitor") -> None:
5656
pass
5757

5858

59-
class EmptyBlockState(State[T, PT]):
60-
parent: State[PT, typing.Any]
61-
62-
def _finish(self, visitor: "CxxVisitor") -> None:
63-
visitor.on_empty_block_end(self)
64-
65-
6659
class ExternBlockState(State[T, PT]):
6760
parent: State[PT, typing.Any]
6861

cxxheaderparser/simple.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151

5252
from .parserstate import (
5353
State,
54-
EmptyBlockState,
5554
ClassBlockState,
5655
ExternBlockState,
5756
NamespaceBlockState,
@@ -181,7 +180,6 @@ class N::C {
181180

182181
# define what user data we store in each state type
183182
SState = State[Block, Block]
184-
SEmptyBlockState = EmptyBlockState[Block, Block]
185183
SExternBlockState = ExternBlockState[Block, Block]
186184
SNamespaceBlockState = NamespaceBlockState[NamespaceScope, NamespaceScope]
187185
SClassBlockState = ClassBlockState[ClassScope, Block]
@@ -209,16 +207,6 @@ def on_pragma(self, state: SState, content: Value) -> None:
209207
def on_include(self, state: SState, filename: str) -> None:
210208
self.data.includes.append(Include(filename))
211209

212-
def on_empty_block_start(self, state: SEmptyBlockState) -> typing.Optional[bool]:
213-
# this matters for some scope/resolving purposes, but you're
214-
# probably going to want to use clang if you care about that
215-
# level of detail
216-
state.user_data = state.parent.user_data
217-
return None
218-
219-
def on_empty_block_end(self, state: SEmptyBlockState) -> None:
220-
pass
221-
222210
def on_extern_block_start(self, state: SExternBlockState) -> typing.Optional[bool]:
223211
state.user_data = state.parent.user_data
224212
return None

cxxheaderparser/visitor.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
from .parserstate import (
2727
State,
28-
EmptyBlockState,
2928
ClassBlockState,
3029
ExternBlockState,
3130
NamespaceBlockState,
@@ -52,26 +51,6 @@ def on_include(self, state: State, filename: str) -> None:
5251
Called once for each ``#include`` directive encountered
5352
"""
5453

55-
def on_empty_block_start(self, state: EmptyBlockState) -> typing.Optional[bool]:
56-
"""
57-
Called when a ``{`` is encountered that isn't associated with or
58-
consumed by other declarations.
59-
60-
.. code-block:: c++
61-
62-
{
63-
// stuff
64-
}
65-
66-
If this function returns False, the visitor will not be called for any
67-
items inside this block (including on_empty_block_end)
68-
"""
69-
70-
def on_empty_block_end(self, state: EmptyBlockState) -> None:
71-
"""
72-
Called when an empty block ends
73-
"""
74-
7554
def on_extern_block_start(self, state: ExternBlockState) -> typing.Optional[bool]:
7655
"""
7756
.. code-block:: c++
@@ -258,12 +237,6 @@ def on_pragma(self, state: State, content: Value) -> None:
258237
def on_include(self, state: State, filename: str) -> None:
259238
return None
260239

261-
def on_empty_block_start(self, state: EmptyBlockState) -> typing.Optional[bool]:
262-
return None
263-
264-
def on_empty_block_end(self, state: EmptyBlockState) -> None:
265-
return None
266-
267240
def on_extern_block_start(self, state: ExternBlockState) -> typing.Optional[bool]:
268241
return None
269242

tests/test_misc.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -351,29 +351,3 @@ def test_warning_directive() -> None:
351351
data = parse_string(content, cleandoc=True)
352352

353353
assert data == ParsedData()
354-
355-
356-
def test_empty_block() -> None:
357-
"""
358-
Ensure the simple visitor doesn't break with an empty block
359-
"""
360-
content = """
361-
{
362-
class X {};
363-
}
364-
"""
365-
data = parse_string(content, cleandoc=True)
366-
367-
assert data == ParsedData(
368-
namespace=NamespaceScope(
369-
classes=[
370-
ClassScope(
371-
class_decl=ClassDecl(
372-
typename=PQName(
373-
segments=[NameSpecifier(name="X")], classkey="class"
374-
)
375-
)
376-
)
377-
]
378-
)
379-
)

tests/test_skip.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
NamespaceScope,
1111
ParsedData,
1212
SClassBlockState,
13-
SEmptyBlockState,
1413
SExternBlockState,
1514
SNamespaceBlockState,
1615
SimpleCxxVisitor,
@@ -148,53 +147,6 @@ class Yup {
148147
)
149148

150149

151-
#
152-
# ensure empty block is skipped
153-
#
154-
155-
156-
class SkipEmptyBlock(SimpleCxxVisitor):
157-
def on_empty_block_start(self, state: SEmptyBlockState) -> typing.Optional[bool]:
158-
return False
159-
160-
161-
def test_skip_empty_block() -> None:
162-
content = """
163-
void fn1();
164-
165-
{
166-
void fn2();
167-
}
168-
169-
void fn3();
170-
"""
171-
v = SkipEmptyBlock()
172-
parser = CxxParser("<str>", inspect.cleandoc(content), v)
173-
parser.parse()
174-
data = v.data
175-
176-
assert data == ParsedData(
177-
namespace=NamespaceScope(
178-
functions=[
179-
Function(
180-
return_type=Type(
181-
typename=PQName(segments=[FundamentalSpecifier(name="void")])
182-
),
183-
name=PQName(segments=[NameSpecifier(name="fn1")]),
184-
parameters=[],
185-
),
186-
Function(
187-
return_type=Type(
188-
typename=PQName(segments=[FundamentalSpecifier(name="void")])
189-
),
190-
name=PQName(segments=[NameSpecifier(name="fn3")]),
191-
parameters=[],
192-
),
193-
]
194-
)
195-
)
196-
197-
198150
#
199151
# ensure namespace 'skip' is skipped
200152
#

0 commit comments

Comments
 (0)