"""Scope."""

from . import HDLObject
from .stmt import HDLStatement


class HDLScope(HDLObject):
    """Scope."""

    _scope_types = ['seq', 'par']

    def __init__(self, scope_type):
        """Initialize."""
        self.statements = []
        if scope_type not in self._scope_types:
            raise KeyError('invalid scope type')

        self.scope_type = scope_type

    def add(self, *elements):
        """Add elements to scope."""
        for element in elements:
            if not isinstance(element, HDLStatement):
                raise TypeError('only HDLStatement allowed')

            # check legality
            if element.stmt_type != self.scope_type\
               and element.stmt_type != 'null':
                raise ValueError('cannot add sequential statements '
                                 'in parallel scopes and vice versa')

            self.statements.append(element)

    def __len__(self):
        """Get statement count."""
        return len(self.statements)

    def __getitem__(self, _slice):
        """Get scope item."""
        return self.statements[_slice]

    def dumps(self):
        """Get intermediate representation."""
        return '\n'.join([x.dumps()+';' for x in self.statements])

@@ -62,16 +62,50 @@
 atement%0A
+from .comment import make_comment%0A
 %0A%0Aclass 
@@ -427,9 +427,8 @@
 lf, 
-*
 elem
@@ -504,16 +504,144 @@
 ements:%0A
+            if isinstance(element, str):%0A                self.statements.append(make_comment(element))%0A                continue%0A
         
@@ -682,24 +682,56 @@
 Statement):%0A
+                print (element)%0A
             
@@ -776,17 +776,96 @@
  allowed
-'
+, got: '%0A                                '%7B%7D'.format(element.__class__.__name__)
 )%0A%0A     

allow adding comments directly in scope