Ejemplo n.º 1
0
  P operator()( target_container& t,  P beg, P end)
  {
    if ( parser::is_null(beg, end) )
    {
      t = target_container();
      return parser::parse_null(beg, end);
    }

    // std::back_insert_iterator<C> bitr =  std::back_inserter(t);
    // std::insert_iterator<C> bitr = std::inserter(t, t.end());
    typename array_type::inserter_iterator bitr = array_type::inserter(t);

    if (beg==end) throw unexpected_end_fragment();
    if (*beg!=L) throw expected_of( std::string(1, L), std::distance(beg, end) );
    ++beg;
    for (;beg!=end;)
    {
      beg = parser::parse_space(beg, end);
      if (beg==end) throw unexpected_end_fragment();
      if (*beg==R) break;
      target tg;
      beg = serializer()( tg, beg, end);
      *(bitr++) = tg;
      beg = parser::parse_space(beg, end);
      if (beg==end) throw unexpected_end_fragment();
      if (*beg==R) break;
      if (*beg!=',') throw expected_of(",", std::distance(beg, end));
      ++beg;
    }
    if (beg==end) throw unexpected_end_fragment();
    if (*beg!=R) throw expected_of(std::string(1, R), std::distance(beg, end));
    ++beg;
    return beg;
  }
Ejemplo n.º 2
0
    P operator()( T& t, P beg, P end)
    {

        if ( parser::is_null(beg, end) )
        {
            t = T();
            return parser::parse_null(beg, end);
        }

        if (beg==end)
            throw unexpected_end_fragment();

        if ( *(beg++) != '{' )
            throw expected_of("{", std::distance(beg, end) );

        beg = parser::parse_space(beg, end);
        if ( beg==end )
            throw unexpected_end_fragment();

        if ( *beg != '}')
        {
            beg = unserialize_members(t, beg, end, L() );
            if ( beg==end ) throw unexpected_end_fragment();
            beg = parser::parse_space(beg, end);
            if ( beg==end ) throw unexpected_end_fragment();
        }

        if (beg==end)
            throw unexpected_end_fragment();

        if ( *(beg++) != '}' )
            throw expected_of("}", std::distance(beg, end));

        return beg;
    }
Ejemplo n.º 3
0
  P operator()( target_container& t,  P beg, P end)
  {
    if ( parser::is_null(beg, end) )
    {
      for (int i = 0; i < N ; ++i)
        t[i] = target();
      return parser::parse_null(beg, end);
    }

//    typename array_type::inserter_iterator bitr = array_type::inserter(t);
    target* bitr = t;
    target* eitr = bitr + N;

    if (beg==end) throw unexpected_end_fragment();
    if (*beg!=L) throw expected_of( std::string(1, L), std::distance(beg, end) );
    ++beg;
    for (;beg!=end && bitr!=eitr;)
    {
      beg = parser::parse_space(beg, end);
      if (beg==end) throw unexpected_end_fragment();
      if (*beg==R) break;
      target tg;
      beg = serializer()( tg, beg, end);
      *(bitr++) = tg;
      beg = parser::parse_space(beg, end);
      if (beg==end) throw unexpected_end_fragment();
      if (*beg==R) break;
      if (*beg!=',') throw expected_of(",", std::distance(beg, end));
      ++beg;
    }
    if (beg==end) throw unexpected_end_fragment();
    if (*beg!=R) throw expected_of(std::string(1, R), std::distance(beg, end));
    ++beg;
    return beg;
  }
Ejemplo n.º 4
0
    P unserialize_members( T& , P beg, P end, ap::empty_type, bool search = false )
    {
        if ( !search )
        {
            beg = parser::parse_space(beg, end);
            if ( beg==end )
                throw unexpected_end_fragment();

            if ( *beg=='}' ) return beg;
            for(;;)
            {
                beg = parser::parse_member(beg, end);
                beg = parser::parse_space(beg, end);
                if ( beg==end ) throw unexpected_end_fragment();
                if ( *beg=='}' ) return beg;
                if ( *beg!=',' ) throw expected_of(",", std::distance(beg, end));
                ++beg;
                beg = parser::parse_space(beg, end);
            }
        }
        else
        {
            // если организован поиск и не нашли то пропускаем

            beg = parser::parse_member(beg, end);
            beg = parser::parse_space(beg, end);
            return beg;
        }
    }
Ejemplo n.º 5
0
 R _parse(T& t, R r, RR rr)
 {
   for ( ;r && rr && *r==*rr; ++r, ++rr);
   if (rr)                                     // ! сделать полный вывод 
     return throw_t<_except_>( t, expected_of( std::string(begin(rr), end(rr) ), distance(r) ), r );;
   return r;
 }
Ejemplo n.º 6
0
  R operator()(T& t, R r)
  {
    if (!r)
      return throw_( t, unexpected_end_fragment(), r );

    if (*r!='{') 
      return throw_( t, expected_of("{",  distance(r) ), r );

    r = t.get_aspect().template get<_space_>()(t, ++r);
    
    if ( !try_(t) )
      return r;
    
    for ( ; r && *r!='}'; )
    {
      r = t.get_aspect().template get<_field_>()(t, r);
      
      if ( !try_(t) )
        return r;
      
      r = t.get_aspect().template get<_space_>()(t, r);
      
      if ( !try_(t) )
        return r;
      
      if (!r)
        return throw_( t, unexpected_end_fragment(), r );
      
      if (*r == ',')
      {
        ++r;
        
        r = t.get_aspect().template get<_space_>()(t, r);
        
        if ( !try_(t) )
          return r;
      }
      else if (*r != '}')
        return throw_( t, expected_of("}",  distance(r) ), r );
    }

    if (!r)
      return throw_( t, unexpected_end_fragment(), r );

    return ++r;
  }
Ejemplo n.º 7
0
    R operator()(T& t, R r)
    {
        if (!r) return throw_t<_except_>( t, unexpected_end_fragment(), r );

        if ( *r == CH )
            return ++r;
        return throw_t<_except_>( t, expected_of( CH, distance(r) ), r );
    }
Ejemplo n.º 8
0
    R operator()(T& t, R r)
    {
        if (!r) return throw_t<_except_>( t, unexpected_end_fragment(), r );

        string_range< typename TChars::value_type > rr = srange( tchars()() );

        for ( ; rr; ++rr ) if ( *r == *rr )
                return ++r;
        return throw_t<_except_>( t, expected_of( tchars()(), distance(r) ), r );
    }
Ejemplo n.º 9
0
  P unserialize(P beg, P end, P1 vitr, int n = -1)
  {
    if (beg==end) 
      throw unexpected_end_fragment();

    if ( *(beg++) != '"' ) 
      throw expected_of("\"");

    for ( ;beg!=end && *beg!='"' && n!=0; )
    {
      if (*beg=='\\')
      {
        if (++beg==end) 
          throw unexpected_end_fragment();
        switch (*beg)
        {
          case '"' :
          case '\\':
          case '/' : *(vitr++) = *beg; ++beg; --n; break;
          case 't':  *(vitr++) = '\t'; ++beg; --n; break;
          case 'b':  *(vitr++) = '\b'; ++beg; --n; break;
          case 'r':  *(vitr++) = '\r'; ++beg; --n; break;
          case 'n':  *(vitr++) = '\n'; ++beg; --n; break;
          case 'f':  *(vitr++) = '\f'; ++beg; --n; break;
          case 'u':  beg = _unserialize_uhex(++beg, end, &vitr, n); break;
          default:
            throw invalid_json_string(std::distance(beg, end) );
        }
      }
      else
        beg = _unserialize_symbol(beg, end, &vitr, n);
    };

    if (beg==end) 
      throw unexpected_end_fragment();

    if ( *(beg++) != '"' ) 
      throw expected_of("\"");

    return beg;
    // return ++beg;
  }
Ejemplo n.º 10
0
 P operator()( target& t,  P beg, P end)
 {
   beg = key_serializer()(t.first, beg, end );
   beg = parser::parse_space(beg, end);
   if (beg==end) throw unexpected_end_fragment();
   if (*beg!=':') throw expected_of(":", std::distance(beg, end) );
   ++beg;
   beg = parser::parse_space(beg, end);
   if (beg==end) throw unexpected_end_fragment();
   beg = value_serializer()(t.second, beg, end );
   return beg;
 }
Ejemplo n.º 11
0
    P unserialize_member_name( T& , P beg, P end, M memb, bool& unserialized )
    {
        const char* name = memb();
        P start = beg;
        if ( !parser::is_string(beg, end) )
            throw expected_of("\"", std::distance(beg, end));
        ++beg;
        unserialized = true;
        for ( ; beg!=end && *name!='\0' && *beg==*name && *beg!='"'; ++name, ++beg)
        {
            if (*name!=*beg)
            {
                unserialized = false;
                break;
            }
        }

        if (beg==end)
            throw unexpected_end_fragment();

        if (*beg!='"' || *name!='\0')
            unserialized = false;

        if ( !unserialized ) return start;
        ++beg;
        beg = parser::parse_space(beg, end);
        if (beg==end)
            throw unexpected_end_fragment();

        if (*beg!=':')
            throw expected_of(":", std::distance(beg, end));
        ++beg;
        beg = parser::parse_space(beg, end);

        if (beg==end)
            throw unexpected_end_fragment();

        return beg;
    }
Ejemplo n.º 12
0
  R operator()(T& t, M, V& v, R r)
  {
    if ( t.get_aspect().template get<_parse_null_>().check(t, r) )
    {
      _clear(v);
      return t.get_aspect().template get<_parse_null_>()(t, r);
    }
    
    if ( !t.get_aspect().template get<_parse_string_>().check(t, r) )
      return r;
    
    // typedef typename T::aspect::template advice_cast<_quote_>::type::separator separator;

    if (!r)
      return throw_t<_except_>(t, unexpected_end_fragment(), r );

    if ( !t.get_aspect().template get<_quote_>().check(t, /*M(),*/ r) )
      return throw_t< _except_ >( t, expected_of( /*separator()()*/'"', distance(r) ), r );
    /*R beg_string = r;
    r = t.get_aspect().template get<_quote_>()(t, r);
    R income = r;
    r = t.get_aspect().template get<_content_string_>()(t, M(), v, r);
    if ( r == income )
      return t.get_aspect().template get<_parse_string_>()(t, beg_string);
    */
      
    r = t.get_aspect().template get<_quote_>()(t, r);
    r = t.get_aspect().template get<_content_string_>()(t, M(), v, r);
    if (!r)
      return throw_t<_except_>(t, unexpected_end_fragment(), r );
    if ( !t.get_aspect().template get<_quote_>().check(t, /*M(),*/ r) )
      return throw_t< _except_ >( t, expected_of( /*separator()()*/'"', distance(r) ), r );
    r = t.get_aspect().template get<_quote_>()(t, /*M(), v,*/ r);
    
    return r;
  }
Ejemplo n.º 13
0
    std::pair<R, RO> operator()(T& t, R r, RO ro)
    {
        if (!r) return throw_t<_except_>( t, unexpected_end_fragment(), r );

        string_range< typename TChars::value_type > rr = srange( tchars()() );

        for ( ; rr; ++rr ) if ( *r == *rr )
            {
                if (!ro)
                    return throw_t<_except_>( t, out_of_range( tchars()(), distance(r) ), r, ro );
                *(ro++) = *rr;
                return std::make_pair(++r, ro);
            }

        return throw_t<_except_>( t, expected_of( tchars()(), distance(r) ), r, ro );
    }
Ejemplo n.º 14
0
  std::pair<R, RO> _copy(T& t, R r, RR rr, RO ro)
  {
    for ( ;r && rr && ro && *r==*rr; ++r, ++rr)
      *(ro++) = *r;
    
    if (rr && !r)
      return throw_t<_except_>( t, unexpected_end_fragment(), r, ro );

    if (rr && !ro)
      return throw_t<_except_>( t, out_of_range( distance(r) ), r, ro );

    if (rr)
      return throw_t<_except_>( t, expected_of( typename string_list::left_type()(), distance(r) ), r, ro);
    
    return std::make_pair(r, ro);
  }
Ejemplo n.º 15
0
  RR operator()(T& t, RR rr)
  {
    tstring_range sr = tstring_range( tstring()() );
    for (;sr;++sr)
    {
      if (!rr.second)
        return throw_<_except_>( t, out_of_range( distance(rr.first) ), rr );

      if ( !rr.first )
        return throw_<_except_>( t, unexpected_end_fragment(), rr );

      if ( *rr.first != *sr )
        return throw_<_except_>( t, expected_of(tstring()(),  distance(rr.first) ), rr );

      *(rr.second++) = *(rr.first++);
    }

    return rr;
  }
Ejemplo n.º 16
0
    P unserialize_members( T& t, P beg, P end, ap::type_list<C, R>, bool search = false )
    {
        bool unserialized = false;
        beg = unserialize_member( t, beg, end, C(), unserialized );

        if (!unserialized)
        {
            if ( !search ) // Организуем поиск с начала списка
                beg = unserialize_members( t, beg, end, L(), true );
            else // Продолжаем поиск
                return unserialize_members( t, beg, end, R(), true );
        }
        else if (search)
            return beg;

        beg = parser::parse_space(beg, end);

        if (beg==end)
            throw unexpected_end_fragment();

        if ( *beg == ',' )
        {
            ++beg;
            beg = parser::parse_space(beg, end);

            if ( unserialized )
                beg = unserialize_members( t, beg, end, R(), false );
            else
                beg = unserialize_members( t, beg, end, ap::type_list<C, R>() , false );
        }

        if (beg==end)
            throw unexpected_end_fragment();

        if ( *beg != '}' )
            throw expected_of("}", std::distance(beg, end));

        return beg;
    }
Ejemplo n.º 17
0
 R _parse_list(T& t, R r, empty_list)
 {
   return throw_t<_except_>( t, expected_of( typename string_list::left_type()(), distance(r) ), r );;
 }
Ejemplo n.º 18
0
 std::pair<R, RO> _copy_list(T& t, R r, empty_list, RO ro)
 {
   return throw_t<_except_>( t, expected_of( typename string_list::left_type()(), distance(r) ), r, ro );
 }
Ejemplo n.º 19
0
  std::pair<R, RD> operator()(T& t, R r, RD rd)
  {
    std::pair<R, RD> rr(r, rd);
    if (!rr.first)
      return throw_( t, unexpected_end_fragment(), rr.first, rr.second );
      

    if (*rr.first!='{') 
      return throw_( t, expected_of("{",  distance(rr.first) ), rr.first, rr.second );

    if ( !rr.second )
      return throw_( t, out_of_range( distance(rr.first) ), rr.first, rr.second );
    
    *(rr.second++) = *(rr.first++);
    
    rr = t.get_aspect().template get<_space_>()(t, rr.first, rr.second);
    
    if ( !try_(t) )
      return rr;
    
    for ( ; rr.first && *rr.first!='}'; )
    {
      rr = t.get_aspect().template get<_field_>()(t, rr.first, rr.second);
      
      if ( !try_(t) )
        return rr;
      
      rr = t.get_aspect().template get<_space_>()(t, rr.first, rr.second);
      
      if ( !try_(t) )
        return rr;
      
      if (!rr.first)
        return throw_( t, unexpected_end_fragment(), rr.first, rr.second );
      
      if (*rr.first == ',')
      {
        if ( !rr.second )
          return throw_( t, out_of_range( distance(rr.first) ), rr.first, rr.second );
        
        *(rr.second++) = *(rr.first++);
        
        rr = t.get_aspect().template get<_space_>()(t, rr.first, rr.second);
        
        if ( !try_(t) )
          return rr;
      }
      else if (*rr.first != '}')
        return throw_( t, expected_of("}",  distance(rr.first) ), rr.first, rr.second );
    }

    if (!rr.first)
      return throw_( t, unexpected_end_fragment(), rr.first, rr.second );

    if ( !rr.second )
      return throw_( t, out_of_range( distance(rr.first) ), rr.first, rr.second );

    *(rr.second++) = *(rr.first++);
    
    return rr;
  }