Skip to content

Commit

Permalink
Remove multiplicity from rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreLachanceGit committed Sep 20, 2023
1 parent 0e259f5 commit 641d80c
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 223 deletions.
1 change: 0 additions & 1 deletion ls_framework/src/features/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ fn get_symbol_completion_type(symbol_kind: String) -> Option<CompletionItemKind>

pub fn get_list(
position: Position,
source_code: &str,
ast_query: &Arc<Mutex<impl AstQuery>>,
st_query: &Arc<Mutex<impl SymbolTableQuery>>,
context: Option<CompletionContext>,
Expand Down
1 change: 0 additions & 1 deletion ls_framework/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ impl File {
) -> Option<Vec<CompletionItem>> {
completion::get_list(
position,
&self.source_code,
&self.ast_manager,
&self.symbol_table_manager,
context,
Expand Down
23 changes: 2 additions & 21 deletions ls_framework/src/language_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,7 @@ pub struct Rule {
#[serde(default)]
pub is_scope: bool,
#[serde(default)]
pub children: Vec<Multiplicity>,
}

#[derive(Debug, Deserialize, Clone)]
pub enum Multiplicity {
One(Child),
Maybe(Child),
Many(Child),
}

impl Multiplicity {
pub fn get_child(&self) -> &Child {
match self {
Multiplicity::One(c) | Multiplicity::Maybe(c) | Multiplicity::Many(c) => c,
}
}
pub children: Vec<Child>,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down Expand Up @@ -145,11 +130,7 @@ impl LanguageDefinition {
symbol_types.insert(0, HighlightType::Keyword.get());

for rule in &self.ast_rules {
for mult in &rule.children {
let child = match mult {
Multiplicity::One(c) | Multiplicity::Maybe(c) | Multiplicity::Many(c) => c,
};

for child in &rule.children {
if let Some(semantic_token_type) = &child.highlight_type {
symbol_types.push(semantic_token_type.get());
}
Expand Down
38 changes: 6 additions & 32 deletions ls_framework/src/metadata/ast/rules_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use indextree::{Arena, NodeId};

use super::{tree::Translator, Ast, Node, NodeKind};
use crate::{
language_def::{
DirectOrRule, LanguageDefinition, Multiplicity, Rule, Symbol, TreesitterNodeQuery,
},
language_def::{Child, DirectOrRule, LanguageDefinition, Rule, Symbol, TreesitterNodeQuery},
lsp_mappings::HighlightType,
};

Expand Down Expand Up @@ -51,21 +49,16 @@ impl RulesTranslator {
None,
);
// TODO: has_error vs is_error
for error_ts_node in children.iter().filter(|node| node.has_error()) {
// current_node_id.append(self.new_error_node(error_ts_node, None), &mut self.arena);
}
// for error_ts_node in children.iter().filter(|node| node.has_error()) {
// current_node_id.append(self.new_error_node(error_ts_node, None), &mut self.arena);
// }

for child in current_rule.children.iter() {
self.query_parse_child(&children, child, current_node_id, current_ts_node);
}

for child in &LanguageDefinition::get().global_ast_rules {
self.query_parse_child(
&children,
&Multiplicity::Many(child.clone()),
current_node_id,
current_ts_node,
);
self.query_parse_child(&children, &child, current_node_id, current_ts_node);

Check warning on line 61 in ls_framework/src/metadata/ast/rules_translator.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> ls_framework/src/metadata/ast/rules_translator.rs:61:47 | 61 | self.query_parse_child(&children, &child, current_node_id, current_ts_node); | ^^^^^^ help: change this to: `child` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
}

current_node_id
Expand All @@ -74,14 +67,12 @@ impl RulesTranslator {
fn query_parse_child(
&mut self,
children: &[tree_sitter::Node],
multiplicity: &Multiplicity,
child: &Child,
current_node_id: NodeId,
current_ts_node: &tree_sitter::Node,

Check warning on line 72 in ls_framework/src/metadata/ast/rules_translator.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `current_ts_node`

warning: unused variable: `current_ts_node` --> ls_framework/src/metadata/ast/rules_translator.rs:72:9 | 72 | current_ts_node: &tree_sitter::Node, | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_current_ts_node` | = note: `#[warn(unused_variables)]` on by default
) {
let child = multiplicity.get_child();
let (query, node_or_rule) = (&child.query, &child.rule);

let mut counter = 0;
for (i, ts_node) in children.iter().enumerate() {
let target_node = if let TreesitterNodeQuery::Path(path) = query {
if path.is_empty() {
Expand Down Expand Up @@ -158,25 +149,8 @@ impl RulesTranslator {
current_node_id.append(self.parse(&rule, &target_node), &mut self.arena);
}
}

counter += 1;
}

if matches!(multiplicity, Multiplicity::One(_) | Multiplicity::Maybe(_)) && counter > 1
{
// current_node_id.append(
// self.new_error_node(ts_node, Some(format!("Too many '{:?}'.", query))),
// &mut self.arena,
// );
}
}

if matches!(multiplicity, Multiplicity::One(_)) && counter == 0 {
// current_node_id.append(
// self.new_error_node(current_ts_node, Some(format!("Missing '{:?}'.", query))),
// &mut self.arena,
// );
}
}

fn new_node(
Expand Down
Loading

0 comments on commit 641d80c

Please sign in to comment.