diff --git a/src/cfile/core.py b/src/cfile/core.py index 5115432..0db4be1 100644 --- a/src/cfile/core.py +++ b/src/cfile/core.py @@ -511,3 +511,8 @@ class Block(Sequence): """ A sequence wrapped in braces """ + +class Break(Element): + """ + Adding break into block + """ diff --git a/src/cfile/factory.py b/src/cfile/factory.py index 71a609e..e661df8 100644 --- a/src/cfile/factory.py +++ b/src/cfile/factory.py @@ -227,3 +227,9 @@ def declaration(self, """New declaration""" return core.Declaration(element, init_value) + + def breakBlock(self) -> core.Break: + """ + Adding break into block + """ + return core.Break() diff --git a/src/cfile/writer.py b/src/cfile/writer.py index e842e8f..6ed1be9 100644 --- a/src/cfile/writer.py +++ b/src/cfile/writer.py @@ -188,6 +188,8 @@ def _write_sequence(self, sequence: core.Sequence) -> None: elif isinstance(elem, core.Line): self._start_line() self._write_line_element(elem) + elif isinstance(elem, core.Break): + self._write_break(elem) else: self._start_line() class_name = elem.__class__.__name__ @@ -709,3 +711,6 @@ def _write_endif_directive(self, elem: core.EndifDirective) -> None: def _write_extern(self, elem: core.Extern) -> None: self._write(f'extern "{elem.language}"') self.last_element = ElementType.DIRECTIVE + + def _write_break(self, elem: core.Break): + self._write("break")