OSDN Git Service

PEGTL を master へアップグレード
authorstarg <starg@users.osdn.me>
Mon, 10 Oct 2016 09:41:30 +0000 (18:41 +0900)
committerstarg <starg@users.osdn.me>
Mon, 10 Oct 2016 09:41:30 +0000 (18:41 +0900)
src/parser/action.hpp
src/parser/action_state_attribute.hpp
src/parser/action_state_composition.hpp
src/parser/action_state_literal.hpp
src/parser/action_state_phrase.hpp
src/parser/error_control.hpp
src/parser/parser.cpp
src/parser/pch.hpp
test/parser/compositionparsertest.cpp
test/parser/pch.hpp
test/parser/phraseparsertest.cpp

index c300842..e90c517 100644 (file)
@@ -12,10 +12,10 @@ namespace Parser
 class AssignLocationAction
 {
 public:
-    template<typename TState, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
+    template<typename TInput, typename TState, typename... TCommonStates>
+    static void apply(const TInput& in, TState& st, TCommonStates&...)
     {
-        st.ASTNode.Location = {in.line(), in.column()};
+        st.ASTNode.Location = {in.line(), in.byte_in_line()};
     }
 };
 
index 1c44990..9019c17 100644 (file)
@@ -41,8 +41,8 @@ template<>
 class AttributeAction<Grammar::Identifier>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, AttributeState& st, TCommonStates&...)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, AttributeState& st, TCommonStates&...)
     {
         st.ASTNode.Name = in.string();
     }
@@ -84,8 +84,8 @@ template<>
 class AttributeKeyAction<Grammar::Identifier>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, AttributeArgumentState& st, TCommonStates&...)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, AttributeArgumentState& st, TCommonStates&...)
     {
         st.ASTNode.Name = in.string();
     }
index 40ea48e..d4ed4cc 100644 (file)
@@ -46,8 +46,8 @@ template<>
 class CompositionAction<Grammar::Identifier>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, CompositionState& st, TCommonStates&...)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, CompositionState& st, TCommonStates&...)
     {
         st.ASTNode.Name = in.string();
     }
@@ -101,8 +101,8 @@ template<>
 class TrackBlockAction<Grammar::UnsignedInteger>
 {
 public:
-    template<typename TCompiler, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TrackBlockState& st, TCompiler& compiler, TCommonStates&...)
+    template<typename TInput, typename TCompiler, typename... TCommonStates>
+    static void apply(const TInput& in, TrackBlockState& st, TCompiler& compiler, TCommonStates&...)
     {
         try
         {
@@ -115,7 +115,7 @@ public:
                     Message::MessageKind::Error,
                     Message::MessageID::IntegerOutOfRange,
                     compiler.GetSourceName(),
-                    {in.line(), in.column()},
+                    {in.line(), in.byte_in_line()},
                     {in.string()}
                 }
             );
@@ -149,8 +149,8 @@ template<>
 class TrackItemAction<Grammar::Identifier>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, TrackItemState& st, TCommonStates&...)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, TrackItemState& st, TCommonStates&...)
     {
         st.ASTNode.PhraseName = in.string();
     }
@@ -182,8 +182,8 @@ template<>
 class CommandAction<Grammar::Identifier>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, CommandState& st, TCommonStates&...)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, CommandState& st, TCommonStates&...)
     {
         st.ASTNode.Name = in.string();
     }
index 901dc24..882a5e3 100644 (file)
@@ -65,8 +65,8 @@ template<>
 class ValueAction<Grammar::SignedInteger>
 {
 public:
-    template<typename TState, typename TCompiler, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TState& st, TCompiler& compiler, TCommonStates&...)
+    template<typename TInput, typename TState, typename TCompiler, typename... TCommonStates>
+    static void apply(const TInput& in, TState& st, TCompiler& compiler, TCommonStates&...)
     {
         try
         {
@@ -79,7 +79,7 @@ public:
                     Message::MessageKind::Error,
                     Message::MessageID::IntegerOutOfRange,
                     compiler.GetSourceName(),
-                    {in.line(), in.column()},
+                    {in.line(), in.byte_in_line()},
                     {in.string()}
                 }
             );
@@ -91,8 +91,8 @@ template<>
 class ValueAction<Grammar::Identifier>
 {
 public:
-    template<typename TState, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
+    template<typename TInput, typename TState, typename... TCommonStates>
+    static void apply(const TInput& in, TState& st, TCommonStates&...)
     {
         st.ASTNode.Value = in.string();
     }
@@ -107,8 +107,8 @@ template<>
 class EscapeAction<Grammar::AnyChar>
 {
 public:
-    template<typename TState, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
+    template<typename TInput, typename TState, typename... TCommonStates>
+    static void apply(const TInput& in, TState& st, TCommonStates&...)
     {
         pegtl::unescape::append_all::apply(in, st);
     }
@@ -118,8 +118,8 @@ template<>
 class EscapeAction<Grammar::EscapeX2>
 {
 public:
-    template<typename TState, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
+    template<typename TInput, typename TState, typename... TCommonStates>
+    static void apply(const TInput& in, TState& st, TCommonStates&...)
     {
         pegtl::unescape::unescape_x::apply(in, st);
     }
@@ -129,8 +129,8 @@ template<>
 class EscapeAction<Grammar::EscapeU4>
 {
 public:
-    template<typename TState, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
+    template<typename TInput, typename TState, typename... TCommonStates>
+    static void apply(const TInput& in, TState& st, TCommonStates&...)
     {
         pegtl::unescape::unescape_u::apply(in, st);
     }
@@ -140,8 +140,8 @@ template<>
 class EscapeAction<Grammar::EscapeU8>
 {
 public:
-    template<typename TState, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
+    template<typename TInput, typename TState, typename... TCommonStates>
+    static void apply(const TInput& in, TState& st, TCommonStates&...)
     {
         pegtl::unescape::unescape_u::apply(in, st);
     }
@@ -151,8 +151,8 @@ template<>
 class EscapeAction<Grammar::EscapeC>
 {
 public:
-    template<typename TState, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
+    template<typename TInput, typename TState, typename... TCommonStates>
+    static void apply(const TInput& in, TState& st, TCommonStates&...)
     {
         pegtl::unescape::unescape_c<Grammar::EscapeC, '\'', '"', '?', '\\', '\a', '\b', '\f', '\n', '\r', '\t', '\v'>::apply(in, st);
     }
index 8a07a0f..e345b0f 100644 (file)
@@ -59,8 +59,8 @@ template<>
 class PhraseAction<Grammar::Identifier>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, PhraseState& st, TCommonStates&...)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, PhraseState& st, TCommonStates&...)
     {
         st.ASTNode.Name = in.string();
     }
@@ -217,8 +217,8 @@ template<>
 class NoteRepeatEachExpressionAction<Grammar::UnsignedInteger>
 {
 public:
-    template<typename TCompiler, typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteRepeatEachExpressionState& st, TCompiler& compiler, TCommonStates&...)
+    template<typename TInput, typename TCompiler, typename... TCommonStates>
+    static void apply(const TInput& in, NoteRepeatEachExpressionState& st, TCompiler& compiler, TCommonStates&...)
     {
         try
         {
@@ -231,7 +231,7 @@ public:
                     Message::MessageKind::Error,
                     Message::MessageID::IntegerOutOfRange,
                     compiler.GetSourceName(),
-                    {in.line(), in.column()},
+                    {in.line(), in.byte_in_line()},
                     {in.string()}
                 }
             );
@@ -270,8 +270,8 @@ template<>
 class NoteRepeatExpressionAction<Grammar::UnsignedInteger>
 {
 public:
-    template<typename TCompiler, typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteRepeatExpressionState& st, TCompiler& compiler, TCommonStates&...)
+    template<typename TInput, typename TCompiler, typename... TCommonStates>
+    static void apply(const TInput& in, NoteRepeatExpressionState& st, TCompiler& compiler, TCommonStates&...)
     {
         try
         {
@@ -284,7 +284,7 @@ public:
                     Message::MessageKind::Error,
                     Message::MessageID::IntegerOutOfRange,
                     compiler.GetSourceName(),
-                    {in.line(), in.column()},
+                    {in.line(), in.byte_in_line()},
                     {in.string()}
                 }
             );
@@ -345,8 +345,8 @@ template<>
 class NoteAccentsAction<Grammar::NoteAccents>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteAccentsState& st, TCommonStates&...)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, NoteAccentsState& st, TCommonStates&...)
     {
         AssignLocationAction::apply(in, st);
 
@@ -426,8 +426,8 @@ template<>
 class SimpleDurationModifierDotsAction<Grammar::SimpleDurationModifierDots>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, SimpleDurationModifierDotsState& st, TCommonStates&... commonStates)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, SimpleDurationModifierDotsState& st, TCommonStates&... commonStates)
     {
         AssignLocationAction::apply(in, st, commonStates...);
         st.ASTNode.Count = static_cast<unsigned long>(in.size());
@@ -460,8 +460,8 @@ template<>
 class SimpleDurationModifierAction<Grammar::UnsignedInteger>
 {
 public:
-    template<typename TCompiler, typename... TCommonStates>
-    static void apply(const pegtl::input& in, SimpleDurationModifierState& st, TCompiler& compiler, TCommonStates&...)
+    template<typename TInput, typename TCompiler, typename... TCommonStates>
+    static void apply(const TInput& in, SimpleDurationModifierState& st, TCompiler& compiler, TCommonStates&...)
     {
         try
         {
@@ -474,7 +474,7 @@ public:
                     Message::MessageKind::Error,
                     Message::MessageID::IntegerOutOfRange,
                     compiler.GetSourceName(),
-                    {in.line(), in.column()},
+                    {in.line(), in.byte_in_line()},
                     {in.string()}
                 }
             );
@@ -508,8 +508,8 @@ template<>
 class SimpleDurationAction<Grammar::UnsignedInteger>
 {
 public:
-    template<typename TCompiler, typename... TCommonStates>
-    static void apply(const pegtl::input& in, SimpleDurationState& st, TCompiler& compiler, TCommonStates&...)
+    template<typename TInput, typename TCompiler, typename... TCommonStates>
+    static void apply(const TInput& in, SimpleDurationState& st, TCompiler& compiler, TCommonStates&...)
     {
         try
         {
@@ -522,7 +522,7 @@ public:
                     Message::MessageKind::Error,
                     Message::MessageID::IntegerOutOfRange,
                     compiler.GetSourceName(),
-                    {in.line(), in.column()},
+                    {in.line(), in.byte_in_line()},
                     {in.string()}
                 }
             );
@@ -605,8 +605,8 @@ template<>
 class NoteOctaveAction<Grammar::SignedInteger>
 {
 public:
-    template<typename TCompiler, typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteOctaveState& st, TCompiler& compiler, TCommonStates&...)
+    template<typename TInput, typename TCompiler, typename... TCommonStates>
+    static void apply(const TInput& in, NoteOctaveState& st, TCompiler& compiler, TCommonStates&...)
     {
         try
         {
@@ -619,7 +619,7 @@ public:
                     Message::MessageKind::Error,
                     Message::MessageID::IntegerOutOfRange,
                     compiler.GetSourceName(),
-                    {in.line(), in.column()},
+                    {in.line(), in.byte_in_line()},
                     {in.string()}
                 }
             );
@@ -657,8 +657,8 @@ template<>
 class NoteNameAction<Grammar::NoteNameBase>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteNameState& st, TCommonStates&...)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, NoteNameState& st, TCommonStates&...)
     {
         st.ASTNode.Name = in.string().at(0);
     }
@@ -668,8 +668,8 @@ template<>
 class NoteNameAction<Grammar::NoteNameKey>
 {
 public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteNameState& st, TCommonStates&...)
+    template<typename TInput, typename... TCommonStates>
+    static void apply(const TInput& in, NoteNameState& st, TCommonStates&...)
     {
         st.ASTNode.Minor = 0;
 
index 190210a..8a84ecb 100644 (file)
@@ -33,20 +33,20 @@ template<>
 class TokenForErrorMessageAction<TokenForErrorMessage>
 {
 public:
-    static void apply(const pegtl::input& in, std::string& st)
+    template<typename TInput>
+    static void apply(const TInput& in, std::string& st)
     {
         st = in.string();
     }
 };
 
-template<typename TInput>
-auto CreateParseErrorMessage(Message::MessageKind kind, Message::MessageID id, const TInput& in)
+auto CreateParseErrorMessage(Message::MessageKind kind, Message::MessageID id, const pegtl::memory_input& in)
 {
     std::string tokenForErrorMsg;
 
-    bool matched = pegtl::parse<TokenForErrorMessageAndSeparators, TokenForErrorMessageAction>(
+    bool matched = pegtl::parse_memory<TokenForErrorMessageAndSeparators, TokenForErrorMessageAction>(
         in.begin(),
-        in.end(),
+        in.end(0),
         in.source(),
         tokenForErrorMsg
     );
@@ -55,7 +55,7 @@ auto CreateParseErrorMessage(Message::MessageKind kind, Message::MessageID id, c
         kind,
         id,
         in.source(),
-        {in.line(), in.column()},
+        {in.line(), in.byte_in_line()},
         {matched ? tokenForErrorMsg : "<EOF>"}
     };
 }
index 4585b83..92501c5 100644 (file)
@@ -8,6 +8,7 @@
 
 #ifdef _MSC_VER
 #pragma warning(push)
+#pragma warning(disable: 4244) // conversion from 'const std::streamsize' to 'std::size_t', possible loss of data
 #pragma warning(disable: 4702) // unreachable code
 #endif
 
@@ -49,7 +50,7 @@ bool YAMMLParser::Parse()
     AST::Module ast;
     ast.Name = GetSourceName();
 
-    bool result = pegtl::parse<pegtl::try_catch<Grammar::Module>, pegtl::nothing, Control>(m_Source, m_Name, ast, *this);
+    bool result = pegtl::parse_string<pegtl::try_catch<Grammar::Module>, pegtl::nothing, Control>(m_Source, m_Name, ast, *this);
 
     if (result && !HasErrors())
     {
index 20179ae..1e80cc5 100644 (file)
@@ -14,6 +14,7 @@
 
 #ifdef _MSC_VER
 #pragma warning(push)
+#pragma warning(disable: 4244) // conversion from 'const std::streamsize' to 'std::size_t', possible loss of data
 #pragma warning(disable: 4702)  // unreachable code
 #pragma warning(disable: 4715)  // not all control paths return a value
 #endif
index f12e7e8..b6b332b 100644 (file)
@@ -3,6 +3,7 @@
 
 #ifdef _MSC_VER
 #pragma warning(push)
+#pragma warning(disable: 4244) // conversion from 'const std::streamsize' to 'std::size_t', possible loss of data
 #pragma warning(disable: 4702) // unreachable code
 #endif
 
@@ -36,7 +37,7 @@ composition Foo
 
 )";
 
-    bool result = pegtl::parse<pegtl::must<Composition, Separators, pegtl::eof>>(data, "source");
+    bool result = pegtl::parse_string<pegtl::must<Composition, Separators, pegtl::eof>>(data, "source");
     BOOST_CHECK(result);
 }
 
index 18f3fde..6b050a2 100644 (file)
@@ -10,6 +10,7 @@
 
 #ifdef _MSC_VER
 #pragma warning(push)
+#pragma warning(disable: 4244) // conversion from 'const std::streamsize' to 'std::size_t', possible loss of data
 #pragma warning(disable: 4702) // unreachable code
 #endif
 
index d98fad8..1819669 100644 (file)
@@ -1,8 +1,16 @@
 
 #include <boost/test/unit_test.hpp>
 
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable: 4244) // conversion from 'const std::streamsize' to 'std::size_t', possible loss of data
+#endif
+
 #include <pegtl.hh>
-#include <pegtl/trace.hh>
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
 
 #include "../../src/parser/parser_phrase.hpp"
 
@@ -13,28 +21,28 @@ BOOST_AUTO_TEST_SUITE(PhraseParserTest)
 BOOST_AUTO_TEST_CASE(NoteNameTest1)
 {
     std::string data = "As";
-    bool result = pegtl::parse<pegtl::must<NoteName, Separators, pegtl::eof>>(data, "source");
+    bool result = pegtl::parse_string<pegtl::must<NoteName, Separators, pegtl::eof>>(data, "source");
     BOOST_CHECK(result);
 }
 
 BOOST_AUTO_TEST_CASE(NoteNumberTest1)
 {
     std::string data = "Bf4";
-    bool result = pegtl::parse<pegtl::must<NoteNumber, Separators, pegtl::eof>>(data, "source");
+    bool result = pegtl::parse_string<pegtl::must<NoteNumber, Separators, pegtl::eof>>(data, "source");
     BOOST_CHECK(result);
 }
 
 BOOST_AUTO_TEST_CASE(NoteAndDurationTest1)
 {
     std::string data = "Bf4/8";
-    bool result = pegtl::parse<pegtl::must<NoteAndDuration, Separators, pegtl::eof>>(data, "source");
+    bool result = pegtl::parse_string<pegtl::must<NoteAndDuration, Separators, pegtl::eof>>(data, "source");
     BOOST_CHECK(result);
 }
 
 BOOST_AUTO_TEST_CASE(NoteAndDurationTest2)
 {
     std::string data = "Bf4/*/*/ / 8";
-    bool result = pegtl::parse<pegtl::must<NoteAndDuration, Separators, pegtl::eof>>(data, "source");
+    bool result = pegtl::parse_string<pegtl::must<NoteAndDuration, Separators, pegtl::eof>>(data, "source");
     BOOST_CHECK(result);
 }
 
@@ -50,7 +58,7 @@ phrase Foo
 
 )";
 
-    bool result = pegtl::parse<pegtl::must<Phrase, Separators, pegtl::eof>>(data, "source");
+    bool result = pegtl::parse_string<pegtl::must<Phrase, Separators, pegtl::eof>>(data, "source");
     BOOST_CHECK(result);
 }
 
@@ -68,7 +76,7 @@ phrase Bar
 
 )";
 
-    bool result = pegtl::parse<pegtl::must<Phrase, Separators, pegtl::eof>>(data, "source");
+    bool result = pegtl::parse_string<pegtl::must<Phrase, Separators, pegtl::eof>>(data, "source");
     BOOST_CHECK(result);
 }