style: wrap comments
This commit is contained in:
parent
b35efa8f33
commit
5825e24d56
13 changed files with 246 additions and 220 deletions
|
|
@ -75,8 +75,8 @@ impl<'a> ParseItemSetBuilder<'a> {
|
|||
|
||||
// The FIRST set of a non-terminal `i` is the union of the following sets:
|
||||
// * the set of all terminals that appear at the beginnings of i's productions
|
||||
// * the FIRST sets of all the non-terminals that appear at the beginnings
|
||||
// of i's productions
|
||||
// * the FIRST sets of all the non-terminals that appear at the beginnings of i's
|
||||
// productions
|
||||
//
|
||||
// Rather than computing these sets using recursion, we use an explicit stack
|
||||
// called `symbols_to_process`.
|
||||
|
|
@ -135,11 +135,11 @@ impl<'a> ParseItemSetBuilder<'a> {
|
|||
// item set when `i` occurs as the next symbol in one if its core items. The
|
||||
// structure of an *addition* is as follows:
|
||||
// * `item` - the new item that must be added as part of the expansion of `i`
|
||||
// * `lookaheads` - lookahead tokens that can always come after that item in
|
||||
// the expansion of `i`
|
||||
// * `propagates_lookaheads` - a boolean indicating whether or not `item` can
|
||||
// occur at the *end* of the expansion of `i`, so that i's own current
|
||||
// lookahead tokens can occur after `item`.
|
||||
// * `lookaheads` - lookahead tokens that can always come after that item in the expansion
|
||||
// of `i`
|
||||
// * `propagates_lookaheads` - a boolean indicating whether or not `item` can occur at the
|
||||
// *end* of the expansion of `i`, so that i's own current lookahead tokens can occur
|
||||
// after `item`.
|
||||
//
|
||||
// Again, rather than computing these additions recursively, we use an explicit
|
||||
// stack called `entries_to_process`.
|
||||
|
|
|
|||
|
|
@ -140,18 +140,17 @@ impl ChildQuantity {
|
|||
/// * `types` - The types of visible children the field can contain.
|
||||
/// * `optional` - Do `N` nodes always have this field?
|
||||
/// * `multiple` - Can `N` nodes have multiple children for this field?
|
||||
/// 3. `children_without_fields` - The *other* named children of `N` that are
|
||||
/// not associated with fields. Data regarding these children:
|
||||
/// 3. `children_without_fields` - The *other* named children of `N` that are not associated with
|
||||
/// fields. Data regarding these children:
|
||||
/// * `types` - The types of named children with no field.
|
||||
/// * `optional` - Do `N` nodes always have at least one named child with no field?
|
||||
/// * `multiple` - Can `N` nodes have multiple named children with no field?
|
||||
///
|
||||
/// Each summary must account for some indirect factors:
|
||||
/// 1. hidden nodes. When a parent node `N` has a hidden child `C`, the visible
|
||||
/// children of `C` *appear* to be direct children of `N`.
|
||||
/// 2. aliases. If a parent node type `M` is aliased as some other type `N`,
|
||||
/// then nodes which *appear* to have type `N` may have internal structure based
|
||||
/// on `M`.
|
||||
/// 1. hidden nodes. When a parent node `N` has a hidden child `C`, the visible children of `C`
|
||||
/// *appear* to be direct children of `N`.
|
||||
/// 2. aliases. If a parent node type `M` is aliased as some other type `N`, then nodes which
|
||||
/// *appear* to have type `N` may have internal structure based on `M`.
|
||||
pub fn get_variable_info(
|
||||
syntax_grammar: &SyntaxGrammar,
|
||||
lexical_grammar: &LexicalGrammar,
|
||||
|
|
@ -224,7 +223,8 @@ pub fn get_variable_info(
|
|||
.entry(field_name)
|
||||
.or_insert_with(ChildQuantity::zero);
|
||||
|
||||
// Inherit the types and quantities of hidden children associated with fields.
|
||||
// Inherit the types and quantities of hidden children associated with
|
||||
// fields.
|
||||
if child_is_hidden && child_symbol.is_non_terminal() {
|
||||
let child_variable_info = &result[child_symbol.index];
|
||||
did_change |= extend_sorted(
|
||||
|
|
@ -529,8 +529,8 @@ pub fn generate_node_types_json(
|
|||
let fields_json = node_type_json.fields.as_mut().unwrap();
|
||||
for (new_field, field_info) in &info.fields {
|
||||
let field_json = fields_json.entry(new_field.clone()).or_insert_with(|| {
|
||||
// If another rule is aliased with the same name, and does *not* have this field,
|
||||
// then this field cannot be required.
|
||||
// If another rule is aliased with the same name, and does *not* have this
|
||||
// field, then this field cannot be required.
|
||||
let mut field_json = FieldInfoJSON::default();
|
||||
if node_type_existed {
|
||||
field_json.required = false;
|
||||
|
|
@ -540,8 +540,8 @@ pub fn generate_node_types_json(
|
|||
populate_field_info_json(field_json, field_info);
|
||||
}
|
||||
|
||||
// If another rule is aliased with the same name, any fields that aren't present in this
|
||||
// cannot be required.
|
||||
// If another rule is aliased with the same name, any fields that aren't present in
|
||||
// this cannot be required.
|
||||
for (existing_field, field_json) in fields_json.iter_mut() {
|
||||
if !info.fields.contains_key(existing_field) {
|
||||
field_json.required = false;
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ struct SymbolStatus {
|
|||
// This has two benefits:
|
||||
// * It reduces the overhead of storing production-specific alias info in the parse table.
|
||||
// * Within an `ERROR` node, no context-specific aliases will be applied. This transformation
|
||||
// ensures that the children of an `ERROR` node have symbols that are consistent with the
|
||||
// way that they would appear in a valid syntax tree.
|
||||
// ensures that the children of an `ERROR` node have symbols that are consistent with the way that
|
||||
// they would appear in a valid syntax tree.
|
||||
pub(super) fn extract_default_aliases(
|
||||
syntax_grammar: &mut SyntaxGrammar,
|
||||
lexical_grammar: &LexicalGrammar,
|
||||
|
|
@ -164,10 +164,10 @@ pub(super) fn extract_default_aliases(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::generate::grammars::{
|
||||
LexicalVariable, Production, ProductionStep, SyntaxVariable, VariableType,
|
||||
use crate::generate::{
|
||||
grammars::{LexicalVariable, Production, ProductionStep, SyntaxVariable, VariableType},
|
||||
nfa::Nfa,
|
||||
};
|
||||
use crate::generate::nfa::Nfa;
|
||||
|
||||
#[test]
|
||||
fn test_extract_simple_aliases() {
|
||||
|
|
|
|||
|
|
@ -178,8 +178,8 @@ impl Generator {
|
|||
}
|
||||
// Two anonymous tokens with different flags but the same string value
|
||||
// should be represented with the same symbol in the public API. Examples:
|
||||
// * "<" and token(prec(1, "<"))
|
||||
// * "(" and token.immediate("(")
|
||||
// * "<" and token(prec(1, "<"))
|
||||
// * "(" and token.immediate("(")
|
||||
else if symbol.is_terminal() {
|
||||
let metadata = self.metadata_for_symbol(*symbol);
|
||||
for other_symbol in &self.parse_table.symbols {
|
||||
|
|
@ -225,7 +225,8 @@ impl Generator {
|
|||
if let Some(existing_symbol) = existing_symbol {
|
||||
alias_id = self.symbol_ids[&self.symbol_map[&existing_symbol]].clone();
|
||||
}
|
||||
// Other aliases don't match any existing symbol, and need their own identifiers.
|
||||
// Other aliases don't match any existing symbol, and need their own
|
||||
// identifiers.
|
||||
else {
|
||||
if let Err(i) = self.unique_aliases.binary_search(alias) {
|
||||
self.unique_aliases.insert(i, alias.clone());
|
||||
|
|
@ -1674,16 +1675,15 @@ impl Generator {
|
|||
/// * `parse_table` - The generated parse table for the language
|
||||
/// * `main_lex_table` - The generated lexing table for the language
|
||||
/// * `keyword_lex_table` - The generated keyword lexing table for the language
|
||||
/// * `keyword_capture_token` - A symbol indicating which token is used
|
||||
/// for keyword capture, if any.
|
||||
/// * `keyword_capture_token` - A symbol indicating which token is used for keyword capture, if any.
|
||||
/// * `syntax_grammar` - The syntax grammar extracted from the language's grammar
|
||||
/// * `lexical_grammar` - The lexical grammar extracted from the language's grammar
|
||||
/// * `default_aliases` - A map describing the global rename rules that should apply.
|
||||
/// the keys are symbols that are *always* aliased in the same way, and the values
|
||||
/// are the aliases that are applied to those symbols.
|
||||
/// * `abi_version` - The language ABI version that should be generated. Usually
|
||||
/// you want Tree-sitter's current version, but right after making an ABI
|
||||
/// change, it may be useful to generate code with the previous ABI.
|
||||
/// * `default_aliases` - A map describing the global rename rules that should apply. the keys are
|
||||
/// symbols that are *always* aliased in the same way, and the values are the aliases that are
|
||||
/// applied to those symbols.
|
||||
/// * `abi_version` - The language ABI version that should be generated. Usually you want
|
||||
/// Tree-sitter's current version, but right after making an ABI change, it may be useful to
|
||||
/// generate code with the previous ABI.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn render_c_code(
|
||||
name: &str,
|
||||
|
|
|
|||
|
|
@ -306,13 +306,15 @@ fn run_tests(
|
|||
let expected_output = format_sexp(&output, 0);
|
||||
let actual_output = format_sexp(&actual, 0);
|
||||
|
||||
// Only bail early before updating if the actual is not the output, sometimes
|
||||
// users want to test cases that are intended to have errors, hence why this
|
||||
// Only bail early before updating if the actual is not the output,
|
||||
// sometimes users want to test cases that
|
||||
// are intended to have errors, hence why this
|
||||
// check isn't shown above
|
||||
if actual.contains("ERROR") || actual.contains("MISSING") {
|
||||
*has_parse_errors = true;
|
||||
|
||||
// keep the original `expected` output if the actual output has an error
|
||||
// keep the original `expected` output if the actual output has an
|
||||
// error
|
||||
corrected_entries.push((
|
||||
name.clone(),
|
||||
input,
|
||||
|
|
|
|||
|
|
@ -850,10 +850,11 @@ fn test_node_numeric_symbols_respect_simple_aliases() {
|
|||
parser.set_language(&get_language("python")).unwrap();
|
||||
|
||||
// Example 1:
|
||||
// Python argument lists can contain "splat" arguments, which are not allowed within
|
||||
// other expressions. This includes `parenthesized_list_splat` nodes like `(*b)`. These
|
||||
// `parenthesized_list_splat` nodes are aliased as `parenthesized_expression`. Their numeric
|
||||
// `symbol`, aka `kind_id` should match that of a normal `parenthesized_expression`.
|
||||
// Python argument lists can contain "splat" arguments, which are not allowed
|
||||
// within other expressions. This includes `parenthesized_list_splat` nodes
|
||||
// like `(*b)`. These `parenthesized_list_splat` nodes are aliased as
|
||||
// `parenthesized_expression`. Their numeric `symbol`, aka `kind_id` should
|
||||
// match that of a normal `parenthesized_expression`.
|
||||
let tree = parser.parse("(a((*b)))", None).unwrap();
|
||||
let root = tree.root_node();
|
||||
assert_eq!(
|
||||
|
|
@ -875,9 +876,9 @@ fn test_node_numeric_symbols_respect_simple_aliases() {
|
|||
assert_eq!(inner_expr_node.kind_id(), outer_expr_node.kind_id());
|
||||
|
||||
// Example 2:
|
||||
// Ruby handles the unary (negative) and binary (minus) `-` operators using two different
|
||||
// tokens. One or more of these is an external token that's aliased as `-`. Their numeric
|
||||
// kind ids should match.
|
||||
// Ruby handles the unary (negative) and binary (minus) `-` operators using two
|
||||
// different tokens. One or more of these is an external token that's
|
||||
// aliased as `-`. Their numeric kind ids should match.
|
||||
parser.set_language(&get_language("ruby")).unwrap();
|
||||
let tree = parser.parse("-a - b", None).unwrap();
|
||||
let root = tree.root_node();
|
||||
|
|
|
|||
|
|
@ -891,12 +891,12 @@ fn test_query_matches_with_immediate_siblings() {
|
|||
let language = get_language("python");
|
||||
|
||||
// The immediate child operator '.' can be used in three similar ways:
|
||||
// 1. Before the first child node in a pattern, it means that there cannot be any
|
||||
// named siblings before that child node.
|
||||
// 1. Before the first child node in a pattern, it means that there cannot be any named
|
||||
// siblings before that child node.
|
||||
// 2. After the last child node in a pattern, it means that there cannot be any named
|
||||
// sibling after that child node.
|
||||
// 2. Between two child nodes in a pattern, it specifies that there cannot be any
|
||||
// named siblings between those two child snodes.
|
||||
// 2. Between two child nodes in a pattern, it specifies that there cannot be any named
|
||||
// siblings between those two child snodes.
|
||||
let query = Query::new(
|
||||
&language,
|
||||
"
|
||||
|
|
@ -1425,7 +1425,8 @@ fn test_query_matches_with_nested_optional_nodes() {
|
|||
allocations::record(|| {
|
||||
let language = get_language("javascript");
|
||||
|
||||
// A function call, optionally containing a function call, which optionally contains a number
|
||||
// A function call, optionally containing a function call, which optionally contains a
|
||||
// number
|
||||
let query = Query::new(
|
||||
&language,
|
||||
"
|
||||
|
|
@ -3269,8 +3270,8 @@ fn test_query_captures_with_too_many_nested_results() {
|
|||
// appearance.
|
||||
// 2. This pattern captures the root `call_expression`.
|
||||
// 3. This pattern's result also depends on the final child (the template string).
|
||||
// 4. In between the `call_expression` and the possible `template_string`, there can
|
||||
// be an arbitrarily deep subtree.
|
||||
// 4. In between the `call_expression` and the possible `template_string`, there can be an
|
||||
// arbitrarily deep subtree.
|
||||
//
|
||||
// This means that, if any patterns match *after* the initial `call_expression` is
|
||||
// captured, but before the final `template_string` is found, those matches must
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue