コード例 #1
0
toSyntaxAnalyzer::statementList toSyntaxAnalyzerOracle::getStatements(const QString& text)
{
    toSyntaxAnalyzer::statementList retval;
    std::string str(text.toStdString());
    try
    {
        std::unique_ptr <SQLLexer::Lexer> lexer = LexerFactTwoParmSing::Instance().create("OracleGuiLexer", "", "toCustomLexer");
        lexer->setStatement(str.c_str(), (int)str.length());

        SQLLexer::Lexer::token_const_iterator start = lexer->begin();
        start = lexer->findStartToken(start);
        while (start->getTokenType() != SQLLexer::Token::X_EOF)
        {
            SQLLexer::Lexer::token_const_iterator end = lexer->findEndToken(start);
            retval << statement(
                       start->getPosition().getLine(),
                       end->getPosition().getLine());
            start = lexer->findStartToken(end);
        }
    }
    catch (std::exception const &e)
    {
        std::string s(e.what());
        std::cout << s << std::endl;
    }
    catch (QString const& e)
    {
        qDebug() << e;
    }
    catch (...)
    {
        qDebug() << __FUNCTION__ ;
    }
    return retval;
}
コード例 #2
0
ファイル: tosqltext.cpp プロジェクト: doniexun/tora
bool toSqlText::showToolTip(toSqlText::ToolTipData const& t)
{
    int start_pos = SendScintilla(QsciScintilla::SCI_POSITIONFROMLINE, t.line);
    int end_pos   = SendScintilla(QsciScintilla::SCI_GETLINEENDPOSITION, t.line);

    int word_len = end_pos - start_pos;
    if (word_len <= 0)
        return false;

    char *buf = new char[word_len + 1];
    SendScintilla(SCI_GETTEXTRANGE, start_pos, end_pos, buf);
    QString word = convertTextS2Q(buf);

    std::unique_ptr <SQLLexer::Lexer> lexer(LexerFactTwoParmSing::Instance().create("OracleGuiLexer", "", "toSqlText::showToolTip"));
    lexer->setStatement(buf, word_len + 1);
    SQLLexer::Lexer::token_const_iterator i = lexer->begin();
    QString toolTipText;

    long offset = t.textPosition - start_pos;

    do
    {
		if (i->getPosition().getLinePos() > offset)
			break;
		toolTipText  = i->getText();
        toolTipText += i->getPosition().toString();
        toolTipText += '(' + i->getTokenTypeName() + '/' + i->_mOrigTypeText + ')';
        i++;
    }
    while(i != lexer->end());

    QToolTip::showText(t.globalPos, toolTipText, viewport(), t.rect);

    delete[] buf;

    return true;
}
コード例 #3
0
toSyntaxAnalyzer::statement toSyntaxAnalyzerOracle::getStatementAt(unsigned line, unsigned linePos)
{
    toSyntaxAnalyzer::statement retval;

    toScintilla *editor = qobject_cast<toScintilla *>(parent());
    std::string str(editor->text().toStdString());
    try
    {
        std::unique_ptr <SQLLexer::Lexer> lexer = LexerFactTwoParmSing::Instance().create("OracleGuiLexer", "", "toCustomLexer");
        lexer->setStatement(str.c_str(), (int)str.length());

        SQLLexer::Lexer::token_const_iterator start = lexer->begin();
        start = lexer->findStartToken(start);
        while (start->getTokenType() != SQLLexer::Token::X_EOF)
        {
            SQLLexer::Lexer::token_const_iterator end = lexer->findEndToken(start);
            SQLLexer::Lexer::token_const_iterator nextStart = lexer->findStartToken(end);
            if (end->getPosition().getLine() < line)
            {
                start = nextStart;
                continue;
            }

            // The statement was found - setup retval
            toScintilla *editor = qobject_cast<toScintilla *>(parent());
            retval = statement(
                         start->getPosition().getLine(),
                         end->getPosition().getLine());

            retval.firstWord = start->getText();
            retval.posFrom = editor->positionFromLineIndex(start->getPosition().getLine()
                             , start->getPosition().getLinePos());
            retval.posTo   = editor->positionFromLineIndex(end->getPosition().getLine()
                             , end->getPosition().getLinePos() + ( end->getTokenType() == SQLLexer::Token::X_EOL ? 0 : end->getLength()));
            switch (start->getTokenType())
            {
                case SQLLexer::Token::L_LPAREN:
                case SQLLexer::Token::L_DML_INTRODUCER:		// INSERT/UPDATE/DELETE/MERGE
                    retval.statementType = DML;
                    break;
                case SQLLexer::Token::L_SELECT_INTRODUCER:
                    retval.statementType = SELECT;
                    break;
                case SQLLexer::Token::L_PL_INTRODUCER:
                    retval.statementType = PLSQL;
                    break;
                case SQLLexer::Token::L_OTHER_INTRODUCER:
                    retval.statementType = OTHER;
                    break;
                case SQLLexer::Token::X_ONE_LINE:
                    retval.statementType = SQLPLUS;
                    break;
                default:
                    //	        DDL,        // CREATE
                    //	        OTHER,      // ALTER SESSION ..., ANALYZE, SET ROLE, EXPLAIN
                    //	        SQLPLUS		// sqlplus command
                    retval.statementType = UNKNOWN;
                    break;
            }
            return retval;
        }
    }
    catch (std::exception const &e)
    {
        std::string s(e.what());
        std::cout << s << std::endl;
    }
    catch (QString const& e)
    {
        qDebug() << e;
    }
    catch (...)
    {
        qDebug() << __FUNCTION__ ;
    }
    return retval;
}