Move Diagnostics to separate namespace
This commit is contained in:
parent
88df299e14
commit
e07d5cb7cb
|
@ -77,7 +77,7 @@ namespace Porygon::Binder {
|
|||
auto key = assignment.GetKey();
|
||||
return new BoundAssignmentStatement(key, boundExpression);
|
||||
} else {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::CantAssignVariable, statement->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantAssignVariable, statement->GetStartPosition(),
|
||||
statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ namespace Porygon::Binder {
|
|||
auto boundIndexType = indexable->GetType();
|
||||
if (boundIndexType->GetClass() != TypeClass::Error &&
|
||||
boundIndexType->operator!=(valueExpression->GetType().get())) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::InvalidTableValueType,
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::InvalidTableValueType,
|
||||
statement->GetStartPosition(), statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ namespace Porygon::Binder {
|
|||
auto var = parameters->at(i);
|
||||
auto parsedType = ParseTypeIdentifier(var->GetType());
|
||||
if (parsedType == nullptr) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::InvalidTypeName, statement->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::InvalidTypeName, statement->GetStartPosition(),
|
||||
statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ namespace Porygon::Binder {
|
|||
|
||||
auto assignment = this->_scope->AssignVariable(identifier.GetHash(), type);
|
||||
if (assignment.GetResult() != VariableAssignmentResult::Ok) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::CantAssignVariable, statement->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantAssignVariable, statement->GetStartPosition(),
|
||||
statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ namespace Porygon::Binder {
|
|||
currentReturnType = this->_currentFunction->GetReturnType();
|
||||
}
|
||||
if (expression == nullptr && currentReturnType != nullptr) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::InvalidReturnType, statement->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::InvalidReturnType, statement->GetStartPosition(),
|
||||
statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ namespace Porygon::Binder {
|
|||
return new BoundReturnStatement(boundExpression);
|
||||
}
|
||||
if (currentReturnType.get()->operator!=(expresionType.get())) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::InvalidReturnType, statement->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::InvalidReturnType, statement->GetStartPosition(),
|
||||
statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ namespace Porygon::Binder {
|
|||
auto conditionalStatement = (ParsedConditionalStatement *) statement;
|
||||
auto boundCondition = this->BindExpression(conditionalStatement->GetCondition());
|
||||
if (boundCondition->GetType()->GetClass() != TypeClass::Bool) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::ConditionNotABool, statement->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::ConditionNotABool, statement->GetStartPosition(),
|
||||
statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ namespace Porygon::Binder {
|
|||
auto key = expression->GetValue();
|
||||
auto scope = this->_scope->Exists(key.GetHash());
|
||||
if (scope == -1) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::VariableNotFound, expression->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::VariableNotFound, expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ namespace Porygon::Binder {
|
|||
expression->GetStartPosition(), expression->GetLength());
|
||||
break;
|
||||
}
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::NoBinaryOperationFound, expression->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::NoBinaryOperationFound, expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ namespace Porygon::Binder {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::NoUnaryOperationFound, expression->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::NoUnaryOperationFound, expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
|
||||
|
@ -445,7 +445,7 @@ namespace Porygon::Binder {
|
|||
auto functionExpression = BindExpression(expression->GetFunction());
|
||||
auto type = functionExpression->GetType();
|
||||
if (type->GetClass() != TypeClass::Function) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::ExpressionIsNotAFunction,
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::ExpressionIsNotAFunction,
|
||||
expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
|
@ -454,7 +454,7 @@ namespace Porygon::Binder {
|
|||
auto parameterTypes = functionType->GetParameterTypes();
|
||||
auto givenParameters = expression->GetParameters();
|
||||
if (parameterTypes.size() != givenParameters->size()) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::ParameterCountMismatch,
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::ParameterCountMismatch,
|
||||
expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
|
@ -464,7 +464,7 @@ namespace Porygon::Binder {
|
|||
auto parameter = givenParameters->at(i);
|
||||
auto boundParameter = this->BindExpression(parameter);
|
||||
if (boundParameter->GetType().get()->operator!=(parameterTypes.at(i).get())) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::ParameterTypeMismatch,
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::ParameterTypeMismatch,
|
||||
parameter->GetStartPosition(),
|
||||
parameter->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
|
@ -482,7 +482,7 @@ namespace Porygon::Binder {
|
|||
|
||||
auto indexerType = indexer->GetType();
|
||||
if (!indexerType->CanBeIndexedWith(index->GetType().get())) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::CantIndex, index->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantIndex, index->GetStartPosition(),
|
||||
index->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
|
@ -491,14 +491,14 @@ namespace Porygon::Binder {
|
|||
auto field = dynamic_pointer_cast<UserData::UserDataScriptType>(indexerType)->GetField(stringKey->GetHashValue());
|
||||
if (!setter) {
|
||||
if (!field->HasGetter()) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::UserDataFieldNoGetter,
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UserDataFieldNoGetter,
|
||||
index->GetStartPosition(),
|
||||
index->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
} else {
|
||||
if (!field->HasSetter()) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::UserDataFieldNoSetter,
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UserDataFieldNoSetter,
|
||||
index->GetStartPosition(),
|
||||
index->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
|
@ -516,7 +516,7 @@ namespace Porygon::Binder {
|
|||
const auto &identifier = expression->GetIndex();
|
||||
const auto &indexerType = indexer->GetType();
|
||||
if (!indexerType->CanBeIndexedWithIdentifier(identifier.GetHash())) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::CantIndex, expression->GetStartPosition(),
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantIndex, expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
|
@ -524,14 +524,14 @@ namespace Porygon::Binder {
|
|||
auto field = dynamic_pointer_cast<UserData::UserDataScriptType>(indexerType)->GetField(identifier.GetHash());
|
||||
if (!setter) {
|
||||
if (!field->HasGetter()) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::UserDataFieldNoGetter,
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UserDataFieldNoGetter,
|
||||
expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
} else {
|
||||
if (!field->HasSetter()) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::UserDataFieldNoSetter,
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UserDataFieldNoSetter,
|
||||
expression->GetStartPosition(),
|
||||
expression->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
|
@ -555,7 +555,7 @@ namespace Porygon::Binder {
|
|||
for (int i = 1; i < expressions->size(); i++) {
|
||||
boundExpressions[i] = this->BindExpression(expressions->at(i));
|
||||
if (boundExpressions[i]->GetType().get()->operator!=(valueType.get())) {
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::InvalidTableValueType,
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::InvalidTableValueType,
|
||||
boundExpressions[i]->GetStartPosition(),
|
||||
boundExpressions[i]->GetLength());
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "DiagnosticSeverity.hpp"
|
||||
#include "DiagnosticCode.hpp"
|
||||
|
||||
namespace Porygon::Diagnostics {
|
||||
class Diagnostic {
|
||||
DiagnosticSeverity _severity;
|
||||
DiagnosticCode _code;
|
||||
|
@ -21,6 +22,7 @@ public:
|
|||
DiagnosticSeverity GetSeverity() {
|
||||
return _severity;
|
||||
}
|
||||
|
||||
DiagnosticCode GetCode() {
|
||||
return _code;
|
||||
}
|
||||
|
@ -33,5 +35,5 @@ public:
|
|||
return _length;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif //PORYGONLANG_DIAGNOSTIC_HPP
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#ifndef PORYGONLANG_DIAGNOSTICCODE_HPP
|
||||
#define PORYGONLANG_DIAGNOSTICCODE_HPP
|
||||
|
||||
namespace Porygon::Diagnostics {
|
||||
enum class DiagnosticCode {
|
||||
// Lex diagnostics
|
||||
UnexpectedCharacter,
|
||||
|
@ -26,5 +27,5 @@ enum class DiagnosticCode{
|
|||
UserDataFieldNoGetter,
|
||||
UserDataFieldNoSetter
|
||||
};
|
||||
|
||||
}
|
||||
#endif //PORYGONLANG_DIAGNOSTICCODE_HPP
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
#ifndef PORYGONLANG_DIAGNOSTICSEVERITY_HPP
|
||||
#define PORYGONLANG_DIAGNOSTICSEVERITY_HPP
|
||||
|
||||
namespace Porygon::Diagnostics {
|
||||
enum class DiagnosticSeverity {
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
};
|
||||
}
|
||||
|
||||
#endif //PORYGONLANG_DIAGNOSTICSEVERITY_HPP
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "DiagnosticsHolder.hpp"
|
||||
|
||||
using namespace Porygon::Diagnostics;
|
||||
vector<Diagnostic> DiagnosticsHolder::GetDiagnostics() {
|
||||
return _diagnostics;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
namespace Porygon::Diagnostics {
|
||||
class DiagnosticsHolder {
|
||||
bool _hasErrors;
|
||||
vector<Diagnostic> _diagnostics;
|
||||
|
@ -22,8 +23,11 @@ public:
|
|||
}
|
||||
|
||||
void Log(DiagnosticSeverity severity, DiagnosticCode code, unsigned int start, unsigned int length);
|
||||
|
||||
void LogError(DiagnosticCode code, unsigned int start, unsigned int length);
|
||||
|
||||
void LogWarning(DiagnosticCode code, unsigned int start, unsigned int length);
|
||||
|
||||
void LogInfo(DiagnosticCode code, unsigned int start, unsigned int length);
|
||||
|
||||
bool HasErrors();
|
||||
|
@ -34,6 +38,6 @@ public:
|
|||
|
||||
Diagnostic *GetDiagnosticAt(int position);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //PORYGONLANG_DIAGNOSTICSHOLDER_HPP
|
||||
|
|
|
@ -99,7 +99,7 @@ namespace Porygon::Parser {
|
|||
Lexer::Next();
|
||||
return new SimpleToken(TokenKind::InequalityToken, this->_position - 2, 2);
|
||||
}
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedCharacter, this->_position - 1, 1);
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedCharacter, this->_position - 1, 1);
|
||||
return new SimpleToken(TokenKind::BadToken, this->_position - 1, 1);
|
||||
case '0':
|
||||
case '1':
|
||||
|
@ -122,7 +122,7 @@ namespace Porygon::Parser {
|
|||
if (isalpha(c) || c > 255) {
|
||||
return LexIdentifierOrKeyword();
|
||||
}
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedCharacter, this->_position - 1, 1);
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedCharacter, this->_position - 1, 1);
|
||||
return new SimpleToken(TokenKind::BadToken, this->_position - 1, 1);
|
||||
}
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ namespace Porygon::Parser {
|
|||
}
|
||||
auto closeToken = this->Next();
|
||||
if (closeToken != c) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedCharacter, this->_position - 1, 1);
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedCharacter, this->_position - 1, 1);
|
||||
return new SimpleToken(TokenKind::BadToken, start, end - start + 1);
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ namespace Porygon::Parser {
|
|||
if (ControlCharacters.find(c) != ControlCharacters.end()) {
|
||||
stream << ControlCharacters.at(c);
|
||||
} else {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::InvalidStringControlCharacter,
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::InvalidStringControlCharacter,
|
||||
start + 1 + i, 1);
|
||||
stream << c;
|
||||
}
|
||||
|
|
|
@ -72,12 +72,12 @@ namespace Porygon::Parser {
|
|||
auto expression = this->ParseExpression(this->Next());
|
||||
|
||||
if (identifier->GetKind() != TokenKind::Identifier) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, identifier->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, identifier->GetStartPosition(),
|
||||
identifier->GetLength());
|
||||
return new ParsedBadStatement(identifier->GetStartPosition(), identifier->GetLength());
|
||||
}
|
||||
if (assignmentToken->GetKind() != TokenKind::AssignmentToken) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, identifier->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, identifier->GetStartPosition(),
|
||||
identifier->GetLength());
|
||||
return new ParsedBadStatement(identifier->GetStartPosition(), identifier->GetLength());
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ namespace Porygon::Parser {
|
|||
break;
|
||||
}
|
||||
if (nextKind == TokenKind::EndOfFile) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, next->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, next->GetStartPosition(),
|
||||
next->GetLength());
|
||||
break;
|
||||
}
|
||||
|
@ -125,13 +125,13 @@ namespace Porygon::Parser {
|
|||
vector<TypedVariableIdentifier *> parameters;
|
||||
bool hasErrors = false;
|
||||
if (functionIdentifierToken->GetKind() != TokenKind::Identifier) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken,
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken,
|
||||
functionIdentifierToken->GetStartPosition(),
|
||||
functionIdentifierToken->GetLength());
|
||||
hasErrors = true;
|
||||
}
|
||||
if (openParenthesis->GetKind() != TokenKind::OpenParenthesis && !hasErrors) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken,
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken,
|
||||
openParenthesis->GetStartPosition(), openParenthesis->GetLength());
|
||||
hasErrors = true;
|
||||
}
|
||||
|
@ -144,20 +144,20 @@ namespace Porygon::Parser {
|
|||
auto identifier = this->Next();
|
||||
auto next = this->Next();
|
||||
if (type->GetKind() != TokenKind::Identifier && !hasErrors) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, type->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, type->GetStartPosition(),
|
||||
type->GetLength());
|
||||
hasErrors = true;
|
||||
continue;
|
||||
}
|
||||
if (identifier->GetKind() != TokenKind::Identifier && !hasErrors) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, identifier->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, identifier->GetStartPosition(),
|
||||
identifier->GetLength());
|
||||
hasErrors = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type->GetKind() != TokenKind::Identifier || identifier->GetKind() != TokenKind::Identifier) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, type->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, type->GetStartPosition(),
|
||||
type->GetLength());
|
||||
hasErrors = true;
|
||||
continue;
|
||||
|
@ -170,7 +170,7 @@ namespace Porygon::Parser {
|
|||
if (nextKind == TokenKind::CloseParenthesis || nextKind == TokenKind::EndOfFile) {
|
||||
break;
|
||||
} else if (nextKind != TokenKind::CommaToken && !hasErrors) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, next->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, next->GetStartPosition(),
|
||||
next->GetLength());
|
||||
hasErrors = true;
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ namespace Porygon::Parser {
|
|||
auto condition = this->ParseExpression(this->Next());
|
||||
auto next = this->Next();
|
||||
if (next->GetKind() != TokenKind::ThenKeyword) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, next->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, next->GetStartPosition(),
|
||||
next->GetLength());
|
||||
return new ParsedBadStatement(next->GetStartPosition(), next->GetLength());
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ namespace Porygon::Parser {
|
|||
case TokenKind::BadToken:
|
||||
return new BadExpression(current->GetStartPosition(), current->GetLength());
|
||||
default:
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, current->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, current->GetStartPosition(),
|
||||
current->GetLength());
|
||||
return new BadExpression(current->GetStartPosition(), current->GetLength());
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ namespace Porygon::Parser {
|
|||
auto expression = this->ParseExpression(next);
|
||||
auto closeToken = this->Next();
|
||||
if (closeToken->GetKind() != TokenKind::CloseParenthesis) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, closeToken->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, closeToken->GetStartPosition(),
|
||||
closeToken->GetLength());
|
||||
return new BadExpression(closeToken->GetStartPosition(), closeToken->GetLength());
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ namespace Porygon::Parser {
|
|||
} else {
|
||||
while (peekedKind != TokenKind::CloseParenthesis) {
|
||||
if (peekedKind == TokenKind::EndOfFile) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, peeked->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, peeked->GetStartPosition(),
|
||||
peeked->GetLength());
|
||||
return new BadExpression(peeked->GetStartPosition(), peeked->GetLength());
|
||||
}
|
||||
|
@ -422,7 +422,7 @@ namespace Porygon::Parser {
|
|||
peeked = this->Next();
|
||||
peekedKind = peeked->GetKind();
|
||||
if (peekedKind != TokenKind::CloseParenthesis && peekedKind != TokenKind::CommaToken) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, peeked->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, peeked->GetStartPosition(),
|
||||
peeked->GetLength());
|
||||
return new BadExpression(peeked->GetStartPosition(), peeked->GetLength());
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ namespace Porygon::Parser {
|
|||
auto indexExpression = this->ParseExpression(this->Next());
|
||||
auto closeBracket = this->Next();
|
||||
if (closeBracket->GetKind() != TokenKind::CloseSquareBracket) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, closeBracket->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, closeBracket->GetStartPosition(),
|
||||
closeBracket->GetLength());
|
||||
return new BadExpression(closeBracket->GetStartPosition(), closeBracket->GetLength());
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ namespace Porygon::Parser {
|
|||
this->Next(); // consume '.' token
|
||||
auto identifier = this->Next();
|
||||
if (identifier->GetKind() != TokenKind::Identifier) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, identifier->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, identifier->GetStartPosition(),
|
||||
identifier->GetLength());
|
||||
return new BadExpression(indexingExpression->GetStartPosition(),
|
||||
identifier->GetEndPosition() - indexingExpression->GetStartPosition());
|
||||
|
@ -481,7 +481,7 @@ namespace Porygon::Parser {
|
|||
n = this->Next();
|
||||
if (n->GetKind() != TokenKind::CommaToken && n->GetKind() != TokenKind::CloseCurlyBracket &&
|
||||
!hasErrors) {
|
||||
this->ScriptData->Diagnostics->LogError(DiagnosticCode::UnexpectedToken, n->GetStartPosition(),
|
||||
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::UnexpectedToken, n->GetStartPosition(),
|
||||
n->GetLength());
|
||||
hasErrors = true;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ Porygon::Script *Porygon::Script::Create(const string &script) {
|
|||
}
|
||||
|
||||
Porygon::Script::Script() {
|
||||
Diagnostics = new DiagnosticsHolder();
|
||||
Diagnostics = new Diagnostics::DiagnosticsHolder();
|
||||
_boundScript = nullptr;
|
||||
_scriptVariables = new unordered_map<uint32_t, shared_ptr<EvalValue>>(0);
|
||||
_evaluator = new Evaluator(this -> _scriptVariables);
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Porygon{
|
|||
public:
|
||||
static Script* Create(const u16string& script);
|
||||
static Script* Create(const string& script);
|
||||
DiagnosticsHolder* Diagnostics;
|
||||
Diagnostics::DiagnosticsHolder* Diagnostics;
|
||||
|
||||
~Script();
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ TEST_CASE( "Diagnostic invalid character", "[integration]" ) {
|
|||
REQUIRE(script->Diagnostics -> HasErrors());
|
||||
auto diags = script->Diagnostics -> GetDiagnostics();
|
||||
REQUIRE(diags.size() == 1);
|
||||
CHECK(diags[0].GetCode() == DiagnosticCode::UnexpectedCharacter);
|
||||
CHECK(diags[0].GetCode() == Diagnostics::DiagnosticCode::UnexpectedCharacter);
|
||||
CHECK(diags[0].GetStartPosition() == 6);
|
||||
CHECK(diags[0].GetLength() == 1);
|
||||
delete script;
|
||||
|
@ -20,7 +20,7 @@ TEST_CASE( "Diagnostic invalid token", "[integration]" ) {
|
|||
REQUIRE(script->Diagnostics -> HasErrors());
|
||||
auto diags = script->Diagnostics -> GetDiagnostics();
|
||||
REQUIRE(diags.size() == 1);
|
||||
CHECK(diags[0].GetCode() == DiagnosticCode::UnexpectedToken);
|
||||
CHECK(diags[0].GetCode() == Diagnostics::DiagnosticCode::UnexpectedToken);
|
||||
CHECK(diags[0].GetStartPosition() == 3);
|
||||
CHECK(diags[0].GetLength() == 1);
|
||||
delete script;
|
||||
|
|
Loading…
Reference in New Issue