// THIS FILE IS GENERATED
// WARNING! All changes made in this file will be lost!

#include "qmakeparser.h"
#include "qmakeast.h"


# 148 "/chakra/desktop/kdevelop/src/kdevelop-5.3.3/plugins/qmakemanager/parser/qmake.g" 1

#include "qmakelexer.h"
#include <QString>
#include <debug.h>

namespace QMake
{

void Parser::tokenize( const QString& contents )
{
    m_contents = contents;
    QMake::Lexer lexer( this, contents );
    int kind = Parser::Token_EOF;

    do
    {
        kind = lexer.nextTokenKind();

        if ( !kind ) // when the lexer returns 0, the end of file is reached
            kind = Parser::Token_EOF;

        Parser::Token &t = this->tokenStream->push();
        t.kind = kind;
        if( t.kind == Parser::Token_EOF )
        {
            t.begin = -1;
            t.end = -1;
        }
        else
        {
            t.begin = lexer.tokenBegin();
            t.end = lexer.tokenEnd();
        }

        if( m_debug )
        {
            qCDebug(KDEV_QMAKE) << kind << "(" << t.begin << "," << t.end << ")::" << tokenText(t.begin, t.end);
        }

    }
    while ( kind != Parser::Token_EOF );

    this->yylex(); // produce the look ahead token
}

QString Parser::tokenText( qint64 begin, qint64 end ) const
{
    return m_contents.mid((int)begin, (int)end-begin+1);
}

void Parser::reportProblem( Parser::ProblemType type, const QString& message )
{
    if (type == Error)
        qCDebug(KDEV_QMAKE) << "** ERROR:" << message;
    else if (type == Warning)
        qCDebug(KDEV_QMAKE) << "** WARNING:" << message;
    else if (type == Info)
        qCDebug(KDEV_QMAKE) << "** Info:" << message;
}


// custom error recovery
void Parser::expectedToken(int /*expected*/, qint64 /*where*/, const QString& name)
{
    reportProblem(
        Parser::Error,
        QStringLiteral("Expected token \"%1\"").arg(name));
}

void Parser::expectedSymbol(int /*expected_symbol*/, const QString& name)
{
    qint64 line;
    qint64 col;
    size_t index = tokenStream->index()-1;
    Token &token = tokenStream->at(index);
    qCDebug(KDEV_QMAKE) << "token starts at:" << token.begin;
    qCDebug(KDEV_QMAKE) << "index is:" << index;
    tokenStream->startPosition(index, &line, &col);
    QString tokenValue = tokenText(token.begin, token.end);
    reportProblem(
        Parser::Error,
        QStringLiteral("Expected symbol \"%1\" (current token: \"%2\" [%3] at line: %4 col: %5)")
        .arg(name, token.kind != 0 ? tokenValue : QStringLiteral("EOF"))
        .arg(token.kind)
        .arg(line)
        .arg(col));
}

void Parser::setDebug( bool debug )
{
    m_debug = debug;
}

} // end of namespace QMake


namespace QMake
{

bool Parser::parseArgumentList(ArgumentListAst **yynode)
{
    *yynode = create<ArgumentListAst>();

    (*yynode)->startToken = tokenStream->index() - 1;

    if (yytoken == Token_CONT
        || yytoken == Token_VALUE || yytoken == Token_RPAREN)
    {
        if (yytoken == Token_CONT
            || yytoken == Token_VALUE)
        {
            if (yytoken == Token_VALUE)
            {
                ValueAst *__node_0 = nullptr;
                if (!parseValue(&__node_0))
                {
                    expectedSymbol(AstNode::ValueKind, QStringLiteral("value"));
                    return false;
                }
                (*yynode)->argsSequence = snoc((*yynode)->argsSequence, __node_0, memoryPool);

            }
            else if (yytoken == Token_CONT)
            {
                if (yytoken != Token_CONT)
                {
                    expectedToken(yytoken, Token_CONT, QStringLiteral("cont"));
                    return false;
                }
                yylex();

                if (yytoken != Token_NEWLINE)
                {
                    expectedToken(yytoken, Token_NEWLINE, QStringLiteral("newline"));
                    return false;
                }
                yylex();

            }
            else
            {
                return false;
            }
            while (yytoken == Token_COMMA
                   || yytoken == Token_CONT)
            {
                if (yytoken == Token_COMMA)
                {
                    if (yytoken != Token_COMMA)
                    {
                        expectedToken(yytoken, Token_COMMA, QStringLiteral("comma"));
                        return false;
                    }
                    yylex();

                }
                else if (yytoken == Token_CONT)
                {
                    if (yytoken != Token_CONT)
                    {
                        expectedToken(yytoken, Token_CONT, QStringLiteral("cont"));
                        return false;
                    }
                    yylex();

                    if (yytoken != Token_NEWLINE)
                    {
                        expectedToken(yytoken, Token_NEWLINE, QStringLiteral("newline"));
                        return false;
                    }
                    yylex();

                }
                else
                {
                    return false;
                }
                ValueAst *__node_1 = nullptr;
                if (!parseValue(&__node_1))
                {
                    expectedSymbol(AstNode::ValueKind, QStringLiteral("value"));
                    return false;
                }
                (*yynode)->argsSequence = snoc((*yynode)->argsSequence, __node_1, memoryPool);

            }
        }
        else if (true /*epsilon*/)
        {
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseFunctionArguments(FunctionArgumentsAst **yynode)
{
    *yynode = create<FunctionArgumentsAst>();

    (*yynode)->startToken = tokenStream->index() - 1;

    if (yytoken == Token_LPAREN)
    {
        if (yytoken != Token_LPAREN)
        {
            expectedToken(yytoken, Token_LPAREN, QStringLiteral("lparen"));
            return false;
        }
        yylex();

        ArgumentListAst *__node_2 = nullptr;
        if (!parseArgumentList(&__node_2))
        {
            expectedSymbol(AstNode::ArgumentListKind, QStringLiteral("argumentList"));
            return false;
        }
        (*yynode)->args = __node_2;

        if (yytoken != Token_RPAREN)
        {
            expectedToken(yytoken, Token_RPAREN, QStringLiteral("rparen"));
            return false;
        }
        yylex();

    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseItem(ItemAst **yynode)
{
    *yynode = create<ItemAst>();

    (*yynode)->startToken = tokenStream->index() - 1;
    (*yynode)->id = -1;

    if (yytoken == Token_IDENTIFIER)
    {
        if (yytoken != Token_IDENTIFIER)
        {
            expectedToken(yytoken, Token_IDENTIFIER, QStringLiteral("identifier"));
            return false;
        }
        (*yynode)->id = tokenStream->index() - 1;
        yylex();

        if (yytoken == Token_LPAREN)
        {
            FunctionArgumentsAst *__node_3 = nullptr;
            if (!parseFunctionArguments(&__node_3))
            {
                expectedSymbol(AstNode::FunctionArgumentsKind, QStringLiteral("functionArguments"));
                return false;
            }
            (*yynode)->functionArguments = __node_3;

        }
        else if (true /*epsilon*/)
        {
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseOp(OpAst **yynode)
{
    *yynode = create<OpAst>();

    (*yynode)->startToken = tokenStream->index() - 1;
    (*yynode)->optoken = -1;
    (*yynode)->optoken = -1;
    (*yynode)->optoken = -1;
    (*yynode)->optoken = -1;
    (*yynode)->optoken = -1;

    if (yytoken == Token_EQUAL
        || yytoken == Token_MINUSEQ
        || yytoken == Token_PLUSEQ
        || yytoken == Token_STAREQ
        || yytoken == Token_TILDEEQ)
    {
        if (yytoken == Token_PLUSEQ)
        {
            if (yytoken != Token_PLUSEQ)
            {
                expectedToken(yytoken, Token_PLUSEQ, QStringLiteral("pluseq"));
                return false;
            }
            (*yynode)->optoken = tokenStream->index() - 1;
            yylex();

        }
        else if (yytoken == Token_MINUSEQ)
        {
            if (yytoken != Token_MINUSEQ)
            {
                expectedToken(yytoken, Token_MINUSEQ, QStringLiteral("minuseq"));
                return false;
            }
            (*yynode)->optoken = tokenStream->index() - 1;
            yylex();

        }
        else if (yytoken == Token_STAREQ)
        {
            if (yytoken != Token_STAREQ)
            {
                expectedToken(yytoken, Token_STAREQ, QStringLiteral("stareq"));
                return false;
            }
            (*yynode)->optoken = tokenStream->index() - 1;
            yylex();

        }
        else if (yytoken == Token_EQUAL)
        {
            if (yytoken != Token_EQUAL)
            {
                expectedToken(yytoken, Token_EQUAL, QStringLiteral("equal"));
                return false;
            }
            (*yynode)->optoken = tokenStream->index() - 1;
            yylex();

        }
        else if (yytoken == Token_TILDEEQ)
        {
            if (yytoken != Token_TILDEEQ)
            {
                expectedToken(yytoken, Token_TILDEEQ, QStringLiteral("tildeeq"));
                return false;
            }
            (*yynode)->optoken = tokenStream->index() - 1;
            yylex();

        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseOrOperator(OrOperatorAst **yynode)
{
    *yynode = create<OrOperatorAst>();

    (*yynode)->startToken = tokenStream->index() - 1;

    if (yytoken == Token_OR)
    {
        do
        {
            if (yytoken != Token_OR)
            {
                expectedToken(yytoken, Token_OR, QStringLiteral("or"));
                return false;
            }
            yylex();

            ItemAst *__node_4 = nullptr;
            if (!parseItem(&__node_4))
            {
                expectedSymbol(AstNode::ItemKind, QStringLiteral("item"));
                return false;
            }
            (*yynode)->itemSequence = snoc((*yynode)->itemSequence, __node_4, memoryPool);

        }
        while (yytoken == Token_OR);
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseProject(ProjectAst **yynode)
{
    *yynode = create<ProjectAst>();

    (*yynode)->startToken = tokenStream->index() - 1;

    if (yytoken == Token_EXCLAM
        || yytoken == Token_IDENTIFIER
        || yytoken == Token_NEWLINE || yytoken == Token_EOF)
    {
        while (yytoken == Token_EXCLAM
               || yytoken == Token_IDENTIFIER
               || yytoken == Token_NEWLINE)
        {
            StatementAst *__node_5 = nullptr;
            if (!parseStatement(&__node_5))
            {
                expectedSymbol(AstNode::StatementKind, QStringLiteral("statement"));
                return false;
            }
            (*yynode)->statementsSequence = snoc((*yynode)->statementsSequence, __node_5, memoryPool);

        }
        if (Token_EOF != yytoken)
        {
            return false;
        }
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseScope(ScopeAst **yynode)
{
    *yynode = create<ScopeAst>();

    (*yynode)->startToken = tokenStream->index() - 1;

    if (yytoken == Token_COLON
        || yytoken == Token_LBRACE
        || yytoken == Token_LPAREN
        || yytoken == Token_OR)
    {
        if (yytoken == Token_LPAREN)
        {
            FunctionArgumentsAst *__node_6 = nullptr;
            if (!parseFunctionArguments(&__node_6))
            {
                expectedSymbol(AstNode::FunctionArgumentsKind, QStringLiteral("functionArguments"));
                return false;
            }
            (*yynode)->functionArguments = __node_6;

            if (yytoken == Token_COLON
                || yytoken == Token_LBRACE)
            {
                ScopeBodyAst *__node_7 = nullptr;
                if (!parseScopeBody(&__node_7))
                {
                    expectedSymbol(AstNode::ScopeBodyKind, QStringLiteral("scopeBody"));
                    return false;
                }
                (*yynode)->scopeBody = __node_7;

            }
            else if (yytoken == Token_OR)
            {
                OrOperatorAst *__node_8 = nullptr;
                if (!parseOrOperator(&__node_8))
                {
                    expectedSymbol(AstNode::OrOperatorKind, QStringLiteral("orOperator"));
                    return false;
                }
                (*yynode)->orOperator = __node_8;

                ScopeBodyAst *__node_9 = nullptr;
                if (!parseScopeBody(&__node_9))
                {
                    expectedSymbol(AstNode::ScopeBodyKind, QStringLiteral("scopeBody"));
                    return false;
                }
                (*yynode)->scopeBody = __node_9;

            }
            else if (true /*epsilon*/)
            {
            }
            else
            {
                return false;
            }
        }
        else if (yytoken == Token_COLON
                 || yytoken == Token_LBRACE
                 || yytoken == Token_OR)
        {
            if (yytoken == Token_OR)
            {
                OrOperatorAst *__node_10 = nullptr;
                if (!parseOrOperator(&__node_10))
                {
                    expectedSymbol(AstNode::OrOperatorKind, QStringLiteral("orOperator"));
                    return false;
                }
                (*yynode)->orOperator = __node_10;

            }
            else if (true /*epsilon*/)
            {
            }
            else
            {
                return false;
            }
            ScopeBodyAst *__node_11 = nullptr;
            if (!parseScopeBody(&__node_11))
            {
                expectedSymbol(AstNode::ScopeBodyKind, QStringLiteral("scopeBody"));
                return false;
            }
            (*yynode)->scopeBody = __node_11;

        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseScopeBody(ScopeBodyAst **yynode)
{
    *yynode = create<ScopeBodyAst>();

    (*yynode)->startToken = tokenStream->index() - 1;

    if (yytoken == Token_COLON
        || yytoken == Token_LBRACE)
    {
        if (yytoken == Token_LBRACE)
        {
            if (yytoken != Token_LBRACE)
            {
                expectedToken(yytoken, Token_LBRACE, QStringLiteral("lbrace"));
                return false;
            }
            yylex();

            if (yytoken == Token_NEWLINE)
            {
                if (yytoken != Token_NEWLINE)
                {
                    expectedToken(yytoken, Token_NEWLINE, QStringLiteral("newline"));
                    return false;
                }
                yylex();

            }
            else if (true /*epsilon*/)
            {
            }
            else
            {
                return false;
            }
            while (yytoken == Token_EXCLAM
                   || yytoken == Token_IDENTIFIER
                   || yytoken == Token_NEWLINE)
            {
                StatementAst *__node_12 = nullptr;
                if (!parseStatement(&__node_12))
                {
                    expectedSymbol(AstNode::StatementKind, QStringLiteral("statement"));
                    return false;
                }
                (*yynode)->statementsSequence = snoc((*yynode)->statementsSequence, __node_12, memoryPool);

            }
            if (yytoken != Token_RBRACE)
            {
                expectedToken(yytoken, Token_RBRACE, QStringLiteral("rbrace"));
                return false;
            }
            yylex();

        }
        else if (yytoken == Token_COLON)
        {
            if (yytoken != Token_COLON)
            {
                expectedToken(yytoken, Token_COLON, QStringLiteral("colon"));
                return false;
            }
            yylex();

            StatementAst *__node_13 = nullptr;
            if (!parseStatement(&__node_13))
            {
                expectedSymbol(AstNode::StatementKind, QStringLiteral("statement"));
                return false;
            }
            (*yynode)->statementsSequence = snoc((*yynode)->statementsSequence, __node_13, memoryPool);

        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseStatement(StatementAst **yynode)
{
    *yynode = create<StatementAst>();

    (*yynode)->startToken = tokenStream->index() - 1;
    (*yynode)->id = -1;
    (*yynode)->id = -1;

    if (yytoken == Token_EXCLAM
        || yytoken == Token_IDENTIFIER
        || yytoken == Token_NEWLINE)
    {
        if (yytoken == Token_IDENTIFIER)
        {
            if (yytoken != Token_IDENTIFIER)
            {
                expectedToken(yytoken, Token_IDENTIFIER, QStringLiteral("identifier"));
                return false;
            }
            (*yynode)->id = tokenStream->index() - 1;
            yylex();

            if (yytoken == Token_EQUAL
                || yytoken == Token_MINUSEQ
                || yytoken == Token_PLUSEQ
                || yytoken == Token_STAREQ
                || yytoken == Token_TILDEEQ)
            {
                VariableAssignmentAst *__node_14 = nullptr;
                if (!parseVariableAssignment(&__node_14))
                {
                    expectedSymbol(AstNode::VariableAssignmentKind, QStringLiteral("variableAssignment"));
                    return false;
                }
                (*yynode)->var = __node_14;

            }
            else if (yytoken == Token_COLON
                     || yytoken == Token_LBRACE
                     || yytoken == Token_LPAREN
                     || yytoken == Token_OR)
            {
                ScopeAst *__node_15 = nullptr;
                if (!parseScope(&__node_15))
                {
                    expectedSymbol(AstNode::ScopeKind, QStringLiteral("scope"));
                    return false;
                }
                (*yynode)->scope = __node_15;

            }
            else
            {
                return false;
            }

# 94 "/chakra/desktop/kdevelop/src/kdevelop-5.3.3/plugins/qmakemanager/parser/qmake.g" 1

            (*yynode)->isNewline = false;
            (*yynode)->isExclam = false;
        }
        else if (yytoken == Token_EXCLAM)
        {
            if (yytoken != Token_EXCLAM)
            {
                expectedToken(yytoken, Token_EXCLAM, QStringLiteral("exclam"));
                return false;
            }
            yylex();

            if (yytoken != Token_IDENTIFIER)
            {
                expectedToken(yytoken, Token_IDENTIFIER, QStringLiteral("identifier"));
                return false;
            }
            (*yynode)->id = tokenStream->index() - 1;
            yylex();

            ScopeAst *__node_16 = nullptr;
            if (!parseScope(&__node_16))
            {
                expectedSymbol(AstNode::ScopeKind, QStringLiteral("scope"));
                return false;
            }
            (*yynode)->scope = __node_16;


# 99 "/chakra/desktop/kdevelop/src/kdevelop-5.3.3/plugins/qmakemanager/parser/qmake.g" 1

            (*yynode)->isNewline = false;
            (*yynode)->isExclam = true;
        }
        else if (yytoken == Token_NEWLINE)
        {
            if (yytoken != Token_NEWLINE)
            {
                expectedToken(yytoken, Token_NEWLINE, QStringLiteral("newline"));
                return false;
            }
            yylex();


# 104 "/chakra/desktop/kdevelop/src/kdevelop-5.3.3/plugins/qmakemanager/parser/qmake.g" 1

            (*yynode)->isNewline = true;
            (*yynode)->isExclam = false;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseValue(ValueAst **yynode)
{
    *yynode = create<ValueAst>();

    (*yynode)->startToken = tokenStream->index() - 1;
    (*yynode)->value = -1;

    if (yytoken == Token_VALUE)
    {
        if (yytoken != Token_VALUE)
        {
            expectedToken(yytoken, Token_VALUE, QStringLiteral("value"));
            return false;
        }
        (*yynode)->value = tokenStream->index() - 1;
        yylex();

    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseValueList(ValueListAst **yynode)
{
    *yynode = create<ValueListAst>();

    (*yynode)->startToken = tokenStream->index() - 1;

    if (yytoken == Token_CONT
        || yytoken == Token_VALUE)
    {
        do
        {
            if (yytoken == Token_VALUE)
            {
                ValueAst *__node_17 = nullptr;
                if (!parseValue(&__node_17))
                {
                    expectedSymbol(AstNode::ValueKind, QStringLiteral("value"));
                    return false;
                }
                (*yynode)->listSequence = snoc((*yynode)->listSequence, __node_17, memoryPool);

            }
            else if (yytoken == Token_CONT)
            {
                if (yytoken != Token_CONT)
                {
                    expectedToken(yytoken, Token_CONT, QStringLiteral("cont"));
                    return false;
                }
                yylex();

                if (yytoken != Token_NEWLINE)
                {
                    expectedToken(yytoken, Token_NEWLINE, QStringLiteral("newline"));
                    return false;
                }
                yylex();

            }
            else
            {
                return false;
            }
        }
        while (yytoken == Token_CONT
               || yytoken == Token_VALUE);
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}

bool Parser::parseVariableAssignment(VariableAssignmentAst **yynode)
{
    *yynode = create<VariableAssignmentAst>();

    (*yynode)->startToken = tokenStream->index() - 1;

    if (yytoken == Token_EQUAL
        || yytoken == Token_MINUSEQ
        || yytoken == Token_PLUSEQ
        || yytoken == Token_STAREQ
        || yytoken == Token_TILDEEQ)
    {
        OpAst *__node_18 = nullptr;
        if (!parseOp(&__node_18))
        {
            expectedSymbol(AstNode::OpKind, QStringLiteral("op"));
            return false;
        }
        (*yynode)->op = __node_18;

        if (yytoken == Token_CONT
            || yytoken == Token_VALUE)
        {
            ValueListAst *__node_19 = nullptr;
            if (!parseValueList(&__node_19))
            {
                expectedSymbol(AstNode::ValueListKind, QStringLiteral("valueList"));
                return false;
            }
            (*yynode)->values = __node_19;

            if (yytoken == Token_NEWLINE)
            {
                if (yytoken != Token_NEWLINE)
                {
                    expectedToken(yytoken, Token_NEWLINE, QStringLiteral("newline"));
                    return false;
                }
                yylex();

            }
            else if (true /*epsilon*/)
            {
            }
            else
            {
                return false;
            }
        }
        else if (yytoken == Token_NEWLINE)
        {
            if (yytoken != Token_NEWLINE)
            {
                expectedToken(yytoken, Token_NEWLINE, QStringLiteral("newline"));
                return false;
            }
            yylex();

        }
        else if (true /*epsilon*/)
        {
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }

    (*yynode)->endToken = tokenStream->index() - 2;

    return true;
}


} // end of namespace QMake

