From feca1ed7c4fb47c94f14da26a33ec4ac7352146b Mon Sep 17 00:00:00 2001 From: starg Date: Fri, 15 Jul 2016 20:55:37 +0900 Subject: [PATCH] =?utf8?q?Action=20=E3=81=A8=20State=20=E3=82=92=E8=A4=87?= =?utf8?q?=E6=95=B0=E5=80=8B=E3=81=AE=20State=20=E3=81=AB=E5=AF=BE?= =?utf8?q?=E5=BF=9C=E3=81=95=E3=81=9B=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/parser/action_state_attribute.hpp | 20 +++-- src/parser/action_state_composition.hpp | 50 ++++++----- src/parser/action_state_literal.hpp | 20 ++--- src/parser/action_state_phrase.hpp | 149 +++++++++++++++++++------------- 4 files changed, 140 insertions(+), 99 deletions(-) diff --git a/src/parser/action_state_attribute.hpp b/src/parser/action_state_attribute.hpp index ff4ca6e..b1e3fd3 100644 --- a/src/parser/action_state_attribute.hpp +++ b/src/parser/action_state_attribute.hpp @@ -17,8 +17,8 @@ namespace Parser class AttributeState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Attributes.push_back(ASTNode); } @@ -35,7 +35,8 @@ template<> class AttributeAction { public: - static void apply(const pegtl::input& in, AttributeState& st) + template + static void apply(const pegtl::input& in, AttributeState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -45,7 +46,8 @@ template<> class AttributeAction { public: - static void apply(const pegtl::input& in, AttributeState& st) + template + static void apply(const pegtl::input& in, AttributeState& st, TCommonStates&...) { st.ASTNode.Name = in.string(); } @@ -54,8 +56,8 @@ public: class AttributeArgumentState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Arguments.push_back(ASTNode); } @@ -72,7 +74,8 @@ template<> class AttributeArgumentAction { public: - static void apply(const pegtl::input& in, AttributeArgumentState& st) + template + static void apply(const pegtl::input& in, AttributeArgumentState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -87,7 +90,8 @@ template<> class AttributeKeyAction { public: - static void apply(const pegtl::input& in, AttributeArgumentState& st) + template + static void apply(const pegtl::input& in, AttributeArgumentState& st, TCommonStates&...) { st.ASTNode.Name = in.string(); } diff --git a/src/parser/action_state_composition.hpp b/src/parser/action_state_composition.hpp index 47144e3..2f5796e 100644 --- a/src/parser/action_state_composition.hpp +++ b/src/parser/action_state_composition.hpp @@ -19,7 +19,8 @@ namespace Parser class CompositionState { public: - void success(AST::Module& mod) + template + void success(AST::Module& mod, TCommonStates&...) { mod.Add(ASTNode); } @@ -36,7 +37,8 @@ template<> class CompositionAction { public: - static void apply(const pegtl::input& in, CompositionState& st) + template + static void apply(const pegtl::input& in, CompositionState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -45,8 +47,8 @@ public: class TrackListBlockState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Statements.emplace_back(ASTNode); } @@ -63,7 +65,8 @@ template<> class TrackListBlockAction { public: - static void apply(const pegtl::input& in, TrackListBlockState& st) + template + static void apply(const pegtl::input& in, TrackListBlockState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -72,8 +75,8 @@ public: class TrackBlockState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Tracks.push_back(ASTNode); } @@ -90,7 +93,8 @@ template<> class TrackBlockAction { public: - static void apply(const pegtl::input& in, TrackBlockState& st) + template + static void apply(const pegtl::input& in, TrackBlockState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -100,7 +104,8 @@ template<> class TrackBlockAction { public: - static void apply(const pegtl::input& in, TrackBlockState& st) + template + static void apply(const pegtl::input& in, TrackBlockState& st, TCommonStates&...) { st.ASTNode.TrackNumber = std::stoul(in.string()); } @@ -109,8 +114,8 @@ public: class TrackItemState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Items.push_back(ASTNode); } @@ -127,7 +132,8 @@ template<> class TrackItemAction { public: - static void apply(const pegtl::input& in, TrackItemState& st) + template + static void apply(const pegtl::input& in, TrackItemState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -137,7 +143,8 @@ template<> class TrackItemAction { public: - static void apply(const pegtl::input& in, TrackItemState& st) + template + static void apply(const pegtl::input& in, TrackItemState& st, TCommonStates&...) { st.ASTNode.PhraseName = in.string(); } @@ -146,8 +153,8 @@ public: class CommandState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Statements.push_back(ASTNode); } @@ -164,7 +171,8 @@ template<> class CommandAction { public: - static void apply(const pegtl::input& in, CommandState& st) + template + static void apply(const pegtl::input& in, CommandState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -174,7 +182,8 @@ template<> class CommandAction { public: - static void apply(const pegtl::input& in, CommandState& st) + template + static void apply(const pegtl::input& in, CommandState& st, TCommonStates&...) { st.ASTNode.Name = in.string(); } @@ -183,8 +192,8 @@ public: class CommandArgumentState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Arguments.push_back(ASTNode); } @@ -201,7 +210,8 @@ template<> class CommandArgumentAction { public: - static void apply(const pegtl::input& in, CommandArgumentState& st) + template + static void apply(const pegtl::input& in, CommandArgumentState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } diff --git a/src/parser/action_state_literal.hpp b/src/parser/action_state_literal.hpp index 13661fa..49f1c72 100644 --- a/src/parser/action_state_literal.hpp +++ b/src/parser/action_state_literal.hpp @@ -20,8 +20,8 @@ namespace Parser class ValueState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Value = ASTNode; } @@ -38,8 +38,8 @@ template<> class ValueAction { public: - template - static void apply(const pegtl::input& in, TState& st) + template + static void apply(const pegtl::input& in, TState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -49,8 +49,8 @@ template<> class ValueAction { public: - template - static void apply(const pegtl::input& in, TState& st) + template + static void apply(const pegtl::input& in, TState& st, TCommonStates&...) { st.ASTNode.Value = std::stol(in.string()); } @@ -60,8 +60,8 @@ template<> class ValueAction { public: - template - static void apply(const pegtl::input& in, TState& st) + template + static void apply(const pegtl::input& in, TState& st, TCommonStates&...) { st.ASTNode.Value = in.string(); } @@ -100,8 +100,8 @@ class EscapeAction : public pegtl::unescape::unescape_c - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Value = std::move(unescaped); } diff --git a/src/parser/action_state_phrase.hpp b/src/parser/action_state_phrase.hpp index 555182a..ac210d6 100644 --- a/src/parser/action_state_phrase.hpp +++ b/src/parser/action_state_phrase.hpp @@ -21,7 +21,8 @@ namespace Parser class PhraseState { public: - void success(AST::Module& mod) + template + void success(AST::Module& mod, TCommonStates&...) { mod.Add(ASTNode); } @@ -43,7 +44,8 @@ template<> class PhraseAction { public: - static void apply(const pegtl::input& in, PhraseState& st) + template + static void apply(const pegtl::input& in, PhraseState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -53,7 +55,8 @@ template<> class PhraseAction { public: - static void apply(const pegtl::input& in, PhraseState& st) + template + static void apply(const pegtl::input& in, PhraseState& st, TCommonStates&...) { st.ASTNode.Name = in.string(); } @@ -62,8 +65,8 @@ public: class NoteSequenceBlockState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Sequences.emplace_back(ASTNode); } @@ -85,7 +88,8 @@ template<> class NoteSequenceBlockAction { public: - static void apply(const pegtl::input& in, NoteSequenceBlockState& st) + template + static void apply(const pegtl::input& in, NoteSequenceBlockState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -94,8 +98,8 @@ public: class NoteSequenceBlockWithoutAttributesState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.OnParse(ASTNode); } @@ -112,7 +116,8 @@ template<> class NoteSequenceBlockWithoutAttributesAction { public: - static void apply(const pegtl::input& in, NoteSequenceBlockWithoutAttributesState& st) + template + static void apply(const pegtl::input& in, NoteSequenceBlockWithoutAttributesState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -121,8 +126,8 @@ public: class NoteSequenceStatementState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Sequences.emplace_back(ASTNode); } @@ -144,7 +149,8 @@ template<> class NoteSequenceStatementAction { public: - static void apply(const pegtl::input& in, NoteSequenceStatementState& st) + template + static void apply(const pegtl::input& in, NoteSequenceStatementState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -153,8 +159,8 @@ public: class NoteSequenceState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.OnParse(ASTNode); } @@ -171,7 +177,8 @@ template<> class NoteSequenceAction { public: - static void apply(const pegtl::input& in, NoteSequenceState& st) + template + static void apply(const pegtl::input& in, NoteSequenceState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -180,8 +187,8 @@ public: class NoteAndExpressionState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Notes.push_back(ASTNode); } @@ -203,7 +210,8 @@ template<> class NoteAndExpressionAction { public: - static void apply(const pegtl::input& in, NoteAndExpressionState& st) + template + static void apply(const pegtl::input& in, NoteAndExpressionState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -212,8 +220,8 @@ public: class NoteRepeatEachExpressionState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Notes.emplace_back(ASTNode); } @@ -235,7 +243,8 @@ template<> class NoteRepeatEachExpressionAction { public: - static void apply(const pegtl::input& in, NoteRepeatEachExpressionState& st) + template + static void apply(const pegtl::input& in, NoteRepeatEachExpressionState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -245,7 +254,8 @@ template<> class NoteRepeatEachExpressionAction { public: - static void apply(const pegtl::input& in, NoteRepeatEachExpressionState& st) + template + static void apply(const pegtl::input& in, NoteRepeatEachExpressionState& st, TCommonStates&...) { st.ASTNode.Count = std::stoul(in.string()); } @@ -254,8 +264,8 @@ public: class NoteRepeatExpressionState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Notes.emplace_back(ASTNode); } @@ -277,7 +287,8 @@ template<> class NoteRepeatExpressionAction { public: - static void apply(const pegtl::input& in, NoteRepeatExpressionState& st) + template + static void apply(const pegtl::input& in, NoteRepeatExpressionState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -287,7 +298,8 @@ template<> class NoteRepeatExpressionAction { public: - static void apply(const pegtl::input& in, NoteRepeatExpressionState& st) + template + static void apply(const pegtl::input& in, NoteRepeatExpressionState& st, TCommonStates&...) { st.ASTNode.Count = std::stoul(in.string()); } @@ -296,8 +308,8 @@ public: class NoteAndDurationState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Notes.emplace_back(ASTNode); } @@ -324,7 +336,8 @@ template<> class NoteAndDurationAction { public: - static void apply(const pegtl::input& in, NoteAndDurationState& st) + template + static void apply(const pegtl::input& in, NoteAndDurationState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -333,8 +346,8 @@ public: class DurationSetState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Duration = ASTNode; } @@ -356,7 +369,8 @@ template<> class DurationSetAction { public: - static void apply(const pegtl::input& in, DurationSetState& st) + template + static void apply(const pegtl::input& in, DurationSetState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -365,8 +379,8 @@ public: class SimpleDurationWithModifierState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.OnParse(ASTNode); } @@ -383,7 +397,8 @@ template<> class SimpleDurationWithModifierAction { public: - static void apply(const pegtl::input& in, SimpleDurationWithModifierState& st) + template + static void apply(const pegtl::input& in, SimpleDurationWithModifierState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -392,8 +407,8 @@ public: class SimpleDurationModifierState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Modifier = ASTNode; } @@ -410,7 +425,8 @@ template<> class SimpleDurationModifierAction { public: - static void apply(const pegtl::input& in, SimpleDurationModifierState& st) + template + static void apply(const pegtl::input& in, SimpleDurationModifierState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -420,7 +436,8 @@ template<> class SimpleDurationModifierAction { public: - static void apply(const pegtl::input& in, SimpleDurationModifierState& st) + template + static void apply(const pegtl::input& in, SimpleDurationModifierState& st, TCommonStates&...) { st.ASTNode.Number = std::stoul(in.string()); } @@ -429,8 +446,8 @@ public: class SimpleDurationState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Base = ASTNode; } @@ -447,7 +464,8 @@ template<> class SimpleDurationAction { public: - static void apply(const pegtl::input& in, SimpleDurationState& st) + template + static void apply(const pegtl::input& in, SimpleDurationState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -457,7 +475,8 @@ template<> class SimpleDurationAction { public: - static void apply(const pegtl::input& in, SimpleDurationState& st) + template + static void apply(const pegtl::input& in, SimpleDurationState& st, TCommonStates&...) { st.ASTNode.Number = std::stoul(in.string()); } @@ -466,8 +485,8 @@ public: class SimpleChordState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Note = ASTNode; } @@ -489,7 +508,8 @@ template<> class SimpleChordAction { public: - static void apply(const pegtl::input& in, SimpleChordState& st) + template + static void apply(const pegtl::input& in, SimpleChordState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -498,8 +518,8 @@ public: class NoteNumberState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.OnParse(ASTNode); } @@ -516,7 +536,8 @@ template<> class NoteNumberAction { public: - static void apply(const pegtl::input& in, NoteNumberState& st) + template + static void apply(const pegtl::input& in, NoteNumberState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -525,8 +546,8 @@ public: class NoteOctaveState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Octave = ASTNode; } @@ -543,7 +564,8 @@ template<> class NoteOctaveAction { public: - static void apply(const pegtl::input& in, NoteOctaveState& st) + template + static void apply(const pegtl::input& in, NoteOctaveState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -553,7 +575,8 @@ template<> class NoteOctaveAction { public: - static void apply(const pegtl::input& in, NoteOctaveState& st) + template + static void apply(const pegtl::input& in, NoteOctaveState& st, TCommonStates&...) { st.ASTNode.Value = std::stoi(in.string()); } @@ -562,8 +585,8 @@ public: class NoteNameState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Name = ASTNode; } @@ -580,7 +603,8 @@ template<> class NoteNameAction { public: - static void apply(const pegtl::input& in, NoteNameState& st) + template + static void apply(const pegtl::input& in, NoteNameState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } @@ -590,7 +614,8 @@ template<> class NoteNameAction { public: - static void apply(const pegtl::input& in, NoteNameState& st) + template + static void apply(const pegtl::input& in, NoteNameState& st, TCommonStates&...) { st.ASTNode.Name = in.string().at(0); } @@ -600,7 +625,8 @@ template<> class NoteNameAction { public: - static void apply(const pegtl::input& in, NoteNameState& st) + template + static void apply(const pegtl::input& in, NoteNameState& st, TCommonStates&...) { st.ASTNode.Minor = 0; @@ -612,8 +638,8 @@ public: class RestState { public: - template - void success(TState& st) + template + void success(TParentState& st, TCommonStates&...) { st.ASTNode.Note = ASTNode; } @@ -630,7 +656,8 @@ template<> class RestAction { public: - static void apply(const pegtl::input& in, RestState& st) + template + static void apply(const pegtl::input& in, RestState& st, TCommonStates&...) { st.ASTNode.Location = {in.line(), in.column()}; } -- 2.11.0