Qualifier* Sintactico::ParseQualifier()
{
	//Utilizamos Primeros(field-specifier) y Primeros( index )
	if ( proximo_token.GetTipo() == punt_punto )
	{
		return ParseFieldSpecifier();
	}
	else if ( proximo_token.GetTipo() == punt_corchizq )
	{
		return ParseIndex();
	}
	else throw SyntaxException("Falta token de cualificador",analizador_lexico->GetLineaActual() );
}
void PacketStreamReader::SetupIndex()
{
    if (!_stream.seekable())
        return;

    auto pos = _stream.tellg();
    _stream.seekg(-(static_cast<istream::off_type>(sizeof(uint64_t)) + TAG_LENGTH), ios_base::end); //a footer is a tag + index position. //todo: this will choke on trailing whitespace. Make it not choke on trailing whitespace.
    //todo also: this will break if the footer size changes. Make this more dynamic.

    if (_stream.peekTag() == TAG_PANGO_FOOTER)
    {
        _stream.seekg(ParseFooter()); //parsing the footer returns the index position
        if (_stream.peekTag() == TAG_PANGO_STATS)
            ParseIndex();
    }

    _stream.clear();
    _stream.seekg(pos);
}
PacketStreamReader::FrameInfo PacketStreamReader::_nextFrame()
{
    while (1)
    {
        auto t = _stream.peekTag();

        switch (t)
        {
        case TAG_PANGO_SYNC:
            SkipSync();
            break;
        case TAG_ADD_SOURCE:
            ParseNewSource();
            break;
        case TAG_SRC_JSON: //frames are sometimes preceded by metadata, but metadata must ALWAYS be followed by a frame from the same source.
        case TAG_SRC_PACKET:
            return _stream.peekFrameHeader(*this);
        case TAG_PANGO_STATS:
            ParseIndex();
            break;
        case TAG_PANGO_FOOTER: //end of frames
        case TAG_END:
            return FrameInfo(); //none
        case TAG_PANGO_HDR: //shoudln't encounter this
            ParseHeader();
            break;
        case TAG_PANGO_MAGIC: //or this
            SkipSync();
            break;
        default: //or anything else
            pango_print_warn("Unexpected packet type: \"%s\". Resyncing()\n", tagName(t).c_str());
            ReSync();
            break;
        }
    }

}
Пример #4
0
/*
================
idAASFileLocal::Load
================
*/
bool idAASFileLocal::Load( const idStr &fileName, unsigned int mapFileCRC )
{
    idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES );
    idToken token;
    int depth;
    unsigned int c;

    name = fileName;
    crc = mapFileCRC;

    common->Printf( "[Load AAS]\n" );
    common->Printf( "loading %s\n", name.c_str() );

    if ( !src.LoadFile( name ) )
    {
        return false;
    }

    if ( !src.ExpectTokenString( AAS_FILEID ) )
    {
        common->Warning( "Not an AAS file: '%s'", name.c_str() );
        return false;
    }

    if ( !src.ReadToken( &token ) || token != AAS_FILEVERSION )
    {
        common->Warning( "AAS file '%s' has version %s instead of %s", name.c_str(), token.c_str(), AAS_FILEVERSION );
        return false;
    }

    if ( !src.ExpectTokenType( TT_NUMBER, TT_INTEGER, &token ) )
    {
        common->Warning( "AAS file '%s' has no map file CRC", name.c_str() );
        return false;
    }

    c = token.GetUnsignedIntValue();
    if ( mapFileCRC && c != mapFileCRC )
    {
        common->Warning( "AAS file '%s' is out of date", name.c_str() );
        return false;
    }

    // clear the file in memory
    Clear();

    // parse the file
    while ( 1 )
    {
        if ( !src.ReadToken( &token ) )
        {
            break;
        }

        if ( token == "settings" )
        {
            if ( !settings.FromParser( src ) )
            {
                return false;
            }
        }
        else if ( token == "planes" )
        {
            if ( !ParsePlanes( src ) )
            {
                return false;
            }
        }
        else if ( token == "vertices" )
        {
            if ( !ParseVertices( src ) )
            {
                return false;
            }
        }
        else if ( token == "edges" )
        {
            if ( !ParseEdges( src ) )
            {
                return false;
            }
        }
        else if ( token == "edgeIndex" )
        {
            if ( !ParseIndex( src, edgeIndex ) )
            {
                return false;
            }
        }
        else if ( token == "faces" )
        {
            if ( !ParseFaces( src ) )
            {
                return false;
            }
        }
        else if ( token == "faceIndex" )
        {
            if ( !ParseIndex( src, faceIndex ) )
            {
                return false;
            }
        }
        else if ( token == "areas" )
        {
            if ( !ParseAreas( src ) )
            {
                return false;
            }
        }
        else if ( token == "nodes" )
        {
            if ( !ParseNodes( src ) )
            {
                return false;
            }
        }
        else if ( token == "portals" )
        {
            if ( !ParsePortals( src ) )
            {
                return false;
            }
        }
        else if ( token == "portalIndex" )
        {
            if ( !ParseIndex( src, portalIndex ) )
            {
                return false;
            }
        }
        else if ( token == "clusters" )
        {
            if ( !ParseClusters( src ) )
            {
                return false;
            }
        }
        else
        {
            src.Error( "idAASFileLocal::Load: bad token \"%s\"", token.c_str() );
            return false;
        }
    }

    FinishAreas();

    depth = MaxTreeDepth();
    if ( depth > MAX_AAS_TREE_DEPTH )
    {
        src.Error( "idAASFileLocal::Load: tree depth = %d", depth );
    }

    common->Printf( "done.\n" );

    return true;
}