OSDN Git Service

AST を定義
authorstarg <starg@users.osdn.me>
Sun, 3 Jul 2016 00:17:39 +0000 (09:17 +0900)
committerstarg <starg@users.osdn.me>
Mon, 4 Jul 2016 15:47:19 +0000 (00:47 +0900)
CMakeLists.txt
include/ast/attribute.hpp [new file with mode: 0644]
include/ast/composition.hpp [new file with mode: 0644]
include/ast/literal.hpp [new file with mode: 0644]
include/ast/module.hpp
include/ast/phrase.hpp [new file with mode: 0644]
include/ast/sourcelocation.hpp [new file with mode: 0644]
include/parser/parser.hpp
src/parser/parser.cpp
src/parser/pch.hpp

index 615dde0..d962f58 100644 (file)
@@ -60,7 +60,7 @@ find_package(Boost COMPONENTS unit_test_framework REQUIRED)
 
 include(cmake/common.cmake)
 
-include_directories("include" ${Boost_INCLUDE_DIRS})
+include_directories("include" ${Boost_INCLUDE_DIRS} ${PEGTLIncludeDir})
 link_directories(${Boost_LIBRARY_DIRS})
 
 add_subdirectory(src)
diff --git a/include/ast/attribute.hpp b/include/ast/attribute.hpp
new file mode 100644 (file)
index 0000000..19cf343
--- /dev/null
@@ -0,0 +1,26 @@
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include <ast/literal.hpp>
+#include <ast/sourcelocation.hpp>
+
+namespace YAMML
+{
+
+namespace AST
+{
+
+class Attribute final
+{
+public:
+    std::string Name;
+    std::vector<Literal> Arguments;
+    SourceLocation Location;
+};
+
+} // namespace AST
+
+} // namespace YAMML
diff --git a/include/ast/composition.hpp b/include/ast/composition.hpp
new file mode 100644 (file)
index 0000000..992f4d7
--- /dev/null
@@ -0,0 +1,61 @@
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include <boost/variant.hpp>
+
+#include <ast/attribute.hpp>
+#include <ast/sourcelocation.hpp>
+
+namespace YAMML
+{
+
+namespace AST
+{
+
+class Command final
+{
+public:
+    std::string Name;
+    std::vector<Literal> Arguments;
+    SourceLocation Location;
+};
+
+class TrackItem final
+{
+public:
+    std::vector<Attribute> Attributes;
+    std::string PhraseName;
+    SourceLocation Location;
+};
+
+class TrackBlock final
+{
+public:
+    int TrackNumber;
+    std::vector<TrackItem> Items;
+    SourceLocation Location;
+};
+
+class TrackListBlock final
+{
+public:
+    std::vector<Attribute> Attributes;
+    std::vector<TrackBlock> Tracks;
+    SourceLocation Location;
+};
+
+class Composition final
+{
+public:
+    std::string Name;
+    std::vector<Attribute> Attributes;
+    std::vector<boost::variant<Command, Attribute, TrackListBlock>> Statements;
+    SourceLocation Location;
+};
+
+} // namespace AST
+
+} // namespace YAMML
diff --git a/include/ast/literal.hpp b/include/ast/literal.hpp
new file mode 100644 (file)
index 0000000..fe293c1
--- /dev/null
@@ -0,0 +1,25 @@
+
+#pragma once
+
+#include <string>
+
+#include <boost/variant.hpp>
+
+#include <ast/sourcelocation.hpp>
+
+namespace YAMML
+{
+
+namespace AST
+{
+
+class Literal final
+{
+public:
+    boost::variant<int, double, std::string> Value;
+    SourceLocation Location;
+};
+
+} // namespace AST
+
+} // namespace YAMML
index ba20998..485d807 100644 (file)
@@ -1,13 +1,27 @@
 
 #pragma once
 
+#include <string>
+#include <unordered_map>
+
+#include <ast/composition.hpp>
+#include <ast/phrase.hpp>
+
 namespace YAMML
 {
 
 namespace AST
 {
 
+class Module final
+{
+public:
 
+private:
+    std::string m_Name;
+    std::unordered_map<std::string, Phrase> m_Phrases;
+    std::unordered_map<std::string, Composition> m_Composition;
+};
 
 } // namespace AST
 
diff --git a/include/ast/phrase.hpp b/include/ast/phrase.hpp
new file mode 100644 (file)
index 0000000..f6e9453
--- /dev/null
@@ -0,0 +1,136 @@
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include <boost/optional.hpp>
+#include <boost/variant.hpp>
+
+#include <ast/attribute.hpp>
+#include <ast/sourcelocation.hpp>
+
+namespace YAMML
+{
+
+namespace AST
+{
+
+class NoteName final
+{
+public:
+    char Name;
+    SourceLocation Location;
+};
+
+class NoteOctave final
+{
+public:
+    int Value;
+    SourceLocation Location;
+};
+
+class NoteNumber final
+{
+public:
+    NoteName Name;
+    boost::optional<NoteOctave> Octave;
+    SourceLocation Location;
+};
+
+class SimpleChord final
+{
+public:
+    std::vector<NoteNumber> Notes;
+    SourceLocation Location;
+};
+
+class SimpleDuration final
+{
+public:
+    int Number;
+    SourceLocation Location;
+};
+
+class SimpleDurationModifier final
+{
+public:
+    int Number;
+    SourceLocation Location;
+};
+
+class SimpleDurationWithModifier final
+{
+public:
+    SimpleDuration Base;
+    boost::optional<SimpleDurationModifier> Modifier;
+    SourceLocation Location;
+};
+
+class DurationSet final
+{
+public:
+    std::vector<SimpleDurationWithModifier> Durations;
+    SourceLocation Location;
+};
+
+class NoteAndDuration final
+{
+public:
+    NoteNumber Note;
+    boost::optional<DurationSet> Duration;
+    SourceLocation Location;
+};
+
+class NoteSequence;
+
+class NoteRepeatExpression final
+{
+public:
+    std::size_t Count;
+    std::vector<boost::variant<NoteAndDuration, boost::recursive_wrapper<NoteSequence>>> Notes;
+    SourceLocation Location;
+};
+
+class NoteRepeatEachExpression final
+{
+public:
+    std::size_t Count;
+    std::vector<NoteRepeatExpression> Notes;
+    SourceLocation Location;
+};
+
+class NoteAndExpression final
+{
+public:
+    std::vector<NoteRepeatEachExpression> Notes;
+    SourceLocation Location;
+};
+
+class NoteSequence final
+{
+public:
+    std::vector<NoteAndExpression> Notes;
+    SourceLocation Location;
+};
+
+class NoteSequenceBlock final
+{
+public:
+    std::vector<Attribute> Attributes;
+    std::vector<NoteSequence> Sequences;
+    SourceLocation Location;
+};
+
+class Phrase final
+{
+public:
+    std::string Name;
+    std::vector<Attribute> Attributes;
+    std::vector<boost::variant<NoteSequence, NoteSequenceBlock>> Statements;
+    SourceLocation Location;
+};
+
+} // namespace AST
+
+} // namespace YAMML
diff --git a/include/ast/sourcelocation.hpp b/include/ast/sourcelocation.hpp
new file mode 100644 (file)
index 0000000..4ecd318
--- /dev/null
@@ -0,0 +1,20 @@
+
+#pragma once
+
+#include <cstddef>
+
+namespace YAMML
+{
+
+namespace AST
+{
+
+struct SourceLocation
+{
+    std::size_t Line;
+    std::size_t Column;
+};
+
+} // namespace AST
+
+} // namespace YAMML
index d20d3e3..5a353f8 100644 (file)
@@ -13,7 +13,12 @@ namespace Parser
 
 class YAMMLParser
 {
-    
+public:
+
+
+
+private:
+    std::string m_Name;
 };
 
 } // namespace Parser
index e69de29..227b345 100644 (file)
@@ -0,0 +1,14 @@
+
+#include <parser/parser.hpp>
+
+namespace YAMML
+{
+
+namespace Parser
+{
+
+
+
+} // namespace Parser
+
+} // namespace YAMML
index 99ddf32..1aaaf52 100644 (file)
@@ -1,2 +1,11 @@
 
 #pragma once
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include <boost/optional.hpp>
+#include <boost/variant.hpp>
+
+#include <pegtl.hh>