Пример #1
0
void Method::applyAttribute(const std::string& attribute)
{
	std::string key;
	std::string value;

	splitAttribute(attribute, key, value);

	// Don`t process empty attributes
	if(key.size() == 0) return;

	// Convert key to lowercase for easier comparison
	std::transform(key.begin(), key.end(), key.begin(), ::tolower);

	// Export method as event
	if(key.compare("event") == 0)
	{
		m_isEvent = true;
	}
	// Place method in a specific category
	else if(key.compare("category") == 0)
	{
		utils::replaceAll(value, "\"", "");
		m_category = value;
		m_category = utils::trim(m_category);
	}
	// This attribute cannot be set for methods
	else
	{
		std::cout << "Warning: Ignored unrecognized method attribute \"" << key << "\"" << std::endl;
	}
}
Пример #2
0
Lexer::Token Fn::parseAttributes( Lexer* lexer )
{
    Lexer::Token tok( document->getNextToken() );
    while( tok != Lexer::TAGEND ) {
        if( tok == Lexer::ATTRIBUTE ) {
            std::wstring key;
            std::wstring value;
            splitAttribute( lexer->text(), key, value );
            if( key == L"id" ) {
                id = new GlobalDictionaryWord( value );
                id->toUpper();          //to uppercase
                if( !document->isInf() )
                    id = document->addWord( id );
            }
            else
                document->printError( ERR1_ATTRNOTDEF );
        }
        else if( tok == Lexer::FLAG )
                document->printError( ERR1_ATTRNOTDEF );
        else if( tok == Lexer::ERROR_TAG )
            throw FatalError( ERR_SYNTAX );
        else if( tok == Lexer::END )
            throw FatalError( ERR_EOF );
        else
            document->printError( ERR1_TAGSYNTAX );
        tok = document->getNextToken();
    }
    if( !id )
        document->printError( ERR1_NOFNID );
    return document->getNextToken();    //consume TAGEND
}
Пример #3
0
Lexer::Token Rm::parse( Lexer* lexer )
{
    Lexer::Token tok( document->getNextToken() );
    while( tok != Lexer::TAGEND ) {
        //parse attributes
        if( tok == Lexer::ATTRIBUTE ) {
            std::wstring key;
            std::wstring value;
            splitAttribute( lexer->text(), key, value );
            if( key == L"margin" ) {
                long int tmp( std::wcstol( value.c_str(), 0, 10 ) );
                if( tmp < 1 )
                    tmp = 1;
                if( tmp > 255 )
                    tmp = 255;
                margin = static_cast< STD1::uint8_t >( tmp );
            }
            else
                document->printError( ERR1_ATTRNOTDEF );
        }
        else if( tok == Lexer::FLAG )
                document->printError( ERR1_ATTRNOTDEF );
        else if( tok == Lexer::ERROR_TAG )
            throw FatalError( ERR_SYNTAX );
        else if( tok == Lexer::END )
            throw FatalError( ERR_EOF );
        else
            document->printError( ERR1_TAGSYNTAX );
        tok = document->getNextToken();
    }
    return document->getNextToken();
}
Пример #4
0
Lexer::Token Font::parse( Lexer* lexer )
{
    FontEntry fnt;
    fnt.codePage = document->codePage();
    bool isDefault( false );
    Lexer::Token tok( document->getNextToken() );
    while( tok != Lexer::TAGEND ) {
        //parse attributes
        if( tok == Lexer::ATTRIBUTE ) {
            std::wstring key;
            std::wstring value;
            splitAttribute( lexer->text(), key, value );
            if( key == L"facename" ) {
                if( value == L"default" ) {
                    index = 0;
                    fnt.height = 0;
                    fnt.width = 0;
                    isDefault = true;
                }
                else if( std::wcstombs( &fnt.faceName[0], value.c_str(), sizeof( fnt.faceName ) / sizeof( char ) ) == static_cast< size_t >( -1 ) )
                    throw( ERR_T_CONV );
            }
            else if( key == L"size" ) {
                wchar_t *end;
                fnt.height = static_cast< STD1::uint16_t >( std::wcstoul( value.c_str(), &end, 10 ) );
                ++end;
                fnt.width =  static_cast< STD1::uint16_t >( std::wcstoul( end, &end, 10 ) );
                if( fnt.height == 0 || fnt.width == 0 ) {
                    index = 0;
                    fnt.height = 0;
                    fnt.width = 0;
                    isDefault = true;
                }
            }
            else if( key == L"codepage" )
                fnt.codePage = static_cast< STD1::uint16_t >( std::wcstoul( value.c_str(), 0, 10 ) );
            else
                document->printError( ERR1_ATTRNOTDEF );
        }
        else if( tok == Lexer::FLAG )
                document->printError( ERR1_ATTRNOTDEF );
        else if( tok == Lexer::ERROR_TAG )
            throw FatalError( ERR_SYNTAX );
        else if( tok == Lexer::END )
            throw FatalError( ERR_EOF );
        else
            document->printError( ERR1_TAGSYNTAX );
        tok = document->getNextToken();
    }
    if( !isDefault ) {
        try {
            index = static_cast< unsigned char >( document->addFont( fnt ) );
        }
        catch( Class2Error& e ) {
            document->printError( e.code );
        }
    }
    return document->getNextToken();
}
Пример #5
0
Lexer::Token Hdref::parse( Lexer* lexer )
{
    std::wstring refid;
    std::wstring res;
    Lexer::Token tok( document->getNextToken() );
    while( tok != Lexer::TAGEND ) {
        //parse attributes
        if( tok == Lexer::ATTRIBUTE ) {
            std::wstring key;
            std::wstring value;
            splitAttribute( lexer->text(), key, value );
            if( key == L"res" )
                res = value;
            else if( key == L"refid" )
                refid = value;
            else
                document->printError( ERR1_ATTRNOTDEF );
        }
        else if( tok == Lexer::FLAG )
            document->printError( ERR1_ATTRNOTDEF );
        else if( tok == Lexer::ERROR_TAG )
            throw FatalError( ERR_SYNTAX );
        else if( tok == Lexer::END )
            throw FatalError( ERR_EOF );
        else
            document->printError( ERR1_TAGSYNTAX );
        tok = document->getNextToken();
    }
    std::wstring temp( L":link reftype=hd" );
    if( !refid.empty() ) {
        temp += L" refid=";
        temp += refid;
    }
    if( !res.empty() ) {
        temp += L" res=";
        temp += res;
    }
    temp += L'.';
    temp += document->reference();
    temp += L":elink.";
    if( !refid.empty() || !res.empty() ) {
        std::wstring* fname( new std::wstring() );
        prepBufferName( fname, *( document->dataName() ) );
        fname = document->addFileName( fname );
        document->pushInput( new IpfBuffer( fname, document->dataLine(), document->dataCol(), temp ) );
        bool oldBlockParsing( document->blockParsing() );
        document->setBlockParsing( true );
        tok = document->getNextToken(); //first token from buffer
        while( tok != Lexer::END ) {
            if( parseInline( lexer, tok ) )
                parseCleanup( lexer, tok );
        }
        document->setBlockParsing( oldBlockParsing );
        document->popInput();
    }
    return document->getNextToken();    //next token from stream
}
Пример #6
0
Lexer::Token DocProf::parse( Lexer* lexer )
{
    Lexer::Token tok( document->getNextToken() );
    while( tok != Lexer::TAGEND ) {
        if( tok == Lexer::ATTRIBUTE ) {
            std::wstring key;
            std::wstring value;
            splitAttribute( lexer->text(), key, value );
            if ( key == L"toc" ) {
                wchar_t ch[ 2 ];
                ch[ 0 ] = value[ value.size() - 1 ];    //last number is critical value
                ch[ 1 ] = L'\0';
                int tmp( static_cast<int>( std::wcstol( ch, 0, 10 ) ) );
                if( tmp < 1 || tmp > 6 )
                    document->printError( ERR2_VALUE );
                else
                    headerCutOff = static_cast< unsigned int >( tmp );
            }
            else if( key == L"objectname" )
                objName = value;
            else if( key == L"dll" )
                dll = value;
            else if ( key == L"objectinfo" )
                objInfo = value ;
            else if( key == L"ctrlarea" ) {
                if( value == L"none" )
                    area = NONE;
                else if( value == L"coverpage" )
                    area = COVERPAGE;
                else if( value == L"page" )
                    area = PAGE;
                else if( value == L"both" )
                    area = BOTH;
                else
                    document->printError( ERR2_VALUE );
            }
            else
                document->printError( ERR1_ATTRNOTDEF );
        }
        else if ( tok == Lexer::FLAG )
            document->printError( ERR1_ATTRNOTDEF );
        else if( tok == Lexer::END )
            throw FatalError( ERR_EOF );
        else
            document->printError( ERR1_TAGSYNTAX );
        tok = document->getNextToken();
    }
    return document->getNextToken();
}
Пример #7
0
Lexer::Token I1::parseAttributes( Lexer* lexer )
{
    Lexer::Token tok( document->getNextToken() );
    while( tok != Lexer::TAGEND ) {
        if( tok == Lexer::ATTRIBUTE ) {
            std::wstring key;
            std::wstring value;
            splitAttribute( lexer->text(), key, value );
            if( key == L"id" ) {
                id = value;
                try {
                    document->addIndexId( id, this );
                }
                catch( Class3Error& e ) {
                    document->printError( e.code );
                }
            }
            else if( key == L"roots" ) {
                std::wstring::size_type idx1( 0 );
                std::wstring::size_type idx2( value.find( L' ' ) );
                while( idx1 != std::wstring::npos ) { //split value on ' '
                    synRoots.push_back( value.substr( idx1, idx2 - idx1 ) );
                    idx1 = idx2 == std::wstring::npos ? std::wstring::npos : idx2 + 1;
                    idx2 = value.find( L' ', idx1 );
                }
            }
            else if( key == L"sortkey" )
                primary->setSortKey( value );
            else
                document->printError( ERR1_ATTRNOTDEF );
        }
        else if( tok == Lexer::FLAG ) {
            if( lexer->text() == L"global" )
                primary->setGlobal();
            else
                document->printError( ERR1_ATTRNOTDEF );
        }
        else if( tok == Lexer::ERROR_TAG )
            throw FatalError( ERR_SYNTAX );
        else if( tok == Lexer::END )
            throw FatalError( ERR_EOF );
        else
            document->printError( ERR1_TAGSYNTAX );
        tok = document->getNextToken();
    }
    return document->getNextToken(); //consume TAGEND
}
Пример #8
0
Lexer::Token Caution::parse( Lexer* lexer )
{
    std::wstring temp;
    std::wstring* fname( new std::wstring() );
    prepBufferName( fname, *( document->dataName() ) );
    fname = document->addFileName( fname );
    Lexer::Token tok( document->getNextToken() );
    while( tok != Lexer::TAGEND ) {
        if( tok == Lexer::ATTRIBUTE ) {
            std::wstring key;
            std::wstring value;
            splitAttribute( lexer->text(), key, value );
            if( key == L"text" ) {
                temp = L":hp2.";
                temp += value;
                temp += L":ehp2.\n";
            }
            else
                document->printError( ERR1_ATTRNOTDEF );
        }
        else if( tok == Lexer::FLAG )
            document->printError( ERR1_ATTRNOTDEF );
        else if( tok == Lexer::ERROR_TAG )
            throw FatalError( ERR_SYNTAX );
        else if( tok == Lexer::END )
            throw FatalError( ERR_EOF );
        else
            document->printError( ERR1_TAGSYNTAX );
        tok = document->getNextToken();
    }
    if( temp.empty() ) {
        temp = L":hp2.";
        temp += document->caution();
        temp += L":ehp2.\n";
    }
    document->pushInput( new IpfBuffer( fname, document->dataLine(),
        document->dataCol(), temp ) );
    bool oldBlockParsing( document->blockParsing() );
    document->setBlockParsing( true );
    whiteSpace = Tag::LITERAL;
    appendChild( new P( document, this, document->dataName(), document->lexerLine(),
        document->lexerCol() ) );
    tok = document->getNextToken(); //first token from buffer
    while( tok != Lexer::END ) {
        if( parseInline( lexer, tok ) )
            parseCleanup( lexer, tok );
    }
    whiteSpace = Tag::NONE;
    document->setBlockParsing( oldBlockParsing );
    document->popInput();
    tok = document->getNextToken(); //next token from main stream
    while( tok != Lexer::END && !( tok == Lexer::TAG && lexer->tagId() == Lexer::EUSERDOC)) {
        if( parseInline( lexer, tok ) ) {
            if( lexer->tagId() == Lexer::ECAUTION )
                    break;
            else if( lexer->tagId() == Lexer::H1 ||
                lexer->tagId() == Lexer::H2 ||
                lexer->tagId() == Lexer::H3 ||
                lexer->tagId() == Lexer::H4 ||
                lexer->tagId() == Lexer::H5 ||
                lexer->tagId() == Lexer::H6 ||
                lexer->tagId() == Lexer::ACVIEWPORT ||
                lexer->tagId() == Lexer::FN )
                    parseCleanup( lexer, tok );
            else if( parseBlock( lexer, tok ) ) {
                if( parseListBlock( lexer, tok ) )
                    parseCleanup( lexer, tok );
            }
        }
    }
    return tok;
}