From d830c7c2550109ac8def7625cd379425575812c9 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 7 Nov 2013 13:24:01 -0800 Subject: [PATCH] Put rule classes in their own files --- TreeSitter.xcodeproj/project.pbxproj | 44 +++++++++- spec/rules_spec.cpp | 14 +--- spec_helper.h | 10 +++ src/rules.cpp | 118 --------------------------- src/rules.h | 86 ++----------------- src/rules/blank.cpp | 24 ++++++ src/rules/blank.h | 19 +++++ src/rules/char.cpp | 27 ++++++ src/rules/char.h | 21 +++++ src/rules/choice.cpp | 30 +++++++ src/rules/choice.h | 23 ++++++ src/rules/rule.h | 22 +++++ src/rules/seq.cpp | 32 ++++++++ src/rules/seq.h | 23 ++++++ src/rules/symbol.cpp | 25 ++++++ src/rules/symbol.h | 21 +++++ src/transition_map.h | 2 - 17 files changed, 326 insertions(+), 215 deletions(-) delete mode 100644 src/rules.cpp create mode 100644 src/rules/blank.cpp create mode 100644 src/rules/blank.h create mode 100644 src/rules/char.cpp create mode 100644 src/rules/char.h create mode 100644 src/rules/choice.cpp create mode 100644 src/rules/choice.h create mode 100644 src/rules/rule.h create mode 100644 src/rules/seq.cpp create mode 100644 src/rules/seq.h create mode 100644 src/rules/symbol.cpp create mode 100644 src/rules/symbol.h diff --git a/TreeSitter.xcodeproj/project.pbxproj b/TreeSitter.xcodeproj/project.pbxproj index 5bbb12c3..77785620 100644 --- a/TreeSitter.xcodeproj/project.pbxproj +++ b/TreeSitter.xcodeproj/project.pbxproj @@ -7,9 +7,13 @@ objects = { /* Begin PBXBuildFile section */ + 12130605182C348F00FCF928 /* char.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12130603182C348F00FCF928 /* char.cpp */; }; + 1213060B182C389100FCF928 /* symbol.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12130609182C389100FCF928 /* symbol.cpp */; }; + 1213060E182C398300FCF928 /* choice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1213060C182C398300FCF928 /* choice.cpp */; }; + 12130611182C3A1100FCF928 /* blank.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1213060F182C3A1100FCF928 /* blank.cpp */; }; + 12130614182C3A1700FCF928 /* seq.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12130612182C3A1700FCF928 /* seq.cpp */; }; 1214930E181E200B008E9BDA /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 121492E9181E200B008E9BDA /* main.cpp */; }; 1214930F181E200B008E9BDA /* rules_spec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 121492EA181E200B008E9BDA /* rules_spec.cpp */; }; - 12E71853181D081C0051A649 /* rules.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12E71851181D081C0051A649 /* rules.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -26,6 +30,17 @@ /* Begin PBXFileReference section */ 121306011829FAED00FCF928 /* spec_helper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = spec_helper.h; sourceTree = SOURCE_ROOT; }; + 12130603182C348F00FCF928 /* char.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = char.cpp; sourceTree = ""; }; + 12130604182C348F00FCF928 /* char.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = char.h; sourceTree = ""; }; + 12130607182C374800FCF928 /* rule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rule.h; sourceTree = ""; }; + 12130609182C389100FCF928 /* symbol.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = symbol.cpp; sourceTree = ""; }; + 1213060A182C389100FCF928 /* symbol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = symbol.h; sourceTree = ""; }; + 1213060C182C398300FCF928 /* choice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = choice.cpp; sourceTree = ""; }; + 1213060D182C398300FCF928 /* choice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = choice.h; sourceTree = ""; }; + 1213060F182C3A1100FCF928 /* blank.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = blank.cpp; sourceTree = ""; }; + 12130610182C3A1100FCF928 /* blank.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = blank.h; sourceTree = ""; }; + 12130612182C3A1700FCF928 /* seq.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = seq.cpp; sourceTree = ""; }; + 12130613182C3A1700FCF928 /* seq.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = seq.h; sourceTree = ""; }; 12149265181E200B008E9BDA /* igloo-tests_CXX_prefix.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "igloo-tests_CXX_prefix.hxx"; sourceTree = ""; }; 12149266181E200B008E9BDA /* igloo-tests_CXX_prefix.hxx.gch */ = {isa = PBXFileReference; lastKnownFileType = file; path = "igloo-tests_CXX_prefix.hxx.gch"; sourceTree = ""; }; 12149267181E200B008E9BDA /* snowhouse-tests_CXX_prefix.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = "snowhouse-tests_CXX_prefix.hxx"; sourceTree = ""; }; @@ -101,7 +116,6 @@ 121492EA181E200B008E9BDA /* rules_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = rules_spec.cpp; path = spec/rules_spec.cpp; sourceTree = SOURCE_ROOT; }; 12C344421822F27700B07BE3 /* transition_map.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = transition_map.h; sourceTree = ""; }; 12E71794181D02A80051A649 /* specs */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = specs; sourceTree = BUILT_PRODUCTS_DIR; }; - 12E71851181D081C0051A649 /* rules.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rules.cpp; sourceTree = ""; }; 12E71852181D081C0051A649 /* rules.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rules.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -116,6 +130,24 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 12130602182C344400FCF928 /* rules */ = { + isa = PBXGroup; + children = ( + 1213060F182C3A1100FCF928 /* blank.cpp */, + 12130610182C3A1100FCF928 /* blank.h */, + 12130603182C348F00FCF928 /* char.cpp */, + 12130604182C348F00FCF928 /* char.h */, + 1213060C182C398300FCF928 /* choice.cpp */, + 1213060D182C398300FCF928 /* choice.h */, + 12130607182C374800FCF928 /* rule.h */, + 12130612182C3A1700FCF928 /* seq.cpp */, + 12130613182C3A1700FCF928 /* seq.h */, + 12130609182C389100FCF928 /* symbol.cpp */, + 1213060A182C389100FCF928 /* symbol.h */, + ); + path = rules; + sourceTree = ""; + }; 1214925C181E200B008E9BDA /* externals */ = { isa = PBXGroup; children = ( @@ -327,7 +359,7 @@ 12E71701181D01890051A649 /* src */ = { isa = PBXGroup; children = ( - 12E71851181D081C0051A649 /* rules.cpp */, + 12130602182C344400FCF928 /* rules */, 12E71852181D081C0051A649 /* rules.h */, 12C344421822F27700B07BE3 /* transition_map.h */, ); @@ -404,9 +436,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 12E71853181D081C0051A649 /* rules.cpp in Sources */, + 12130614182C3A1700FCF928 /* seq.cpp in Sources */, 1214930F181E200B008E9BDA /* rules_spec.cpp in Sources */, + 12130611182C3A1100FCF928 /* blank.cpp in Sources */, + 1213060E182C398300FCF928 /* choice.cpp in Sources */, 1214930E181E200B008E9BDA /* main.cpp in Sources */, + 12130605182C348F00FCF928 /* char.cpp in Sources */, + 1213060B182C389100FCF928 /* symbol.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/spec/rules_spec.cpp b/spec/rules_spec.cpp index dbd5c84a..1ac05e7d 100644 --- a/spec/rules_spec.cpp +++ b/spec/rules_spec.cpp @@ -1,18 +1,6 @@ +#include "spec_helper.h" #include "rules.h" #include "transition_map.h" -#include - -using namespace std; -using namespace igloo; -using namespace tree_sitter; - -EqualsContainerConstraint< - TransitionMap, - bool (*)(const TransitionMap::pair_type &, const TransitionMap::pair_type &) -> -EqualsTransitionMap(const TransitionMap &expected) { - return EqualsContainer(expected, TransitionMap::elements_equal); -} Describe(Rules) { Describe(transitions) { diff --git a/spec_helper.h b/spec_helper.h index 2e2644ff..a548b2b0 100644 --- a/spec_helper.h +++ b/spec_helper.h @@ -5,6 +5,10 @@ #include "transition_map.h" #include "rules.h" +using namespace igloo; +using namespace tree_sitter; + +// Assertion helpers for transition maps namespace snowhouse { template<> std::string Stringize(const tree_sitter::TransitionMap &map) { @@ -19,4 +23,10 @@ namespace snowhouse { } } +typedef TransitionMap tmap; +typedef bool (* tmap_comparator)(const tmap::pair_type &, const tmap::pair_type &); +EqualsContainerConstraint EqualsTransitionMap(const tmap &expected) { + return EqualsContainer(expected, tmap::elements_equal); +} + #endif diff --git a/src/rules.cpp b/src/rules.cpp deleted file mode 100644 index f3cd192c..00000000 --- a/src/rules.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "rules.h" -#include "spec_helper.h" -#include "transition_map.h" - -using namespace std; - -namespace tree_sitter { - namespace rules { - - // Constructors - Blank::Blank() {} - Symbol::Symbol(int id) : id(id) {}; - Char::Char(char value) : value(value) {}; - Seq::Seq(const Rule &left, const Rule &right) : left(left.copy()), right(right.copy()) {}; - Seq::Seq(const Rule *left, const Rule *right) : left(left), right(right) {}; - Seq::Seq(shared_ptr left, shared_ptr right) : left(left), right(right) {}; - Choice::Choice(const Rule &left, const Rule &right) : left(left.copy()), right(right.copy()) {}; - Choice::Choice(const Rule *left, const Rule *right) : left(left), right(right) {}; - Choice::Choice(shared_ptr left, shared_ptr right) : left(left), right(right) {}; - - // Transitions - TransitionMap Blank::transitions() const { - return TransitionMap(); - } - - TransitionMap Symbol::transitions() const { - return TransitionMap({ copy() }, { new Blank() }); - } - - TransitionMap Char::transitions() const { - return TransitionMap({ copy() }, { new Blank() }); - } - - TransitionMap Choice::transitions() const { - auto result = left->transitions(); - result.merge(right->transitions(), [&](rule_ptr left, rule_ptr right) -> rule_ptr { - return rule_ptr(new Choice(left, right)); - }); - return result; - } - - TransitionMap Seq::transitions() const { - return left->transitions().map([&](rule_ptr left_rule) -> rule_ptr { - if (typeid(*left_rule) == typeid(Blank)) - return right; - else - return rule_ptr(new Seq(left_rule, right)); - }); - } - - // Equality - bool Blank::operator==(const Rule &rule) const { - return dynamic_cast(&rule) != NULL; - } - - bool Symbol::operator==(const Rule &rule) const { - const Symbol *other = dynamic_cast(&rule); - return (other != NULL) && (other->id == id); - } - - bool Char::operator==(const Rule &rule) const { - const Char *other = dynamic_cast(&rule); - return (other != NULL) && (other->value == value); - } - - bool Choice::operator==(const Rule &rule) const { - const Choice *other = dynamic_cast(&rule); - return (other != NULL) && (*other->left == *left) && (*other->right == *right); - } - - bool Seq::operator==(const Rule &rule) const { - const Seq *other = dynamic_cast(&rule); - return (other != NULL) && (*other->left == *left) && (*other->right == *right); - } - - // Copying - Blank * Blank::copy() const { - return new Blank(); - } - - Symbol * Symbol::copy() const { - return new Symbol(id); - } - - Char * Char::copy() const { - return new Char(value); - } - - Choice * Choice::copy() const { - return new Choice(left, right); - } - - Seq * Seq::copy() const { - return new Seq(left, right); - } - - // Description - string Blank::to_string() const { - return "blank"; - } - - string Symbol::to_string() const { - return std::to_string(id); - } - - string Char::to_string() const { - return std::to_string(value); - } - - string Choice::to_string() const { - return string("(choice ") + left->to_string() + " " + right->to_string() + ")"; - } - - string Seq::to_string() const { - return string("(seq ") + left->to_string() + " " + right->to_string() + ")"; - } - } -} \ No newline at end of file diff --git a/src/rules.h b/src/rules.h index 26a4bc75..d4e676d0 100644 --- a/src/rules.h +++ b/src/rules.h @@ -1,81 +1,11 @@ -#ifndef __TreeSitter__Rule__ -#define __TreeSitter__Rule__ +#ifndef __TreeSitter__rules__ +#define __TreeSitter__rules__ -#include - -namespace tree_sitter { - template class TransitionMap; - - namespace rules { - class Rule { - public: - virtual TransitionMap transitions() const = 0; - virtual Rule * copy() const = 0; - virtual bool operator==(const Rule& other) const = 0; - virtual std::string to_string() const = 0; - }; - - typedef std::shared_ptr rule_ptr; - - class Blank : public Rule { - public: - Blank(); - TransitionMap transitions() const; - Blank * copy() const; - bool operator==(const Rule& other) const; - std::string to_string() const; - }; - - class Symbol : public Rule { - public: - Symbol(int id); - TransitionMap transitions() const; - Symbol * copy() const; - bool operator==(const Rule& other) const; - std::string to_string() const; - private: - int id; - }; - - class Char : public Rule { - public: - Char(char value); - TransitionMap transitions() const; - Char * copy() const; - bool operator==(const Rule& other) const; - std::string to_string() const; - private: - char value; - }; - - class Choice : public Rule { - public: - Choice(const Rule &left, const Rule &right); - Choice(const Rule *left, const Rule *right); - Choice(std::shared_ptr left, std::shared_ptr right); - TransitionMap transitions() const; - Choice * copy() const; - bool operator==(const Rule& other) const; - std::string to_string() const; - private: - rule_ptr left; - rule_ptr right; - }; - - class Seq : public Rule { - public: - Seq(const Rule &left, const Rule &right); - Seq(const Rule *left, const Rule *right); - Seq(std::shared_ptr left, std::shared_ptr right); - TransitionMap transitions() const; - Seq * copy() const; - bool operator==(const Rule& other) const; - std::string to_string() const; - private: - rule_ptr left; - rule_ptr right; - }; - } -} +#include "rules/rule.h" +#include "rules/blank.h" +#include "rules/char.h" +#include "rules/symbol.h" +#include "rules/choice.h" +#include "rules/seq.h" #endif diff --git a/src/rules/blank.cpp b/src/rules/blank.cpp new file mode 100644 index 00000000..7d8ec1c1 --- /dev/null +++ b/src/rules/blank.cpp @@ -0,0 +1,24 @@ +#include "blank.h" +#include "transition_map.h" + +namespace tree_sitter { + namespace rules { + Blank::Blank() {} + + TransitionMap Blank::transitions() const { + return TransitionMap(); + } + + bool Blank::operator==(const Rule &rule) const { + return dynamic_cast(&rule) != NULL; + } + + Blank * Blank::copy() const { + return new Blank(); + } + + std::string Blank::to_string() const { + return "blank"; + } + } +} \ No newline at end of file diff --git a/src/rules/blank.h b/src/rules/blank.h new file mode 100644 index 00000000..e95f9475 --- /dev/null +++ b/src/rules/blank.h @@ -0,0 +1,19 @@ +#ifndef __tree_sitter__blank__ +#define __tree_sitter__blank__ + +#include "rule.h" + +namespace tree_sitter { + namespace rules { + class Blank : public Rule { + public: + Blank(); + TransitionMap transitions() const; + Blank * copy() const; + bool operator==(const Rule& other) const; + std::string to_string() const; + }; + } +} + +#endif \ No newline at end of file diff --git a/src/rules/char.cpp b/src/rules/char.cpp new file mode 100644 index 00000000..03f91946 --- /dev/null +++ b/src/rules/char.cpp @@ -0,0 +1,27 @@ +#include "char.h" +#include "transition_map.h" + +using namespace std; + +namespace tree_sitter { + namespace rules { + Char::Char(char value) : value(value) {}; + + TransitionMap Char::transitions() const { + return TransitionMap({ copy() }, { new Blank() }); + } + + bool Char::operator==(const Rule &rule) const { + const Char *other = dynamic_cast(&rule); + return (other != NULL) && (other->value == value); + } + + Char * Char::copy() const { + return new Char(value); + } + + string Char::to_string() const { + return std::to_string(value); + } + } +} \ No newline at end of file diff --git a/src/rules/char.h b/src/rules/char.h new file mode 100644 index 00000000..42c8267c --- /dev/null +++ b/src/rules/char.h @@ -0,0 +1,21 @@ +#ifndef __tree_sitter__char__ +#define __tree_sitter__char__ + +#include "rule.h" + +namespace tree_sitter { + namespace rules { + class Char : public Rule { + public: + Char(char value); + TransitionMap transitions() const; + Char * copy() const; + bool operator==(const Rule& other) const; + std::string to_string() const; + private: + char value; + }; + } +} + +#endif \ No newline at end of file diff --git a/src/rules/choice.cpp b/src/rules/choice.cpp new file mode 100644 index 00000000..fdd33352 --- /dev/null +++ b/src/rules/choice.cpp @@ -0,0 +1,30 @@ +#include "choice.h" +#include "transition_map.h" + +namespace tree_sitter { + namespace rules { + Choice::Choice(const Rule &left, const Rule &right) : left(left.copy()), right(right.copy()) {}; + Choice::Choice(rule_ptr left, rule_ptr right) : left(left), right(right) {}; + + TransitionMap Choice::transitions() const { + auto result = left->transitions(); + result.merge(right->transitions(), [&](rule_ptr left, rule_ptr right) -> rule_ptr { + return rule_ptr(new Choice(left, right)); + }); + return result; + } + + bool Choice::operator==(const Rule &rule) const { + const Choice *other = dynamic_cast(&rule); + return (other != NULL) && (*other->left == *left) && (*other->right == *right); + } + + Choice * Choice::copy() const { + return new Choice(left, right); + } + + std::string Choice::to_string() const { + return std::string("(choice ") + left->to_string() + " " + right->to_string() + ")"; + } + } +} \ No newline at end of file diff --git a/src/rules/choice.h b/src/rules/choice.h new file mode 100644 index 00000000..823fb308 --- /dev/null +++ b/src/rules/choice.h @@ -0,0 +1,23 @@ +#ifndef __tree_sitter__choice__ +#define __tree_sitter__choice__ + +#include "rule.h" + +namespace tree_sitter { + namespace rules { + class Choice : public Rule { + public: + Choice(const Rule &left, const Rule &right); + Choice(std::shared_ptr left, std::shared_ptr right); + TransitionMap transitions() const; + Choice * copy() const; + bool operator==(const Rule& other) const; + std::string to_string() const; + private: + rule_ptr left; + rule_ptr right; + }; + } +} + +#endif \ No newline at end of file diff --git a/src/rules/rule.h b/src/rules/rule.h new file mode 100644 index 00000000..3f6152e9 --- /dev/null +++ b/src/rules/rule.h @@ -0,0 +1,22 @@ +#ifndef __TreeSitter__rule__ +#define __TreeSitter__rule__ + +#include + +namespace tree_sitter { + template class TransitionMap; + + namespace rules { + class Rule { + public: + virtual TransitionMap transitions() const = 0; + virtual Rule * copy() const = 0; + virtual bool operator==(const Rule& other) const = 0; + virtual std::string to_string() const = 0; + }; + + typedef std::shared_ptr rule_ptr; + } +} + +#endif \ No newline at end of file diff --git a/src/rules/seq.cpp b/src/rules/seq.cpp new file mode 100644 index 00000000..df865611 --- /dev/null +++ b/src/rules/seq.cpp @@ -0,0 +1,32 @@ +#include "seq.h" +#include "blank.h" +#include "transition_map.h" + +namespace tree_sitter { + namespace rules { + Seq::Seq(const Rule &left, const Rule &right) : left(left.copy()), right(right.copy()) {}; + Seq::Seq(rule_ptr left, rule_ptr right) : left(left), right(right) {}; + + TransitionMap Seq::transitions() const { + return left->transitions().map([&](rule_ptr left_rule) -> rule_ptr { + if (typeid(*left_rule) == typeid(Blank)) + return right; + else + return rule_ptr(new Seq(left_rule, right)); + }); + } + + bool Seq::operator==(const Rule &rule) const { + const Seq *other = dynamic_cast(&rule); + return (other != NULL) && (*other->left == *left) && (*other->right == *right); + } + + Seq * Seq::copy() const { + return new Seq(left, right); + } + + std::string Seq::to_string() const { + return std::string("(seq ") + left->to_string() + " " + right->to_string() + ")"; + } + } +} \ No newline at end of file diff --git a/src/rules/seq.h b/src/rules/seq.h new file mode 100644 index 00000000..fcc8b57f --- /dev/null +++ b/src/rules/seq.h @@ -0,0 +1,23 @@ +#ifndef __tree_sitter__seq__ +#define __tree_sitter__seq__ + +#include "rule.h" + +namespace tree_sitter { + namespace rules { + class Seq : public Rule { + public: + Seq(const Rule &left, const Rule &right); + Seq(std::shared_ptr left, std::shared_ptr right); + TransitionMap transitions() const; + Seq * copy() const; + bool operator==(const Rule& other) const; + std::string to_string() const; + private: + rule_ptr left; + rule_ptr right; + }; + } +} + +#endif \ No newline at end of file diff --git a/src/rules/symbol.cpp b/src/rules/symbol.cpp new file mode 100644 index 00000000..167b99d7 --- /dev/null +++ b/src/rules/symbol.cpp @@ -0,0 +1,25 @@ +#include "symbol.h" +#include "transition_map.h" + +namespace tree_sitter { + namespace rules { + Symbol::Symbol(int id) : id(id) {}; + + TransitionMap Symbol::transitions() const { + return TransitionMap({ copy() }, { new Blank() }); + } + + bool Symbol::operator==(const Rule &rule) const { + const Symbol *other = dynamic_cast(&rule); + return (other != NULL) && (other->id == id); + } + + Symbol * Symbol::copy() const { + return new Symbol(id); + } + + std::string Symbol::to_string() const { + return std::to_string(id); + } + } +} \ No newline at end of file diff --git a/src/rules/symbol.h b/src/rules/symbol.h new file mode 100644 index 00000000..40ebe862 --- /dev/null +++ b/src/rules/symbol.h @@ -0,0 +1,21 @@ +#ifndef __tree_sitter__sym__ +#define __tree_sitter__sym__ + +#include "rule.h" + +namespace tree_sitter { + namespace rules { + class Symbol : public Rule { + public: + Symbol(int id); + TransitionMap transitions() const; + Symbol * copy() const; + bool operator==(const Rule& other) const; + std::string to_string() const; + private: + int id; + }; + } +} + +#endif \ No newline at end of file diff --git a/src/transition_map.h b/src/transition_map.h index f45b3ddf..7ba4f876 100644 --- a/src/transition_map.h +++ b/src/transition_map.h @@ -6,8 +6,6 @@ #include "rules.h" namespace tree_sitter { - class rules::Rule; - template class TransitionMap { public: