A precedence annotation wrapping a sequence of characters now only affects how tightly those characters bind to *each other*, not how tightly they bind to the preceding character. This bug surfaced because a generated lexer was failing to recognize a '\n' character as a token, instead treating it as ubiquitous whitespace. It made this error because, even though anonymous ubiquitous tokens have the lowest precedence, the character immediately *after* the '\n' was part of a normal token, which had *normal* precedence (0). Advancing into that following token was incorrectly prioritized above accepting the line-break token.
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
#include "rule_helpers.h"
|
|
#include <memory>
|
|
#include "compiler/rules/symbol.h"
|
|
|
|
namespace tree_sitter {
|
|
using std::make_shared;
|
|
using std::set;
|
|
using std::map;
|
|
using std::ostream;
|
|
using std::string;
|
|
using std::to_string;
|
|
|
|
rule_ptr character(const set<uint32_t> &ranges) {
|
|
return character(ranges, true);
|
|
}
|
|
|
|
rule_ptr character(const set<uint32_t> &chars, bool sign) {
|
|
rules::CharacterSet result;
|
|
if (sign) {
|
|
for (uint32_t c : chars)
|
|
result.include(c);
|
|
} else {
|
|
result.include_all();
|
|
for (uint32_t c : chars)
|
|
result.exclude(c);
|
|
}
|
|
return result.copy();
|
|
}
|
|
|
|
rule_ptr i_sym(size_t index) {
|
|
return make_shared<rules::Symbol>(index);
|
|
}
|
|
|
|
rule_ptr i_token(size_t index) {
|
|
return make_shared<rules::Symbol>(index, true);
|
|
}
|
|
|
|
rule_ptr metadata(rule_ptr rule, map<rules::MetadataKey, int> values) {
|
|
return make_shared<rules::Metadata>(rule, values);
|
|
}
|
|
|
|
rule_ptr active_prec(int precedence, rule_ptr rule) {
|
|
return std::make_shared<rules::Metadata>(rule, map<rules::MetadataKey, int>({
|
|
{ rules::PRECEDENCE, precedence },
|
|
{ rules::IS_ACTIVE, true }
|
|
}));
|
|
}
|
|
|
|
bool operator==(const Variable &left, const Variable &right) {
|
|
return left.name == right.name && left.rule->operator==(*right.rule) &&
|
|
left.type == right.type;
|
|
}
|
|
}
|