+++ /dev/null
-
-#pragma once
-
-#include <string>
-
-#include <exceptions/exception.hpp>
-#include <message/id.hpp>
-
-namespace YAMML
-{
-
-namespace Exceptions
-{
-
-class ParseException : public Exception
-{
-public:
- ParseException(
- const std::string& ruleName,
- const std::string& source,
- std::size_t line,
- std::size_t column,
- const std::string& nextToken,
- Message::MessageID id
- ) : Exception("ParseException: MessageID=" + std::to_string(static_cast<int>(id))),
- RuleName(ruleName),
- Source(source),
- Line{line},
- Column{column},
- NextToken(nextToken),
- ID{id}
- {
- }
-
- std::string RuleName;
- std::string Source;
- std::size_t Line;
- std::size_t Column;
- std::string NextToken;
- Message::MessageID ID;
-};
-
-} // namespace Exceptions
-
-} // namespace YAMML
#include <pegtl.hh>
#include <pegtl/internal/demangle.hh>
-#include <exceptions/parseexception.hpp>
+#include <message/message.hpp>
#include "parser_literal.hpp"
};
template<typename TInput>
-void ThrowParseException(const std::string& ruleName, const TInput& in, Message::MessageID id)
+auto CreateParseErrorMessage(Message::MessageKind kind, Message::MessageID id, const TInput& in)
{
std::string tokenForErrorMsg;
tokenForErrorMsg
);
- throw Exceptions::ParseException(
- ruleName,
+ return Message::MessageItem{
+ kind,
+ id,
in.source(),
- in.line(),
- in.column(),
- matched ? tokenForErrorMsg : "<EOF>",
- id
- );
+ {in.line(), in.column()},
+ {matched ? tokenForErrorMsg : "<EOF>"}
+ };
}
template<typename TRule>
public:
static const Message::MessageID ID;
- template<typename TInput, typename... TStates>
- static void raise(const TInput& in, TStates&&...)
+ template<typename TInput, typename TCurrentState, typename TCompiler, typename... TOtherStates>
+ static void raise(const TInput& in, TCurrentState&, TCompiler& compiler, TOtherStates&&...)
{
- ThrowParseException(pegtl::internal::demangle<TRule>(), in, ID);
+ compiler.AddMessage(CreateParseErrorMessage(Message::MessageKind::Error, ID, in));
+ ErrorControl::normal::raise(in);
}
};
#include <algorithm>
#include <utility>
-#include <exceptions/parseexception.hpp>
#include <message/kind.hpp>
#include <message/message.hpp>
#include <parser/parser.hpp>
return false;
}
}
- catch (const Exceptions::ParseException& e)
+ catch (const pegtl::parse_error&)
{
- AddMessage(Message::MessageItem{Message::MessageKind::Error, e.ID, e.Source, {e.Line, e.Column}, {e.NextToken}});
return false;
}
}