--- /dev/null
+
+#pragma once
+
+#include <type_traits>
+
+#include <pegtl.hh>
+#include <pegtl/contrib/changes.hh>
+
+namespace YAMML
+{
+
+namespace Parser
+{
+
+// Based on pegtl/contrib/changes.hh, which is "Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey" (https://github.com/ColinH/PEGTL/)
+
+template<typename TRule, typename TState, template<typename...> class TBase = pegtl::normal>
+class ChangeState : public TBase<TRule>
+{
+public:
+ template<
+ pegtl::apply_mode TApplyMode,
+ template<typename...> class TAction,
+ template<typename...> class TControl,
+ typename TInput,
+ typename TParentState,
+ typename... TCommonStates
+ >
+ static bool match(TInput& in, TParentState&& parentState, TCommonStates&... commonStates)
+ {
+ pegtl::internal::state_disable_helper<TApplyMode, TState> childState;
+
+ if (TBase<TRule>::template match<TApplyMode, TAction, TControl>(in, childState, commonStates...))
+ {
+ childState.success(parentState, commonStates...);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+};
+
+template<typename TRule, typename TState, template<typename...> class TAction, template<typename...> class TBase = pegtl::normal>
+class ChangeStateAndAction : public ChangeState<TRule, TState, pegtl::change_both_helper<TAction, TBase>::template change_action>
+{
+};
+
+} // namespace Parser
+
+} // namespace YAMML
#pragma once
#include <pegtl.hh>
-#include <pegtl/contrib/changes.hh>
#include "action_state_attribute.hpp"
#include "action_state_composition.hpp"
#include "action_state_literal.hpp"
#include "action_state_phrase.hpp"
+
+#include "changes.hpp"
+
#include "error_control.hpp"
#include "parser_attribute.hpp"
#include "parser_composition.hpp"
template<>
class Control<Grammar::Composition>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::Composition,
CompositionState,
CompositionAction,
template<>
class Control<Grammar::Attribute>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::Attribute,
AttributeState,
AttributeAction,
template<>
class Control<Grammar::AttributeArgument>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::AttributeArgument,
AttributeArgumentState,
AttributeArgumentAction,
template<>
class Control<Grammar::Value>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::Value,
ValueState,
ValueAction,
template<char TQuote>
class Control<Grammar::QuotedStringLiteral<TQuote>>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::QuotedStringLiteral<TQuote>,
EscapeState,
EscapeAction,
template<>
class Control<Grammar::TrackListBlock>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::TrackListBlock,
TrackListBlockState,
TrackListBlockAction,
template<>
class Control<Grammar::TrackBlock>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::TrackBlock,
TrackBlockState,
TrackBlockAction,
template<>
class Control<Grammar::TrackItem>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::TrackItem,
TrackItemState,
TrackItemAction,
template<>
class Control<Grammar::Command>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::Command,
CommandState,
CommandAction,
template<>
class Control<Grammar::CommandArgument>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::CommandArgument,
CommandArgumentState,
CommandArgumentAction,
template<>
class Control<Grammar::Phrase>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::Phrase,
PhraseState,
PhraseAction,
template<>
class Control<Grammar::NoteSequenceBlock>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteSequenceBlock,
NoteSequenceBlockState,
NoteSequenceBlockAction,
template<>
class Control<Grammar::NoteSequenceBlockWithoutAttributes>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteSequenceBlockWithoutAttributes,
NoteSequenceBlockWithoutAttributesState,
NoteSequenceBlockWithoutAttributesAction,
template<>
class Control<Grammar::NoteSequenceStatement>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteSequenceStatement,
NoteSequenceStatementState,
NoteSequenceStatementAction,
template<>
class Control<Grammar::NoteSequence>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteSequence,
NoteSequenceState,
NoteSequenceAction,
template<>
class Control<Grammar::NoteAndExpression>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteAndExpression,
NoteAndExpressionState,
NoteAndExpressionAction,
template<>
class Control<Grammar::NoteRepeatEachExpression>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteRepeatEachExpression,
NoteRepeatEachExpressionState,
NoteRepeatEachExpressionAction,
template<>
class Control<Grammar::NoteRepeatExpression>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteRepeatExpression,
NoteRepeatExpressionState,
NoteRepeatExpressionAction,
template<>
class Control<Grammar::NoteAndDuration>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteAndDuration,
NoteAndDurationState,
NoteAndDurationAction,
template<>
class Control<Grammar::DurationSet>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::DurationSet,
DurationSetState,
DurationSetAction,
template<>
class Control<Grammar::SimpleDurationWithModifier>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::SimpleDurationWithModifier,
SimpleDurationWithModifierState,
SimpleDurationWithModifierAction,
template<>
class Control<Grammar::SimpleDurationModifier>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::SimpleDurationModifier,
SimpleDurationModifierState,
SimpleDurationModifierAction,
template<>
class Control<Grammar::SimpleDuration>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::SimpleDuration,
SimpleDurationState,
SimpleDurationAction,
template<>
class Control<Grammar::SimpleChord>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::SimpleChord,
SimpleChordState,
SimpleChordAction,
template<>
class Control<Grammar::NoteNumber>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteNumber,
NoteNumberState,
NoteNumberAction,
template<>
class Control<Grammar::NoteOctave>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteOctave,
NoteOctaveState,
NoteOctaveAction,
template<>
class Control<Grammar::NoteName>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::NoteName,
NoteNameState,
NoteNameAction,
template<>
class Control<Grammar::Rest>
- : public pegtl::change_state_and_action<
+ : public ChangeStateAndAction<
Grammar::Rest,
RestState,
RestAction,