#!/usr/bin/env python
"""
:Author Patrik Valkovic
:Created 23.06.2017 16:39
:Licence GNUv3
Part of grammpy

"""

from .Terminal import Terminal
from .HashContainer import HashContainer
from .exceptions import NotNonterminalException

class RawGrammar:
    def __init__(self, terminals=[], nonterminals=None, rules=None):
        # Ensure that parameters are immutable
        if rules is None:
            rules = []
        if nonterminals is None:
            nonterminals = []
        # TODO fill and add tests
        self.__terminals = HashContainer(terminals)
        self.__nonterminals = {}

    # Term part
    def add_term(self, term):
        return self.__terminals.add(term)

    def remove_term(self, term=None):
        return self.__terminals.remove(term)

    def have_term(self, term):
        return self.__terminals.have(term)

    def get_term(self, term=None):
        if term is not None and not HashContainer.is_iterable(term):
            item = self.__terminals.get(term)
            return Terminal(item, self) if item is not None else None
        vals = []
        for t in self.__terminals.get(term):
            vals.append(Terminal(t,self) if t is not None else None)
        return vals

    def term(self, term=None):
        return self.get_term(term)

    def terms(self):
        for item in self.__terminals.all():
            yield Terminal(item, self)

    def terms_count(self):
        return self.__terminals.count()

    # Non term part
    def add_nonterm(self, nonterm):
        raise NotImplementedError()

    def remove_nonterm(self, nonterm=None):
        raise NotImplementedError()

    def have_nonterm(self, nonterm):
        raise NotImplementedError()

    def get_nonterm(self, nonterm = None):
        raise NotImplementedError()

    def nonterm(self, nonterm):
        raise NotImplementedError()

    def nonterms(self):
        raise NotImplementedError()

    def nonterms_count(self):
        raise NotImplementedError()

    pass

@@ -278,18 +278,20 @@
 rminals=
-%5B%5D
+None
 , nonter
@@ -328,158 +328,173 @@
     
-# Ensure that parameters are immutable%0A        if rules is None:%0A            rules = %5B%5D%0A        if nonterminals is None:%0A            nonterminals = %5B%5D
+terminals = %5B%5D if terminals is None else terminals%0A        nonterminals = %5B%5D if nonterminals is None else nonterminals%0A        rules = %5B%5D if rules is None else rules
 %0A   
@@ -610,10 +610,35 @@
 s = 
-%7B%7D
+HashContainer(nonterminals)
 %0A%0A  
@@ -1564,35 +1564,68 @@
     
-raise NotImplementedError()
+nonterm = HashContainer.to_iterable(nonterm)%0A        self.__
 %0A%0A  

Reimplement constructor of RawGrammar so parameters are now immutable