OSDN Git Service

composition か phrase 以外のトークンがあるときのエラーメッセージを改善
authorstarg <starg@users.osdn.me>
Wed, 14 Sep 2016 16:46:51 +0000 (01:46 +0900)
committerstarg <starg@users.osdn.me>
Wed, 14 Sep 2016 16:46:51 +0000 (01:46 +0900)
include/message/id.hpp
src/driver/msgcallback.cpp
src/parser/error_module.hpp
src/parser/parser_module.hpp

index 7c7749a..bc5b492 100644 (file)
@@ -60,6 +60,7 @@ enum class MessageID : int
     GrammarUntilSingleQuote,
 
     // error_module.hpp
+    GrammarTrapNeitherCompositionNorPhrase,
     GrammarPhrasesAndCompositions,
 
     // grammar_phrase.hpp
index 59a5071..9050d3d 100644 (file)
@@ -81,7 +81,8 @@ MessagePrinter::MessagePrinter(IStdErrWriter* pStdErrWriter)
         {Message::MessageID::GrammarUntilSingleQuote, "unterminated string literal (missing single quote)"},
 
         // error_module.hpp
-        {Message::MessageID::GrammarPhrasesAndCompositions, "parse error: GrammarPhrasesAndCompositions"},
+        {Message::MessageID::GrammarTrapNeitherCompositionNorPhrase, "unexpected token '{0}', expecting 'phrase' or 'composition'"},
+        {Message::MessageID::GrammarPhrasesAndCompositions, "expecting 'phrase' or 'composition'"},
 
         // grammar_phrase.hpp
         {Message::MessageID::GrammarNoteSequenceBlockWithoutAttributes, "expecting '{' here"},
index 50e8faf..4c266df 100644 (file)
@@ -13,6 +13,9 @@ namespace Parser
 {
 
 template<>
+const Message::MessageID ErrorControl<Grammar::TrapNeitherCompositionNorPhrase>::ID = Message::MessageID::GrammarTrapNeitherCompositionNorPhrase;
+
+template<>
 const Message::MessageID ErrorControl<Grammar::PhrasesAndCompositions>::ID = Message::MessageID::GrammarPhrasesAndCompositions;
 
 template<>
index b1ef2df..d809a14 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <pegtl.hh>
 
+#include "parser_attribute.hpp"
 #include "parser_composition.hpp"
 #include "parser_phrase.hpp"
 #include "parser_skips.hpp"
@@ -16,7 +17,16 @@ namespace Parser
 namespace Grammar
 {
 
-class PhrasesAndCompositions : public pegtl::star<pegtl::pad<pegtl::sor<Composition, Phrase>, Separator>>
+class TrapNeitherCompositionNorPhrase
+    : public pegtl::seq<
+        pegtl::disable<AttributeOptionalSequence>,
+        pegtl::not_at<pegtl::eof>,
+        pegtl::raise<TrapNeitherCompositionNorPhrase>
+    >
+{
+};
+
+class PhrasesAndCompositions : public pegtl::star<pegtl::pad<pegtl::sor<Composition, Phrase, TrapNeitherCompositionNorPhrase>, Separator>>
 {
 };