mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1666 CommandFile: Add line numbers to parse messages
This commit is contained in:
@@ -5,6 +5,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifcCommandFileReader.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfMessages.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -13,6 +14,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifcCommandFileReader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfMessages.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
@@ -29,15 +29,15 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
|
||||
{
|
||||
fieldValue = "";
|
||||
|
||||
inputStream.skipWhiteSpace();
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||
QString accumulatedFieldValue;
|
||||
QChar currentChar;
|
||||
inputStream >> currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
if ( currentChar == QChar('"') )
|
||||
{
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
if ( currentChar != QChar('\\') )
|
||||
{
|
||||
if ( currentChar == QChar('"') ) // End Quote
|
||||
@@ -52,7 +52,7 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
|
||||
}
|
||||
else
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
accumulatedFieldValue += currentChar;
|
||||
}
|
||||
}
|
||||
|
||||
67
ApplicationCode/CommandFileInterface/Core/RicfMessages.cpp
Normal file
67
ApplicationCode/CommandFileInterface/Core/RicfMessages.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#include "RicfMessages.h"
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfMessages::addWarning(const QString& message)
|
||||
{
|
||||
m_messages.push_back(std::make_pair(WARNING, "Line " + QString::number(m_currentLineNumber) +": " + message));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfMessages::addError(const QString& message)
|
||||
{
|
||||
m_messages.push_back(std::make_pair(ERROR, "Line " + QString::number(m_currentLineNumber) +": " + message));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfMessages::skipWhiteSpaceWithLineNumberCount(QTextStream& inputStream)
|
||||
{
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
QChar ch = readCharWithLineNumberCount(inputStream);
|
||||
if ( !ch.isSpace() )
|
||||
{
|
||||
inputStream.seek(inputStream.pos()-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QChar RicfMessages::readCharWithLineNumberCount(QTextStream& inputStream)
|
||||
{
|
||||
QChar ch;
|
||||
inputStream >> ch;
|
||||
if ( ch == QChar('\n') )
|
||||
{
|
||||
m_currentLineNumber++;
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
@@ -15,26 +15,36 @@
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
|
||||
class QTextStream;
|
||||
|
||||
class RicfMessages
|
||||
{
|
||||
public:
|
||||
RicfMessages() : m_currentLineNumber(1) {}
|
||||
|
||||
enum MessageType
|
||||
{
|
||||
WARNING,
|
||||
ERROR
|
||||
};
|
||||
|
||||
void addWarning(const QString& message) { m_messages.push_back(std::make_pair(WARNING, message));}
|
||||
void addError(const QString& message) { m_messages.push_back(std::make_pair(ERROR, message));}
|
||||
void addWarning(const QString& message);
|
||||
void addError(const QString& message);
|
||||
|
||||
void skipWhiteSpaceWithLineNumberCount(QTextStream& inputStream);
|
||||
QChar readCharWithLineNumberCount(QTextStream& inputStream);
|
||||
|
||||
QString currentCommand;
|
||||
QString currentArgument;
|
||||
std::vector<std::pair<MessageType, QString> > m_messages;
|
||||
|
||||
private:
|
||||
int m_currentLineNumber;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -59,17 +59,17 @@ void RicfObjectCapability::readFields(QTextStream& inputStream,
|
||||
bool isEndOfArgumentFound = false;
|
||||
QString keyword;
|
||||
{
|
||||
inputStream.skipWhiteSpace();
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
QChar currentChar;
|
||||
inputStream >> currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
if ( currentChar.isSpace() )
|
||||
{
|
||||
// Must skip to, and read "="
|
||||
|
||||
inputStream.skipWhiteSpace();
|
||||
inputStream >> currentChar;
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
|
||||
if ( currentChar != QChar('=') )
|
||||
{
|
||||
@@ -135,7 +135,7 @@ void RicfObjectCapability::readFields(QTextStream& inputStream,
|
||||
bool isOutsideQuotes = true;
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
if ( isOutsideQuotes )
|
||||
{
|
||||
if ( currentChar == QChar(',') )
|
||||
@@ -162,7 +162,7 @@ void RicfObjectCapability::readFields(QTextStream& inputStream,
|
||||
|
||||
if ( currentChar == QChar('\\') )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,22 +37,21 @@ std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands(QTextStream&
|
||||
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
inputStream.skipWhiteSpace();
|
||||
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||
// Read command name
|
||||
QString commandName;
|
||||
bool foundStartBracet = false;
|
||||
{
|
||||
inputStream.skipWhiteSpace();
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
QChar currentChar;
|
||||
inputStream >> currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
if ( currentChar.isSpace() )
|
||||
{
|
||||
inputStream.skipWhiteSpace();
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||
QChar isBracket('a');
|
||||
inputStream >> isBracket;
|
||||
isBracket = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
if ( isBracket != QChar('(') )
|
||||
{
|
||||
// Error, could not find start bracket for command
|
||||
@@ -84,7 +83,7 @@ std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands(QTextStream&
|
||||
bool isOutsideQuotes = true;
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
if ( isOutsideQuotes )
|
||||
{
|
||||
if ( currentChar == QChar(')') )
|
||||
@@ -105,7 +104,7 @@ std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands(QTextStream&
|
||||
|
||||
if ( currentChar == QChar('\\') )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user