Named rules
This commit is contained in:
parent
6426beec15
commit
adb8d3db97
|
@ -2,3 +2,4 @@ JSONLexer.h
|
||||||
JSONLexer.cpp
|
JSONLexer.cpp
|
||||||
JSONParser.h
|
JSONParser.h
|
||||||
JSONParser.cpp
|
JSONParser.cpp
|
||||||
|
json
|
||||||
|
|
|
@ -73,9 +73,9 @@ namespace backends {
|
||||||
std::map<const std::string, templ::TemplateContext> r;
|
std::map<const std::string, templ::TemplateContext> r;
|
||||||
r["index"] = templ::make_string(std::to_string(i));
|
r["index"] = templ::make_string(std::to_string(i));
|
||||||
r["rhs_length"] = templ::make_string(std::to_string(grammar.rules[i]->tail.size()));
|
r["rhs_length"] = templ::make_string(std::to_string(grammar.rules[i]->tail.size()));
|
||||||
if (false /* the rule has a name */) {
|
if (grammar.rules[i]->name.length()) {
|
||||||
r["rname"] = templ::make_string(""); //The name
|
r["rname"] = templ::make_string(grammar.rules[i]->name); //The name
|
||||||
rulenames.insert(""); //The name
|
rulenames.insert(grammar.rules[i]->name); //The name
|
||||||
} else {
|
} else {
|
||||||
rulenames.insert(std::to_string(i));
|
rulenames.insert(std::to_string(i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace pds {
|
||||||
struct Rule {
|
struct Rule {
|
||||||
std::string head; ///< The replaced variable
|
std::string head; ///< The replaced variable
|
||||||
std::vector<std::string> tail; ///< The replacement rule
|
std::vector<std::string> tail; ///< The replacement rule
|
||||||
|
const std::string name; ///< An optional name for this rule, if it's empty, there's no name
|
||||||
|
|
||||||
bool operator<(const Rule& other) const {
|
bool operator<(const Rule& other) const {
|
||||||
if(head != other.head){
|
if(head != other.head){
|
||||||
|
@ -27,8 +28,9 @@ namespace pds {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rule() : head(""), tail() {}
|
Rule() : head(""), tail(), name("") {}
|
||||||
Rule(const std::string& h, const std::vector<std::string>& t) : head(h), tail(t) {}
|
Rule(const std::string& h, const std::vector<std::string>& t) : head(h), tail(t), name("") {}
|
||||||
|
Rule(const std::string& h, const std::vector<std::string>& t, const std::string& name) : head(h), tail(t), name(name) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class PrecedenceType {
|
enum class PrecedenceType {
|
||||||
|
|
Loading…
Reference in New Issue