From 7c711c5537d7ea1befd3c678e78a9c78ef4fb194 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 16 Dec 2019 12:38:40 -0800 Subject: [PATCH] Move the private functions in node_types.rs to the end of the file --- cli/src/generate/node_types.rs | 156 ++++++++++++++++----------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/cli/src/generate/node_types.rs b/cli/src/generate/node_types.rs index 46a8f7b4..bf30ee5e 100644 --- a/cli/src/generate/node_types.rs +++ b/cli/src/generate/node_types.rs @@ -395,84 +395,6 @@ pub(crate) fn get_variable_info( Ok(result) } -fn variable_type_for_child_type( - child_type: &ChildType, - syntax_grammar: &SyntaxGrammar, - lexical_grammar: &LexicalGrammar, -) -> VariableType { - match child_type { - ChildType::Aliased(alias) => alias.kind(), - ChildType::Normal(symbol) => { - if syntax_grammar.supertype_symbols.contains(&symbol) { - VariableType::Named - } else if syntax_grammar.variables_to_inline.contains(&symbol) { - VariableType::Hidden - } else { - match symbol.kind { - SymbolType::NonTerminal => syntax_grammar.variables[symbol.index].kind, - SymbolType::Terminal => lexical_grammar.variables[symbol.index].kind, - SymbolType::External => syntax_grammar.external_tokens[symbol.index].kind, - _ => VariableType::Hidden, - } - } - } - } -} - -fn sorted_vec_insert(vec: &mut Vec, value: &T) -> bool -where - T: Clone + Eq + Ord, -{ - if let Err(i) = vec.binary_search(&value) { - vec.insert(i, value.clone()); - true - } else { - false - } -} - -fn sorted_vec_replace(left: &mut Vec, right: &Vec, value: T) -> bool -where - T: Eq + Ord, -{ - if left.len() == 0 { - return false; - } - - let mut i = 0; - for right_elem in right.iter() { - while left[i] < *right_elem { - i += 1; - if i == left.len() { - return false; - } - } - if left[i] != *right_elem { - return false; - } - } - - i = 0; - left.retain(|left_elem| { - if i == right.len() { - return true; - } - while right[i] < *left_elem { - i += 1; - if i == right.len() { - return true; - } - } - right[i] != *left_elem - }); - - if let Err(i) = left.binary_search(&value) { - left.insert(i, value); - } - - true -} - pub(crate) fn generate_node_types_json( syntax_grammar: &SyntaxGrammar, lexical_grammar: &LexicalGrammar, @@ -728,6 +650,84 @@ pub(crate) fn generate_node_types_json( result } +fn variable_type_for_child_type( + child_type: &ChildType, + syntax_grammar: &SyntaxGrammar, + lexical_grammar: &LexicalGrammar, +) -> VariableType { + match child_type { + ChildType::Aliased(alias) => alias.kind(), + ChildType::Normal(symbol) => { + if syntax_grammar.supertype_symbols.contains(&symbol) { + VariableType::Named + } else if syntax_grammar.variables_to_inline.contains(&symbol) { + VariableType::Hidden + } else { + match symbol.kind { + SymbolType::NonTerminal => syntax_grammar.variables[symbol.index].kind, + SymbolType::Terminal => lexical_grammar.variables[symbol.index].kind, + SymbolType::External => syntax_grammar.external_tokens[symbol.index].kind, + _ => VariableType::Hidden, + } + } + } + } +} + +fn sorted_vec_insert(vec: &mut Vec, value: &T) -> bool +where + T: Clone + Eq + Ord, +{ + if let Err(i) = vec.binary_search(&value) { + vec.insert(i, value.clone()); + true + } else { + false + } +} + +fn sorted_vec_replace(left: &mut Vec, right: &Vec, value: T) -> bool +where + T: Eq + Ord, +{ + if left.len() == 0 { + return false; + } + + let mut i = 0; + for right_elem in right.iter() { + while left[i] < *right_elem { + i += 1; + if i == left.len() { + return false; + } + } + if left[i] != *right_elem { + return false; + } + } + + i = 0; + left.retain(|left_elem| { + if i == right.len() { + return true; + } + while right[i] < *left_elem { + i += 1; + if i == right.len() { + return true; + } + } + right[i] != *left_elem + }); + + if let Err(i) = left.binary_search(&value) { + left.insert(i, value); + } + + true +} + #[cfg(test)] mod tests { use super::*;