OSDN Git Service

パースエラーを ErrorControl で表示するようにし、Exceptions::ParseException を削除してかわりに pegtl::parse_erro...
authorstarg <starg@users.osdn.me>
Fri, 26 Aug 2016 01:16:44 +0000 (10:16 +0900)
committerstarg <starg@users.osdn.me>
Fri, 26 Aug 2016 01:16:44 +0000 (10:16 +0900)
include/exceptions/parseexception.hpp [deleted file]
src/parser/error_control.hpp
src/parser/parser.cpp

diff --git a/include/exceptions/parseexception.hpp b/include/exceptions/parseexception.hpp
deleted file mode 100644 (file)
index f933163..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-
-#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
index f901172..d35c5c9 100644 (file)
@@ -6,7 +6,7 @@
 #include <pegtl.hh>
 #include <pegtl/internal/demangle.hh>
 
-#include <exceptions/parseexception.hpp>
+#include <message/message.hpp>
 
 #include "parser_literal.hpp"
 
@@ -40,7 +40,7 @@ public:
 };
 
 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;
 
@@ -51,14 +51,13 @@ void ThrowParseException(const std::string& ruleName, const TInput& in, Message:
         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>
@@ -67,10 +66,11 @@ class ErrorControl : public pegtl::normal<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);
     }
 };
 
index c2e3026..fa2168b 100644 (file)
@@ -2,7 +2,6 @@
 #include <algorithm>
 #include <utility>
 
-#include <exceptions/parseexception.hpp>
 #include <message/kind.hpp>
 #include <message/message.hpp>
 #include <parser/parser.hpp>
@@ -64,9 +63,8 @@ bool YAMMLParser::Parse()
             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;
     }
 }