Rename RENAME rule to ALIAS, allow it to create anonymous nodes
This commit is contained in:
parent
b5f421cafb
commit
cb5fe80348
28 changed files with 304 additions and 270 deletions
|
|
@ -9,6 +9,20 @@ namespace rules {
|
|||
using std::move;
|
||||
using std::string;
|
||||
|
||||
bool Alias::operator==(const Alias &other) const {
|
||||
return value == other.value && is_named == other.is_named;
|
||||
}
|
||||
|
||||
bool Alias::operator!=(const Alias &other) const {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
bool Alias::operator<(const Alias &other) const {
|
||||
if (value < other.value) return true;
|
||||
if (other.value < value) return false;
|
||||
return is_named < other.is_named;
|
||||
}
|
||||
|
||||
Metadata::Metadata(const Rule &rule, MetadataParams params) :
|
||||
rule(std::make_shared<Rule>(rule)), params(params) {}
|
||||
|
||||
|
|
@ -77,9 +91,9 @@ Metadata Metadata::main_token(const Rule &rule) {
|
|||
return Metadata{rule, params};
|
||||
}
|
||||
|
||||
Metadata Metadata::rename(string &&name, const Rule &rule) {
|
||||
Metadata Metadata::alias(string &&value, bool is_named, const Rule &rule) {
|
||||
MetadataParams params;
|
||||
params.name_replacement = move(name);
|
||||
params.alias = {move(value), is_named};
|
||||
return Metadata{rule, params};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,14 @@ enum Associativity {
|
|||
AssociativityRight,
|
||||
};
|
||||
|
||||
struct Alias {
|
||||
std::string value = "";
|
||||
bool is_named = false;
|
||||
bool operator==(const Alias &) const;
|
||||
bool operator!=(const Alias &) const;
|
||||
bool operator<(const Alias &) const;
|
||||
};
|
||||
|
||||
struct MetadataParams {
|
||||
int precedence;
|
||||
int dynamic_precedence;
|
||||
|
|
@ -23,7 +31,7 @@ struct MetadataParams {
|
|||
bool is_string;
|
||||
bool is_active;
|
||||
bool is_main_token;
|
||||
std::string name_replacement;
|
||||
Alias alias;
|
||||
|
||||
inline MetadataParams() :
|
||||
precedence{0}, dynamic_precedence{0}, associativity{AssociativityNone},
|
||||
|
|
@ -41,7 +49,7 @@ struct MetadataParams {
|
|||
is_string == other.is_string &&
|
||||
is_active == other.is_active &&
|
||||
is_main_token == other.is_main_token &&
|
||||
name_replacement == other.name_replacement
|
||||
alias == other.alias
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
@ -62,7 +70,7 @@ struct Metadata {
|
|||
static Metadata prec_dynamic(int precedence, const Rule &rule);
|
||||
static Metadata separator(const Rule &rule);
|
||||
static Metadata main_token(const Rule &rule);
|
||||
static Metadata rename(std::string &&name, const Rule &rule);
|
||||
static Metadata alias(std::string &&value, bool is_named, const Rule &rule);
|
||||
|
||||
bool operator==(const Metadata &other) const;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue