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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue