Fix precedence of comments vs '/' operator
This commit is contained in:
parent
155a57d3ab
commit
174f306e2a
6 changed files with 1247 additions and 1234 deletions
|
|
@ -161,6 +161,9 @@ namespace tree_sitter_examples {
|
|||
{ "type_name", sym("_identifier") },
|
||||
{ "_identifier", pattern("\\a[\\w_]*") },
|
||||
{ "number", pattern("\\d+(\\.\\d+)?") },
|
||||
{ "comment", pattern("//[^\n]*") },
|
||||
|
||||
// TODO - make it clear how this number relates to the
|
||||
// precedence used by the `keyword` helper.
|
||||
{ "comment", token(prec(1000, pattern("//[^\n]*"))) },
|
||||
}).ubiquitous_tokens({ "comment" });
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -322,6 +322,7 @@ LEX_FN() {
|
|||
ADVANCE(27);
|
||||
LEX_ERROR();
|
||||
case ts_lex_state_error:
|
||||
START_TOKEN();
|
||||
if (lookahead == '\0')
|
||||
ADVANCE(25);
|
||||
if (('\t' <= lookahead && lookahead <= '\n') ||
|
||||
|
|
|
|||
|
|
@ -10,12 +10,15 @@ START_TEST
|
|||
describe("getting metadata for rules", []() {
|
||||
MetadataKey key1 = MetadataKey(100);
|
||||
MetadataKey key2 = MetadataKey(101);
|
||||
rule_ptr rule;
|
||||
|
||||
describe("when given a metadata rule", [&]() {
|
||||
auto rule = make_shared<Metadata>(sym("x"), map<MetadataKey, int>({
|
||||
{ key1, 1 },
|
||||
{ key2, 2 },
|
||||
}));
|
||||
before_each([&]() {
|
||||
rule = make_shared<Metadata>(sym("x"), map<MetadataKey, int>({
|
||||
{ key1, 1 },
|
||||
{ key2, 2 },
|
||||
}));
|
||||
});
|
||||
|
||||
it("returns the value for the given key", [&]() {
|
||||
AssertThat(get_metadata(rule, key1), Equals(1));
|
||||
|
|
@ -23,7 +26,17 @@ describe("getting metadata for rules", []() {
|
|||
});
|
||||
|
||||
it("returns 0 if the rule does not have the key", [&]() {
|
||||
AssertThat(get_metadata(rule, MetadataKey(3)), Equals(0));
|
||||
AssertThat(get_metadata(rule, MetadataKey(0)), Equals(0));
|
||||
});
|
||||
|
||||
describe("when the rule contains another metadata rule", [&]() {
|
||||
it("also gets metadata from the inner metadata rule", [&]() {
|
||||
rule = make_shared<Metadata>(make_shared<Metadata>(sym("x"), map<MetadataKey, int>({
|
||||
{ key1, 1 }
|
||||
})), map<MetadataKey, int>());
|
||||
|
||||
AssertThat(get_metadata(rule, key1), Equals(1));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ parses comments
|
|||
==========================================
|
||||
package trivial
|
||||
|
||||
var x = 1 // on package
|
||||
var x = 1 // on variable
|
||||
|
||||
func main() {
|
||||
// in function
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ namespace tree_sitter {
|
|||
rules::MetadataKey metadata_key;
|
||||
|
||||
int apply_to(const rules::Metadata *rule) {
|
||||
return rule->value_for(metadata_key);
|
||||
int result = rule->value_for(metadata_key);
|
||||
return (result != 0) ? result : apply(rule->rule);
|
||||
}
|
||||
|
||||
// TODO -
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue