OSDN Git Service

Action のうちソースコードの行番号を記録する部分を共通化
authorstarg <starg@users.osdn.me>
Sun, 17 Jul 2016 11:45:53 +0000 (20:45 +0900)
committerstarg <starg@users.osdn.me>
Sun, 17 Jul 2016 11:45:53 +0000 (20:45 +0900)
src/parser/CMakeLists.txt
src/parser/action.hpp [new file with mode: 0644]
src/parser/action_state_attribute.hpp
src/parser/action_state_composition.hpp
src/parser/action_state_literal.hpp
src/parser/action_state_phrase.hpp

index 6bba254..cc360d2 100644 (file)
@@ -1,6 +1,7 @@
 
 set(ParserHeaders
     ../../include/parser/parser.hpp
+    action.hpp
     action_state_attribute.hpp
     action_state_composition.hpp
     action_state_literal.hpp
diff --git a/src/parser/action.hpp b/src/parser/action.hpp
new file mode 100644 (file)
index 0000000..c300842
--- /dev/null
@@ -0,0 +1,24 @@
+
+#pragma once
+
+#include <pegtl.hh>
+
+namespace YAMML
+{
+
+namespace Parser
+{
+
+class AssignLocationAction
+{
+public:
+    template<typename TState, typename... TCommonStates>
+    static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
+    {
+        st.ASTNode.Location = {in.line(), in.column()};
+    }
+};
+
+} // namespace Parser
+
+} // namespace YAMML
index b1e3fd3..4186382 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <ast/attribute.hpp>
 
+#include "action.hpp"
 #include "parser_attribute.hpp"
 
 
@@ -32,14 +33,8 @@ class AttributeAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class AttributeAction<Grammar::Attribute>
+class AttributeAction<Grammar::Attribute> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, AttributeState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -71,14 +66,8 @@ class AttributeArgumentAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class AttributeArgumentAction<Grammar::AttributeArgument>
+class AttributeArgumentAction<Grammar::AttributeArgument> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, AttributeArgumentState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<typename TRule>
index d304521..db2aade 100644 (file)
@@ -9,6 +9,7 @@
 #include <ast/module.hpp>
 #include <parser/parser.hpp>
 
+#include "action.hpp"
 #include "parser_composition.hpp"
 
 namespace YAMML
@@ -46,14 +47,8 @@ class CompositionAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class CompositionAction<Grammar::Composition>
+class CompositionAction<Grammar::Composition> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, CompositionState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -85,14 +80,8 @@ class TrackListBlockAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class TrackListBlockAction<Grammar::TrackListBlock>
+class TrackListBlockAction<Grammar::TrackListBlock> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, TrackListBlockState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class TrackBlockState
@@ -113,14 +102,8 @@ class TrackBlockAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class TrackBlockAction<Grammar::TrackBlock>
+class TrackBlockAction<Grammar::TrackBlock> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, TrackBlockState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -152,14 +135,8 @@ class TrackItemAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class TrackItemAction<Grammar::TrackItem>
+class TrackItemAction<Grammar::TrackItem> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, TrackItemState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -191,14 +168,8 @@ class CommandAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class CommandAction<Grammar::Command>
+class CommandAction<Grammar::Command> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, CommandState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -230,14 +201,8 @@ class CommandArgumentAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class CommandArgumentAction<Grammar::CommandArgument>
+class CommandArgumentAction<Grammar::CommandArgument> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, CommandArgumentState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 } // namespace Parser
index 43e500b..e575ea5 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <ast/literal.hpp>
 
+#include "action.hpp"
 #include "parser_literal.hpp"
 
 namespace YAMML
@@ -45,14 +46,8 @@ class ValueAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class ValueAction<Grammar::Value>
+class ValueAction<Grammar::Value> : public AssignLocationAction
 {
-public:
-    template<typename TState, typename... TCommonStates>
-    static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
index 54d32db..4b1226e 100644 (file)
@@ -11,6 +11,7 @@
 #include <ast/phrase.hpp>
 #include <parser/parser.hpp>
 
+#include "action.hpp"
 #include "parser_phrase.hpp"
 
 namespace YAMML
@@ -53,14 +54,8 @@ class PhraseAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class PhraseAction<Grammar::Phrase>
+class PhraseAction<Grammar::Phrase> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, PhraseState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -97,14 +92,8 @@ class NoteSequenceBlockAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteSequenceBlockAction<Grammar::NoteSequenceBlock>
+class NoteSequenceBlockAction<Grammar::NoteSequenceBlock> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteSequenceBlockState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class NoteSequenceBlockWithoutAttributesState
@@ -125,14 +114,8 @@ class NoteSequenceBlockWithoutAttributesAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteSequenceBlockWithoutAttributesAction<Grammar::NoteSequenceBlockWithoutAttributes>
+class NoteSequenceBlockWithoutAttributesAction<Grammar::NoteSequenceBlockWithoutAttributes> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteSequenceBlockWithoutAttributesState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class NoteSequenceStatementState
@@ -158,14 +141,8 @@ class NoteSequenceStatementAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteSequenceStatementAction<Grammar::NoteSequence>
+class NoteSequenceStatementAction<Grammar::NoteSequence> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteSequenceStatementState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class NoteSequenceState
@@ -186,14 +163,8 @@ class NoteSequenceAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteSequenceAction<Grammar::NoteSequence>
+class NoteSequenceAction<Grammar::NoteSequence> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteSequenceState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class NoteAndExpressionState
@@ -219,14 +190,8 @@ class NoteAndExpressionAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteAndExpressionAction<Grammar::NoteAndExpression>
+class NoteAndExpressionAction<Grammar::NoteAndExpression> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteAndExpressionState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class NoteRepeatEachExpressionState
@@ -252,14 +217,8 @@ class NoteRepeatEachExpressionAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteRepeatEachExpressionAction<Grammar::NoteRepeatEachExpression>
+class NoteRepeatEachExpressionAction<Grammar::NoteRepeatEachExpression> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteRepeatEachExpressionState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -296,14 +255,8 @@ class NoteRepeatExpressionAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteRepeatExpressionAction<Grammar::NoteRepeatExpression>
+class NoteRepeatExpressionAction<Grammar::NoteRepeatExpression> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteRepeatExpressionState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -345,14 +298,8 @@ class NoteAndDurationAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteAndDurationAction<Grammar::NoteAndDuration>
+class NoteAndDurationAction<Grammar::NoteAndDuration> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteAndDurationState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class DurationSetState
@@ -378,14 +325,8 @@ class DurationSetAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class DurationSetAction<Grammar::DurationSet>
+class DurationSetAction<Grammar::DurationSet> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, DurationSetState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class SimpleDurationWithModifierState
@@ -406,14 +347,8 @@ class SimpleDurationWithModifierAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class SimpleDurationWithModifierAction<Grammar::SimpleDurationWithModifier>
+class SimpleDurationWithModifierAction<Grammar::SimpleDurationWithModifier> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, SimpleDurationWithModifierState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class SimpleDurationModifierState
@@ -434,14 +369,8 @@ class SimpleDurationModifierAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class SimpleDurationModifierAction<Grammar::SimpleDurationModifier>
+class SimpleDurationModifierAction<Grammar::SimpleDurationModifier> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, SimpleDurationModifierState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -473,14 +402,8 @@ class SimpleDurationAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class SimpleDurationAction<Grammar::SimpleDuration>
+class SimpleDurationAction<Grammar::SimpleDuration> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, SimpleDurationState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -517,14 +440,8 @@ class SimpleChordAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class SimpleChordAction<Grammar::SimpleChord>
+class SimpleChordAction<Grammar::SimpleChord> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, SimpleChordState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class NoteNumberState
@@ -545,14 +462,8 @@ class NoteNumberAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteNumberAction<Grammar::NoteNumber>
+class NoteNumberAction<Grammar::NoteNumber> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteNumberState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 class NoteOctaveState
@@ -573,14 +484,8 @@ class NoteOctaveAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteOctaveAction<Grammar::NoteOctave>
+class NoteOctaveAction<Grammar::NoteOctave> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteOctaveState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -612,14 +517,8 @@ class NoteNameAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class NoteNameAction<Grammar::NoteName>
+class NoteNameAction<Grammar::NoteName> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, NoteNameState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 template<>
@@ -665,14 +564,8 @@ class RestAction : public pegtl::nothing<TRule>
 };
 
 template<>
-class RestAction<Grammar::Rest>
+class RestAction<Grammar::Rest> : public AssignLocationAction
 {
-public:
-    template<typename... TCommonStates>
-    static void apply(const pegtl::input& in, RestState& st, TCommonStates&...)
-    {
-        st.ASTNode.Location = {in.line(), in.column()};
-    }
 };
 
 } // namespace Parser