Merge pull request #1836 from nmote/extra-alias

Avoid extracting default alias for extras
This commit is contained in:
Max Brunsfeld 2022-08-13 21:10:34 -07:00 committed by GitHub
commit a882d0b036
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 4 deletions

View file

@ -62,6 +62,18 @@ pub(super) fn extract_default_aliases(
}
}
for symbol in syntax_grammar.extra_symbols.iter() {
let mut status = match symbol.kind {
SymbolType::External => &mut external_status_list[symbol.index],
SymbolType::NonTerminal => &mut non_terminal_status_list[symbol.index],
SymbolType::Terminal => &mut terminal_status_list[symbol.index],
SymbolType::End | SymbolType::EndOfNonTerminalExtra => {
panic!("Unexpected end token")
}
};
status.appears_unaliased = true;
}
let symbols_with_statuses = (terminal_status_list
.iter_mut()
.enumerate()

View file

@ -2,11 +2,12 @@
Method calls
======================================
a.b(c(d.e));
*a.b(c(d.e));
---
(statement
(star)
(call_expression
(member_expression
(variable_name)

View file

@ -1,7 +1,10 @@
module.exports = grammar({
name: 'aliased_rules',
extras: $ => [/\s/],
extras: $ => [
/\s/,
$.star,
],
rules: {
statement: $ => seq($._expression, ';'),
@ -25,6 +28,15 @@ module.exports = grammar({
alias($.identifier, $.property_name)
)),
identifier: $ => /[a-z]+/
identifier: $ => /[a-z]+/,
// Tests for https://github.com/tree-sitter/tree-sitter/issues/1834
//
// Even though the alias is unused, that issue causes all instances of
// the extra that appear in the tree to be renamed to `star_aliased`.
//
// Instead, this alias should have no effect because it is unused.
star: $ => '*',
unused: $ => alias($.star, $.star_aliased),
}
});
});