<commit_before>//==============================================================================
// Computer parser class
//==============================================================================
// Note #1: after retrieving/parsing something, we must get ready for the next
//          task and this means getting the next token. Indeed, doing so means
//          that the next task doesn't have to worry about whether the current
//          token is the correct one or not...
// Note #2: the parser is based on the YACC description of the ANSI C language:
//          http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
//==============================================================================


#include "computerparser.h"
#include "computerscanner.h"

//==============================================================================

namespace OpenCOR {
namespace Computer {

//==============================================================================

ComputerParser::ComputerParser() :
    mErrors(ComputerErrors())
{
    // Create a scanner

    mScanner = new ComputerScanner();
}

//==============================================================================

ComputerParser::~ComputerParser()
{
    // Delete some internal objects

    delete mScanner;
}

//==============================================================================

ComputerScanner * ComputerParser::scanner()
{
    // Return the computer parser's scanner

    return mScanner;
}

//==============================================================================

ComputerErrors ComputerParser::errors()
{
    // Return the computer parser's error(s)

    return mErrors;
}

//==============================================================================

void ComputerParser::addError(const QString &pMessage,
                              const bool &pExpectedMessage,
                              const bool &pUseCurrentToken,
                              const ComputerScannerToken &pOtherToken,
                              const QString &pExtraInformation)
{
    ComputerScannerToken token = pUseCurrentToken?mScanner->token():pOtherToken;

    if (pExpectedMessage) {
        // First, check that there isn't already an error for that line/column
        // combination

        int tokenLine = token.line();
        int tokenColumn = token.column();

        foreach (const ComputerError &error, mErrors)
            if ((error.line() == tokenLine) && (error.column() == tokenColumn))
                // There is already an error for that line line/column
                // combination, so...

                return;

        mErrors.append(ComputerError(tr("%1 was expected, but '%2' was found instead").arg(pMessage, token.string()),
                                     tokenLine, tokenColumn));
    } else {
        mErrors.append(ComputerError(pMessage, token.line(), token.column(),
                                     pExtraInformation));
    }
}

//==============================================================================<commit_msg>Minor improvement to our 'C' parser.<commit_after>//==============================================================================
// Computer parser class
//==============================================================================
// Note #1: after retrieving/parsing something, we must get ready for the next
//          task and this means getting the next token. Indeed, doing so means
//          that the next task doesn't have to worry about whether the current
//          token is the correct one or not...
// Note #2: the parser is based on the YACC description of the ANSI C language:
//          http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
//==============================================================================


#include "computerparser.h"
#include "computerscanner.h"

//==============================================================================

namespace OpenCOR {
namespace Computer {

//==============================================================================

ComputerParser::ComputerParser() :
    mErrors(ComputerErrors())
{
    // Create a scanner

    mScanner = new ComputerScanner();
}

//==============================================================================

ComputerParser::~ComputerParser()
{
    // Delete some internal objects

    delete mScanner;
}

//==============================================================================

ComputerScanner * ComputerParser::scanner()
{
    // Return the computer parser's scanner

    return mScanner;
}

//==============================================================================

ComputerErrors ComputerParser::errors()
{
    // Return the computer parser's error(s)

    return mErrors;
}

//==============================================================================

void ComputerParser::addError(const QString &pMessage,
                              const bool &pExpectedMessage,
                              const bool &pUseCurrentToken,
                              const ComputerScannerToken &pOtherToken,
                              const QString &pExtraInformation)
{
    ComputerScannerToken token = pUseCurrentToken?mScanner->token():pOtherToken;

    if (pExpectedMessage) {
        // First, check that there isn't already an error for that line/column
        // combination

        int tokenLine = token.line();
        int tokenColumn = token.column();

        foreach (const ComputerError &error, mErrors)
            if ((error.line() == tokenLine) && (error.column() == tokenColumn))
                // There is already an error for that line line/column
                // combination, so...

                return;

        mErrors.append(ComputerError(tr("%1 was expected, but '%2' was found instead").arg(pMessage, (token.symbol() == ComputerScannerToken::Eof)?"EoF":token.string()),
                                     tokenLine, tokenColumn));
    } else {
        mErrors.append(ComputerError(pMessage, token.line(), token.column(),
                                     pExtraInformation));
    }
}

//==============================================================================
{'fraction_non_alphanumeric': 0.3311300983395131, 'fraction_numerical': 0.0012896985329679186, 'mean_word_length': 3.191891891891892, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6980041', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1241, 'n_words': 368}