def grammar(grammar_type=None, grammar_name=None):
 def grammar_creator(validator, name):
  def setter(self, value):
   if isinstance(grammar_type, (type, tuple)):
    _assert_is_type(validator.__name__, value, grammar_type)
   validator(value)
   self.grammar[name] = value
  def getter(self):
   return self.grammar.get(name, None)
  def deleter(self):
   if (name in self.grammar):
    del self.grammar[name]
  return property(getter, setter, deleter, validator.__doc__)
 if isinstance(grammar_type, (type, tuple)):
  def grammar_dec(validator):
   if grammar_name:
    return grammar_creator(validator, grammar_name)
   else:
    return grammar_creator(validator, validator.__name__)
  return grammar_dec
 elif isinstance(grammar_name, str_types):
  def grammar_dec(validator):
   return grammar_creator(validator, grammar_name)
  return grammar_dec
 else:
  return grammar_creator(grammar_type, grammar_type.__name__)

def grammar ( grammar_type = None , grammar_name = None ) : def grammar_creator ( validator , name ) : def setter ( self , value ) : if isinstance ( grammar_type , ( type , tuple ) ) : _assert_is_type ( validator . __name__ , value , grammar_type ) validator ( value ) self . grammar [ name ] = value def getter ( self ) : return self . grammar . get ( name , None ) def deleter ( self ) : if ( name in self . grammar ) : del self . grammar [ name ] return property ( getter , setter , deleter , validator . __doc__ ) if isinstance ( grammar_type , ( type , tuple ) ) : def grammar_dec ( validator ) : if grammar_name : return grammar_creator ( validator , grammar_name ) else : return grammar_creator ( validator , validator . __name__ ) return grammar_dec elif isinstance ( grammar_name , str_types ) : def grammar_dec ( validator ) : return grammar_creator ( validator , grammar_name ) return grammar_dec else : return grammar_creator ( grammar_type , grammar_type . __name__ )
decorator to define properties that map to the grammar dict .