#pragma once
+#include <stdexcept>
#include <string>
#include <pegtl.hh>
#include <ast/composition.hpp>
#include <ast/module.hpp>
+#include <message/message.hpp>
#include <parser/parser.hpp>
#include "action.hpp"
class TrackBlockAction<Grammar::UnsignedInteger>
{
public:
- template<typename... TCommonStates>
- static void apply(const pegtl::input& in, TrackBlockState& st, TCommonStates&...)
+ template<typename TCompiler, typename... TCommonStates>
+ static void apply(const pegtl::input& in, TrackBlockState& st, TCompiler& compiler, TCommonStates&...)
{
- st.ASTNode.TrackNumber = std::stoul(in.string());
+ try
+ {
+ st.ASTNode.TrackNumber = std::stoul(in.string());
+ }
+ catch (const std::out_of_range&)
+ {
+ compiler.AddMessage(
+ Message::MessageItem{
+ Message::MessageKind::Error,
+ Message::MessageID::IntegerOutOfRange,
+ compiler.GetSourceName(),
+ {in.line(), in.column()},
+ {in.string()}
+ }
+ );
+ }
}
};
#pragma once
+#include <stdexcept>
#include <string>
#include <utility>
#endif
#include <ast/literal.hpp>
+#include <message/message.hpp>
#include "action.hpp"
#include "parser_literal.hpp"
class ValueAction<Grammar::SignedInteger>
{
public:
- template<typename TState, typename... TCommonStates>
- static void apply(const pegtl::input& in, TState& st, TCommonStates&...)
+ template<typename TState, typename TCompiler, typename... TCommonStates>
+ static void apply(const pegtl::input& in, TState& st, TCompiler& compiler, TCommonStates&...)
{
- st.ASTNode.Value = std::stol(in.string());
+ try
+ {
+ st.ASTNode.Value = std::stol(in.string());
+ }
+ catch (const std::out_of_range&)
+ {
+ compiler.AddMessage(
+ Message::MessageItem{
+ Message::MessageKind::Error,
+ Message::MessageID::IntegerOutOfRange,
+ compiler.GetSourceName(),
+ {in.line(), in.column()},
+ {in.string()}
+ }
+ );
+ }
}
};
#pragma once
#include <algorithm>
+#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <ast/module.hpp>
#include <ast/phrase.hpp>
+#include <message/message.hpp>
#include <parser/parser.hpp>
#include "action.hpp"
class NoteRepeatEachExpressionAction<Grammar::UnsignedInteger>
{
public:
- template<typename... TCommonStates>
- static void apply(const pegtl::input& in, NoteRepeatEachExpressionState& st, TCommonStates&...)
- {
- st.ASTNode.Count = std::stoul(in.string());
+ template<typename TCompiler, typename... TCommonStates>
+ static void apply(const pegtl::input& in, NoteRepeatEachExpressionState& st, TCompiler& compiler, TCommonStates&...)
+ {
+ try
+ {
+ st.ASTNode.Count = std::stoul(in.string());
+ }
+ catch (const std::out_of_range&)
+ {
+ compiler.AddMessage(
+ Message::MessageItem{
+ Message::MessageKind::Error,
+ Message::MessageID::IntegerOutOfRange,
+ compiler.GetSourceName(),
+ {in.line(), in.column()},
+ {in.string()}
+ }
+ );
+ }
}
};
class NoteRepeatExpressionAction<Grammar::UnsignedInteger>
{
public:
- template<typename... TCommonStates>
- static void apply(const pegtl::input& in, NoteRepeatExpressionState& st, TCommonStates&...)
- {
- st.ASTNode.Count = std::stoul(in.string());
+ template<typename TCompiler, typename... TCommonStates>
+ static void apply(const pegtl::input& in, NoteRepeatExpressionState& st, TCompiler& compiler, TCommonStates&...)
+ {
+ try
+ {
+ st.ASTNode.Count = std::stoul(in.string());
+ }
+ catch (const std::out_of_range&)
+ {
+ compiler.AddMessage(
+ Message::MessageItem{
+ Message::MessageKind::Error,
+ Message::MessageID::IntegerOutOfRange,
+ compiler.GetSourceName(),
+ {in.line(), in.column()},
+ {in.string()}
+ }
+ );
+ }
}
};
class SimpleDurationModifierAction<Grammar::UnsignedInteger>
{
public:
- template<typename... TCommonStates>
- static void apply(const pegtl::input& in, SimpleDurationModifierState& st, TCommonStates&...)
- {
- st.ASTNode.Number = std::stoul(in.string());
+ template<typename TCompiler, typename... TCommonStates>
+ static void apply(const pegtl::input& in, SimpleDurationModifierState& st, TCompiler& compiler, TCommonStates&...)
+ {
+ try
+ {
+ st.ASTNode.Number = std::stoul(in.string());
+ }
+ catch (const std::out_of_range&)
+ {
+ compiler.AddMessage(
+ Message::MessageItem{
+ Message::MessageKind::Error,
+ Message::MessageID::IntegerOutOfRange,
+ compiler.GetSourceName(),
+ {in.line(), in.column()},
+ {in.string()}
+ }
+ );
+ }
}
};
class SimpleDurationAction<Grammar::UnsignedInteger>
{
public:
- template<typename... TCommonStates>
- static void apply(const pegtl::input& in, SimpleDurationState& st, TCommonStates&...)
- {
- st.ASTNode.Number = std::stoul(in.string());
+ template<typename TCompiler, typename... TCommonStates>
+ static void apply(const pegtl::input& in, SimpleDurationState& st, TCompiler& compiler, TCommonStates&...)
+ {
+ try
+ {
+ st.ASTNode.Number = std::stoul(in.string());
+ }
+ catch (const std::out_of_range&)
+ {
+ compiler.AddMessage(
+ Message::MessageItem{
+ Message::MessageKind::Error,
+ Message::MessageID::IntegerOutOfRange,
+ compiler.GetSourceName(),
+ {in.line(), in.column()},
+ {in.string()}
+ }
+ );
+ }
}
};
class NoteOctaveAction<Grammar::SignedInteger>
{
public:
- template<typename... TCommonStates>
- static void apply(const pegtl::input& in, NoteOctaveState& st, TCommonStates&...)
- {
- st.ASTNode.Value = std::stoi(in.string());
+ template<typename TCompiler, typename... TCommonStates>
+ static void apply(const pegtl::input& in, NoteOctaveState& st, TCompiler& compiler, TCommonStates&...)
+ {
+ try
+ {
+ st.ASTNode.Value = std::stoi(in.string());
+ }
+ catch (const std::out_of_range&)
+ {
+ compiler.AddMessage(
+ Message::MessageItem{
+ Message::MessageKind::Error,
+ Message::MessageID::IntegerOutOfRange,
+ compiler.GetSourceName(),
+ {in.line(), in.column()},
+ {in.string()}
+ }
+ );
+ }
}
};