#include"mkf_definition.hpp"




Definition::
Definition()
{
}


Definition::
Definition(const char*  id, Element&&  el)
{
  reset(id,std::move(el));
}


Definition::
Definition(const char*  id, std::vector<Element>&&  els):
identifier(id)
{
    for(auto&  el: els)
    {
      append(std::move(el),'|');
    }
}


Definition::
Definition(const char*&  p)
{
  reset(p);
}


Definition::
Definition(const Definition&   rhs):
Group(rhs),
identifier(rhs.identifier)
{
}


Definition::
Definition(Definition&&  rhs):
Group(std::move(rhs)),
identifier(std::move(rhs.identifier))
{
}




void
Definition::
reset(const char*  id, Element&&  el)
{
  clear();

  identifier = id;

  append(std::move(el),';');
}


void
Definition::
reset(const char*&  p)
{
  clear();

  char  buf[256];

  int  n = 0;

    if(sscanf(p," %256[0-9a-zA-Z_] = %n",buf,&n) == 1)
    {
      identifier = buf;

      p += n;

      scan(p,';');
    }

  else
    {
      report;
    }
}


const Identifier&
Definition::
get_identifier() const
{
  return identifier;
}


void
Definition::
print() const
{
  printf("%s = ",identifier.get_buffer());

  Group::print();
}




