Replace {left,right}_assoc w/ prec, with an associativity argument
This commit is contained in:
parent
a19b0e75ac
commit
b1f8ba6202
7 changed files with 37 additions and 38 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "tree_sitter/compiler.h"
|
||||
#include "compiler/rules/rule.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
@ -16,11 +17,7 @@ enum MetadataKey {
|
|||
ASSOCIATIVITY,
|
||||
};
|
||||
|
||||
enum Associativity {
|
||||
AssociativityUnspecified,
|
||||
AssociativityLeft,
|
||||
AssociativityRight,
|
||||
};
|
||||
const Associativity AssociativityUnspecified = (Associativity)0;
|
||||
|
||||
class Metadata : public Rule {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -43,25 +43,22 @@ rule_ptr sym(const string &name) { return make_shared<NamedSymbol>(name); }
|
|||
rule_ptr pattern(const string &value) { return make_shared<Pattern>(value); }
|
||||
|
||||
rule_ptr str(const string &value) {
|
||||
return token(left_assoc(1, make_shared<String>(value)));
|
||||
return token(prec(1, make_shared<String>(value)));
|
||||
}
|
||||
|
||||
rule_ptr err(const rule_ptr &rule) {
|
||||
return choice({ rule, ERROR().copy() });
|
||||
}
|
||||
|
||||
rule_ptr left_assoc(int precedence, const rule_ptr &rule) {
|
||||
rule_ptr prec(int precedence, const rule_ptr &rule, Associativity associativity) {
|
||||
return metadata(rule, {
|
||||
{ PRECEDENCE, precedence },
|
||||
{ ASSOCIATIVITY, AssociativityLeft }
|
||||
{ ASSOCIATIVITY, associativity }
|
||||
});
|
||||
}
|
||||
|
||||
rule_ptr right_assoc(int precedence, const rule_ptr &rule) {
|
||||
return metadata(rule, {
|
||||
{ PRECEDENCE, precedence },
|
||||
{ ASSOCIATIVITY, AssociativityRight }
|
||||
});
|
||||
rule_ptr prec(int precedence, const rule_ptr &rule) {
|
||||
return prec(precedence, rule, AssociativityLeft);
|
||||
}
|
||||
|
||||
rule_ptr token(const rule_ptr &rule) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue